diff options
Diffstat (limited to 'spec/frontend/behaviors/shortcuts/keybindings_spec.js')
-rw-r--r-- | spec/frontend/behaviors/shortcuts/keybindings_spec.js | 72 |
1 files changed, 52 insertions, 20 deletions
diff --git a/spec/frontend/behaviors/shortcuts/keybindings_spec.js b/spec/frontend/behaviors/shortcuts/keybindings_spec.js index d05b3fbdce2..53ce06e78c6 100644 --- a/spec/frontend/behaviors/shortcuts/keybindings_spec.js +++ b/spec/frontend/behaviors/shortcuts/keybindings_spec.js @@ -1,33 +1,53 @@ +import { flatten } from 'lodash'; import { useLocalStorageSpy } from 'helpers/local_storage_helper'; +import { + keysFor, + getCustomizations, + keybindingGroups, + TOGGLE_PERFORMANCE_BAR, + LOCAL_STORAGE_KEY, + WEB_IDE_COMMIT, +} from '~/behaviors/shortcuts/keybindings'; -describe('~/behaviors/shortcuts/keybindings.js', () => { - let keysFor; - let TOGGLE_PERFORMANCE_BAR; - let LOCAL_STORAGE_KEY; - +describe('~/behaviors/shortcuts/keybindings', () => { beforeAll(() => { useLocalStorageSpy(); }); - const setupCustomizations = async (customizationsAsString) => { + const setupCustomizations = (customizationsAsString) => { localStorage.clear(); if (customizationsAsString) { localStorage.setItem(LOCAL_STORAGE_KEY, customizationsAsString); } - jest.resetModules(); - ({ keysFor, TOGGLE_PERFORMANCE_BAR, LOCAL_STORAGE_KEY } = await import( - '~/behaviors/shortcuts/keybindings' - )); + getCustomizations.cache.clear(); }; + describe('keybinding definition errors', () => { + beforeEach(() => { + setupCustomizations(); + }); + + it('has no duplicate group IDs', () => { + const allGroupIds = keybindingGroups.map((group) => group.id); + expect(allGroupIds).toHaveLength(new Set(allGroupIds).size); + }); + + it('has no duplicate commands IDs', () => { + const allCommandIds = flatten( + keybindingGroups.map((group) => group.keybindings.map((kb) => kb.id)), + ); + expect(allCommandIds).toHaveLength(new Set(allCommandIds).size); + }); + }); + describe('when a command has not been customized', () => { - beforeEach(async () => { - await setupCustomizations('{}'); + beforeEach(() => { + setupCustomizations('{}'); }); - it('returns the default keybinding for the command', () => { + it('returns the default keybindings for the command', () => { expect(keysFor(TOGGLE_PERFORMANCE_BAR)).toEqual(['p b']); }); }); @@ -35,18 +55,30 @@ describe('~/behaviors/shortcuts/keybindings.js', () => { describe('when a command has been customized', () => { const customization = ['p b a r']; - beforeEach(async () => { - await setupCustomizations(JSON.stringify({ [TOGGLE_PERFORMANCE_BAR]: customization })); + beforeEach(() => { + setupCustomizations(JSON.stringify({ [TOGGLE_PERFORMANCE_BAR.id]: customization })); }); - it('returns the default keybinding for the command', () => { + it('returns the custom keybindings for the command', () => { expect(keysFor(TOGGLE_PERFORMANCE_BAR)).toEqual(customization); }); }); + describe('when a command is marked as non-customizable', () => { + const customization = ['mod+shift+c']; + + beforeEach(() => { + setupCustomizations(JSON.stringify({ [WEB_IDE_COMMIT.id]: customization })); + }); + + it('returns the default keybinding for the command', () => { + expect(keysFor(WEB_IDE_COMMIT)).toEqual(['mod+enter']); + }); + }); + describe("when the localStorage entry isn't valid JSON", () => { - beforeEach(async () => { - await setupCustomizations('{'); + beforeEach(() => { + setupCustomizations('{'); }); it('returns the default keybinding for the command', () => { @@ -55,8 +87,8 @@ describe('~/behaviors/shortcuts/keybindings.js', () => { }); describe(`when localStorage doesn't contain the ${LOCAL_STORAGE_KEY} key`, () => { - beforeEach(async () => { - await setupCustomizations(); + beforeEach(() => { + setupCustomizations(); }); it('returns the default keybinding for the command', () => { |