Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-15 00:09:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-15 00:09:33 +0300
commit791f72d8ff71daaec3f18e254f5d8ca9267cfc8b (patch)
tree5194ab2cccd5509d7db18be29b1620447ac39178 /spec/frontend/behaviors
parentaf21f4fd32f5a99ef57215b458e49f23af7e503d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/behaviors')
-rw-r--r--spec/frontend/behaviors/shortcuts/keybindings_spec.js72
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', () => {