debian-mirror-gitlab/spec/frontend/jira_connect/utils_spec.js

33 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-04-17 20:07:23 +05:30
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import { ALERT_LOCALSTORAGE_KEY } from '~/jira_connect/constants';
import { persistAlert, retrieveAlert } from '~/jira_connect/utils';
useLocalStorageSpy();
describe('JiraConnect utils', () => {
describe('alert utils', () => {
it.each`
arg | expectedRetrievedValue
${{ title: 'error' }} | ${{ title: 'error' }}
${{ title: 'error', randomKey: 'test' }} | ${{ title: 'error' }}
${{ title: 'error', message: 'error message', linkUrl: 'link', variant: 'danger' }} | ${{ title: 'error', message: 'error message', linkUrl: 'link', variant: 'danger' }}
${undefined} | ${{}}
`(
'persists and retrieves alert data from localStorage when arg is $arg',
({ arg, expectedRetrievedValue }) => {
persistAlert(arg);
expect(localStorage.setItem).toHaveBeenCalledWith(
ALERT_LOCALSTORAGE_KEY,
JSON.stringify(expectedRetrievedValue),
);
const retrievedValue = retrieveAlert();
expect(localStorage.getItem).toHaveBeenCalledWith(ALERT_LOCALSTORAGE_KEY);
expect(retrievedValue).toEqual(expectedRetrievedValue);
},
);
});
});