blob: d05b3fbdce2bf1a0978c53e24f0f9ff1466f50c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
describe('~/behaviors/shortcuts/keybindings.js', () => {
let keysFor;
let TOGGLE_PERFORMANCE_BAR;
let LOCAL_STORAGE_KEY;
beforeAll(() => {
useLocalStorageSpy();
});
const setupCustomizations = async (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'
));
};
describe('when a command has not been customized', () => {
beforeEach(async () => {
await setupCustomizations('{}');
});
it('returns the default keybinding for the command', () => {
expect(keysFor(TOGGLE_PERFORMANCE_BAR)).toEqual(['p b']);
});
});
describe('when a command has been customized', () => {
const customization = ['p b a r'];
beforeEach(async () => {
await setupCustomizations(JSON.stringify({ [TOGGLE_PERFORMANCE_BAR]: customization }));
});
it('returns the default keybinding for the command', () => {
expect(keysFor(TOGGLE_PERFORMANCE_BAR)).toEqual(customization);
});
});
describe("when the localStorage entry isn't valid JSON", () => {
beforeEach(async () => {
await setupCustomizations('{');
});
it('returns the default keybinding for the command', () => {
expect(keysFor(TOGGLE_PERFORMANCE_BAR)).toEqual(['p b']);
});
});
describe(`when localStorage doesn't contain the ${LOCAL_STORAGE_KEY} key`, () => {
beforeEach(async () => {
await setupCustomizations();
});
it('returns the default keybinding for the command', () => {
expect(keysFor(TOGGLE_PERFORMANCE_BAR)).toEqual(['p b']);
});
});
});
|