diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/frontend/behaviors | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/frontend/behaviors')
-rw-r--r-- | spec/frontend/behaviors/load_startup_css_spec.js | 44 | ||||
-rw-r--r-- | spec/frontend/behaviors/shortcuts/keybindings_spec.js | 66 |
2 files changed, 110 insertions, 0 deletions
diff --git a/spec/frontend/behaviors/load_startup_css_spec.js b/spec/frontend/behaviors/load_startup_css_spec.js new file mode 100644 index 00000000000..81222ac5aaa --- /dev/null +++ b/spec/frontend/behaviors/load_startup_css_spec.js @@ -0,0 +1,44 @@ +import { setHTMLFixture } from 'helpers/fixtures'; +import { loadStartupCSS } from '~/behaviors/load_startup_css'; + +describe('behaviors/load_startup_css', () => { + let loadListener; + + const setupListeners = () => { + document + .querySelectorAll('link') + .forEach(x => x.addEventListener('load', () => loadListener(x))); + }; + + beforeEach(() => { + loadListener = jest.fn(); + + setHTMLFixture(` + <meta charset="utf-8" /> + <link media="print" src="./lorem-print.css" /> + <link media="print" src="./ipsum-print.css" /> + <link media="all" src="./dolar-all.css" /> + `); + + setupListeners(); + + loadStartupCSS(); + }); + + it('does nothing at first', () => { + expect(loadListener).not.toHaveBeenCalled(); + }); + + describe('on window load', () => { + beforeEach(() => { + window.dispatchEvent(new Event('load')); + }); + + it('dispatches load to the print links', () => { + expect(loadListener.mock.calls.map(([el]) => el.getAttribute('src'))).toEqual([ + './lorem-print.css', + './ipsum-print.css', + ]); + }); + }); +}); diff --git a/spec/frontend/behaviors/shortcuts/keybindings_spec.js b/spec/frontend/behaviors/shortcuts/keybindings_spec.js new file mode 100644 index 00000000000..23fea79f828 --- /dev/null +++ b/spec/frontend/behaviors/shortcuts/keybindings_spec.js @@ -0,0 +1,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']); + }); + }); +}); |