Skip to content

Commit

Permalink
Tests for sorting shortcut columns (jupyterlab#16098)
Browse files Browse the repository at this point in the history
* Tests for sorting shortcut columns

* Lint checks

* Adapting review comments.
  • Loading branch information
itsmevichu authored Apr 3, 2024
1 parent 41be86d commit d4b000f
Showing 1 changed file with 148 additions and 0 deletions.
148 changes: 148 additions & 0 deletions packages/shortcuts-extension/test/components/ShortcutUI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,153 @@ describe('@jupyterlab/shortcut-extension', () => {
expect(data.user.shortcuts).toHaveLength(1);
});
});

describe('#sortShortcuts()', () => {
let mockedFilteredShortcutList: IShortcutTarget[];
beforeEach(() => {
mockedFilteredShortcutList = [
{
id: '1',
label: 'Zebra',
command: 'Zebra',
selector: 'Zebra',
category: 'Zebra',
keybindings: [{ keys: ['Ctrl+Z', 'Z'], isDefault: false }],
args: undefined
},
{
id: '2',
label: 'Apple',
command: 'Apple',
selector: 'Apple',
category: 'Apple',
keybindings: [{ keys: ['Shift+A', 'A'], isDefault: true }],
args: undefined
},
{
id: '3',
label: 'Banana',
command: 'Banana',
selector: 'Banana',
category: 'Banana',
keybindings: [{ keys: ['Ctrl+B', 'B'], isDefault: false }],
args: undefined
},
{
id: '4',
label: 'Tomato',
command: 'Tomato',
selector: 'Tomato',
category: 'Tomato',
keybindings: [{ keys: ['Tab+T', 'T'], isDefault: true }],
args: undefined
}
];
});

it('should test sort by the `category` column', () => {
shortcutUI.state = {
...shortcutUI.state,
currentSort: 'category',
filteredShortcutList: mockedFilteredShortcutList
};

expect(shortcutUI.state.filteredShortcutList[0].category).not.toBe(
'Apple'
);
shortcutUI.sortShortcuts();
expect(shortcutUI.state.filteredShortcutList[0].category).toBe('Apple');
expect(shortcutUI.state.filteredShortcutList[1].category).toBe(
'Banana'
);
expect(shortcutUI.state.filteredShortcutList[2].category).toBe(
'Tomato'
);
expect(shortcutUI.state.filteredShortcutList[3].category).toBe('Zebra');
});

it('should test sort by the `command` column', () => {
shortcutUI.state = {
...shortcutUI.state,
currentSort: 'command',
filteredShortcutList: mockedFilteredShortcutList
};

expect(shortcutUI.state.filteredShortcutList[0].label).not.toBe(
'Apple'
);
shortcutUI.sortShortcuts();
expect(shortcutUI.state.filteredShortcutList[0].label).toBe('Apple');
expect(shortcutUI.state.filteredShortcutList[1].label).toBe('Banana');
expect(shortcutUI.state.filteredShortcutList[2].label).toBe('Tomato');
expect(shortcutUI.state.filteredShortcutList[3].label).toBe('Zebra');
});

it('should test sort by the `selector` column', () => {
shortcutUI.state = {
...shortcutUI.state,
currentSort: 'selector',
filteredShortcutList: mockedFilteredShortcutList
};

expect(shortcutUI.state.filteredShortcutList[0].selector).not.toBe(
'Apple'
);
shortcutUI.sortShortcuts();
expect(shortcutUI.state.filteredShortcutList[0].selector).toBe('Apple');
expect(shortcutUI.state.filteredShortcutList[1].selector).toBe(
'Banana'
);
expect(shortcutUI.state.filteredShortcutList[2].selector).toBe(
'Tomato'
);
expect(shortcutUI.state.filteredShortcutList[3].selector).toBe('Zebra');
});

it('should test sort by the `source` column', () => {
shortcutUI.state = {
...shortcutUI.state,
currentSort: 'source',
filteredShortcutList: mockedFilteredShortcutList
};

expect(
shortcutUI.state.filteredShortcutList[0].keybindings.every(
k => k.isDefault
)
? 'default'
: 'other'
).toBe('other');
shortcutUI.sortShortcuts();
expect(
shortcutUI.state.filteredShortcutList[0].keybindings.every(
k => k.isDefault
)
? 'default'
: 'other'
).toBe('default');
expect(
shortcutUI.state.filteredShortcutList[1].keybindings.every(
k => k.isDefault
)
? 'default'
: 'other'
).toBe('default');
expect(
shortcutUI.state.filteredShortcutList[2].keybindings.every(
k => k.isDefault
)
? 'default'
: 'other'
).toBe('other');
expect(
shortcutUI.state.filteredShortcutList[3].keybindings.every(
k => k.isDefault
)
? 'default'
: 'other'
).toBe('other');
});
});
});
});

0 comments on commit d4b000f

Please sign in to comment.