32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { beforeEach, describe, expect, it, jest } from '@jest/globals';
|
|
|
|
import onClicked from '~background/utils/contextMenus/onClicked';
|
|
import { REPORT_MENU_ITEM_ID, SETTINGS_MENU_ITEM_ID } from '~utils/constants';
|
|
|
|
describe('background/utils/runtime/onClicked.ts', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should call chrome.action.openPopup when REPORT_MENU_ITEM_ID is clicked', () => {
|
|
const data = { menuItemId: REPORT_MENU_ITEM_ID } as chrome.contextMenus.OnClickData;
|
|
onClicked(data);
|
|
expect(chrome.runtime.openOptionsPage).not.toHaveBeenCalled();
|
|
expect(chrome.action.openPopup).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should call chrome.runtime.openOptionsPage when SETTINGS_MENU_ITEM_ID is clicked', () => {
|
|
const data = { menuItemId: SETTINGS_MENU_ITEM_ID } as chrome.contextMenus.OnClickData;
|
|
onClicked(data);
|
|
expect(chrome.runtime.openOptionsPage).toHaveBeenCalled();
|
|
expect(chrome.action.openPopup).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should do nothing when an unrecognized menu item ID is clicked', () => {
|
|
const data = { menuItemId: 'UNKNOWN_MENU_ITEM_ID' } as chrome.contextMenus.OnClickData;
|
|
onClicked(data);
|
|
expect(chrome.runtime.openOptionsPage).not.toHaveBeenCalled();
|
|
expect(chrome.action.openPopup).not.toHaveBeenCalled();
|
|
});
|
|
});
|