Commit 6aeaaee6 authored by Mark Florian's avatar Mark Florian

Add test for alert dismissal

This also fixes an edge case in the `useLocalStorageSpy` helper, which
didn't initialise the localStorage getter properly in the case that
earlier, unrelated `describe` blocks in the same suite rely on real
`localStorage` behaviour, or just don't need it to be mocked.
parent 02b3b8a5
......@@ -4,6 +4,7 @@ import { GlAlert, GlLink } from '@gitlab/ui';
import SecurityConfigurationApp from 'ee/security_configuration/components/app.vue';
import ManageFeature from 'ee/security_configuration/components/manage_feature.vue';
import stubChildren from 'helpers/stub_children';
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import { generateFeatures } from './helpers';
......@@ -127,6 +128,35 @@ describe('Security Configuration App', () => {
}
},
);
describe('dismissing the alert', () => {
useLocalStorageSpy();
beforeEach(() => {
createComponent({
propsData: {
gitlabCiPresent: false,
autoDevopsEnabled: false,
canEnableAutoDevops: true,
},
stubs: {
LocalStorageSync,
},
});
getAlert().vm.$emit('dismiss');
});
it('hides the alert', () => {
expect(getAlert().exists()).toBe(false);
});
it('saves dismissal in localStorage', () => {
expect(localStorage.setItem.mock.calls).toEqual([
[SecurityConfigurationApp.autoDevopsAlertStorageKey, 'true'],
]);
});
});
});
describe('features table', () => {
......
......@@ -10,7 +10,7 @@
*/
const useLocalStorage = fn => {
const origLocalStorage = window.localStorage;
let currentLocalStorage;
let currentLocalStorage = origLocalStorage;
Object.defineProperty(window, 'localStorage', {
get: () => currentLocalStorage,
......
import { useLocalStorageSpy } from './local_storage_helper';
useLocalStorageSpy();
describe('block before helper is installed', () => {
it('should leave original localStorage intact', () => {
expect(localStorage.getItem).toEqual(expect.any(Function));
expect(jest.isMockFunction(localStorage.getItem)).toBe(false);
});
});
describe('localStorage helper', () => {
useLocalStorageSpy();
it('mocks localStorage but works exactly like original localStorage', () => {
localStorage.setItem('test', 'testing');
localStorage.setItem('test2', 'testing');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment