Skip to content

Commit

Permalink
chore: add missing unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Oct 29, 2023
1 parent 80dfdd2 commit a54db8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ describe('ContextMenu Plugin', () => {

it('should create a Context Menu item with commands sub-menu items and expect sub-menu list to show in the DOM element when sub-menu is clicked', () => {
const actionMock = jest.fn();
const disposeSubMenuSpy = jest.spyOn(plugin, 'disposeSubMenus');
jest.spyOn(getEditorLockMock, 'commitCurrentEdit').mockReturnValue(true);

plugin.dispose();
Expand All @@ -668,6 +669,7 @@ describe('ContextMenu Plugin', () => {

let contextMenu1Elm = document.body.querySelector('.slick-context-menu.slickgrid12345.slick-menu-level-0') as HTMLDivElement;
const commandList1Elm = contextMenu1Elm.querySelector('.slick-menu-command-list') as HTMLDivElement;
const deleteRowCommandElm = commandList1Elm.querySelector('[data-command="delete-row"]') as HTMLDivElement;
const subCommands1Elm = commandList1Elm.querySelector('[data-command="sub-commands"]') as HTMLDivElement;
const commandContentElm2 = subCommands1Elm.querySelector('.slick-menu-content') as HTMLDivElement;
const commandChevronElm = commandList1Elm.querySelector('.sub-item-chevron') as HTMLSpanElement;
Expand Down Expand Up @@ -706,6 +708,10 @@ describe('ContextMenu Plugin', () => {
document.body.dispatchEvent(subCommandEvent);
contextMenu2Elm = document.body.querySelector('.slick-context-menu.slickgrid12345.slick-menu-level-1') as HTMLDivElement;
expect(contextMenu2Elm).toBeTruthy();

// calling another command on parent menu should dispose sub-menus
deleteRowCommandElm!.dispatchEvent(new Event('mouseover'));
expect(disposeSubMenuSpy).toHaveBeenCalledTimes(4);
});

it('should create a Context Menu and expect the button click handler & "action" callback to be executed when defined', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ describe('GridMenuControl', () => {
const commandList1Elm = gridMenu1Elm.querySelector('.slick-menu-command-list') as HTMLDivElement;
Object.defineProperty(commandList1Elm, 'clientWidth', { writable: true, configurable: true, value: 70 });
const subCommands1Elm = commandList1Elm.querySelector('[data-command="sub-commands"]') as HTMLDivElement;
const helpCommandElm = commandList1Elm.querySelector('[data-command="help"]') as HTMLDivElement;
Object.defineProperty(subCommands1Elm, 'clientWidth', { writable: true, configurable: true, value: 70 });
const commandContentElm2 = subCommands1Elm.querySelector('.slick-menu-content') as HTMLDivElement;
const commandChevronElm = commandList1Elm.querySelector('.sub-item-chevron') as HTMLSpanElement;
Expand Down Expand Up @@ -957,9 +958,15 @@ describe('GridMenuControl', () => {
subCommands1Elm!.dispatchEvent(new Event('click'));
expect(disposeSubMenuSpy).toHaveBeenCalledTimes(0);
const subCommands12Elm = commandList1Elm.querySelector('[data-command="sub-commands2"]') as HTMLDivElement;
subCommands12Elm!.dispatchEvent(new Event('click'));
subCommands12Elm!.dispatchEvent(new Event('mouseover'));
expect(disposeSubMenuSpy).toHaveBeenCalledTimes(1);
expect(disposeSubMenuSpy).toHaveBeenCalled();
subCommands1Elm!.dispatchEvent(new Event('mouseover'));
expect(disposeSubMenuSpy).toHaveBeenCalledTimes(2);

// calling another command on parent menu should dispose sub-menus
helpCommandElm!.dispatchEvent(new Event('mouseover'));
expect(disposeSubMenuSpy).toHaveBeenCalledTimes(3);
});

it('should create a Cell Menu item with commands sub-menu items and expect sub-menu list to show in the DOM element align right when sub-menu is clicked', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ describe('HeaderMenu Plugin', () => {
const headerMenu1Elm = gridContainerDiv.querySelector('.slick-header-menu.slick-menu-level-0') as HTMLDivElement;
const commandList1Elm = headerMenu1Elm.querySelector('.slick-menu-command-list') as HTMLDivElement;
Object.defineProperty(commandList1Elm, 'clientWidth', { writable: true, configurable: true, value: 70 });
const helpCommandElm = commandList1Elm.querySelector('[data-command="help"]') as HTMLDivElement;
const subCommands1Elm = commandList1Elm.querySelector('[data-command="sub-commands"]') as HTMLDivElement;
Object.defineProperty(subCommands1Elm, 'clientWidth', { writable: true, configurable: true, value: 70 });
const commandContentElm2 = subCommands1Elm.querySelector('.slick-menu-content') as HTMLDivElement;
Expand Down Expand Up @@ -688,6 +689,10 @@ describe('HeaderMenu Plugin', () => {
subCommands12Elm!.dispatchEvent(new Event('click'));
expect(disposeSubMenuSpy).toHaveBeenCalledTimes(2);
expect(disposeSubMenuSpy).toHaveBeenCalled();

// calling another command on parent menu should dispose sub-menus
helpCommandElm!.dispatchEvent(new Event('mouseover'));
expect(disposeSubMenuSpy).toHaveBeenCalledTimes(3);
});

it('should create a Header Menu item with commands sub-menu commandItems and expect sub-menu list to show in the DOM element align right when sub-menu is clicked', () => {
Expand Down

0 comments on commit a54db8e

Please sign in to comment.