51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
|
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
|
||
|
|
||
|
import databaseRefreshHandler from '~background/messages/database/refresh';
|
||
|
import onInstalled from '~background/utils/runtime/onInstalled';
|
||
|
import {
|
||
|
EXTENSION_MENU_ITEM_ID,
|
||
|
REPORT_MENU_ITEM_ID,
|
||
|
SETTINGS_MENU_ITEM_ID,
|
||
|
} from '~utils/constants';
|
||
|
|
||
|
jest.mock('~background/messages/database/refresh');
|
||
|
|
||
|
describe('background/utils/runtime/onInstalled.ts', () => {
|
||
|
beforeEach(() => {
|
||
|
jest.clearAllMocks();
|
||
|
});
|
||
|
|
||
|
it('should remove existing context menus and create new ones', async () => {
|
||
|
const documentUrlPatterns = ['https://example.com/*'];
|
||
|
|
||
|
await onInstalled();
|
||
|
|
||
|
expect(chrome.contextMenus.removeAll).toHaveBeenCalled();
|
||
|
expect(chrome.contextMenus.create).toHaveBeenNthCalledWith(1, {
|
||
|
contexts: ['all'],
|
||
|
documentUrlPatterns,
|
||
|
id: EXTENSION_MENU_ITEM_ID,
|
||
|
title: 'Cookie Dialog Monster',
|
||
|
});
|
||
|
expect(chrome.contextMenus.create).toHaveBeenNthCalledWith(2, {
|
||
|
contexts: ['all'],
|
||
|
documentUrlPatterns,
|
||
|
id: SETTINGS_MENU_ITEM_ID,
|
||
|
parentId: EXTENSION_MENU_ITEM_ID,
|
||
|
title: chrome.i18n.getMessage('contextMenu_settingsOption'),
|
||
|
});
|
||
|
expect(chrome.contextMenus.create).toHaveBeenNthCalledWith(3, {
|
||
|
contexts: ['all'],
|
||
|
documentUrlPatterns,
|
||
|
id: REPORT_MENU_ITEM_ID,
|
||
|
parentId: EXTENSION_MENU_ITEM_ID,
|
||
|
title: chrome.i18n.getMessage('contextMenu_reportOption'),
|
||
|
});
|
||
|
expect(chrome.storage.local.remove).toHaveBeenCalledWith('updateAvailable');
|
||
|
expect(databaseRefreshHandler).toHaveBeenCalledWith(
|
||
|
{ name: 'database/refresh' },
|
||
|
{ send: expect.any(Function) }
|
||
|
);
|
||
|
});
|
||
|
});
|