diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/frontend/jira_import/utils | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/frontend/jira_import/utils')
-rw-r--r-- | spec/frontend/jira_import/utils/jira_import_utils_spec.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/frontend/jira_import/utils/jira_import_utils_spec.js b/spec/frontend/jira_import/utils/jira_import_utils_spec.js index 504d399217a..8ae1fc3535a 100644 --- a/spec/frontend/jira_import/utils/jira_import_utils_spec.js +++ b/spec/frontend/jira_import/utils/jira_import_utils_spec.js @@ -1,10 +1,16 @@ +import { useLocalStorageSpy } from 'helpers/local_storage_helper'; import { calculateJiraImportLabel, extractJiraProjectsOptions, IMPORT_STATE, isFinished, isInProgress, + setFinishedAlertHideMap, + shouldShowFinishedAlert, } from '~/jira_import/utils/jira_import_utils'; +import { JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY } from '~/issuables_list/constants'; + +useLocalStorageSpy(); describe('isInProgress', () => { it.each` @@ -89,3 +95,56 @@ describe('calculateJiraImportLabel', () => { expect(label.color).toBe('#333'); }); }); + +describe('shouldShowFinishedAlert', () => { + const labelTitle = 'jira-import::JCP-1'; + + afterEach(() => { + localStorage.clear(); + }); + + it('checks localStorage value', () => { + jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({})); + + shouldShowFinishedAlert(labelTitle, IMPORT_STATE.FINISHED); + + expect(localStorage.getItem).toHaveBeenCalledWith(JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY); + }); + + it('returns true when an import has finished', () => { + jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({})); + + expect(shouldShowFinishedAlert(labelTitle, IMPORT_STATE.FINISHED)).toBe(true); + }); + + it('returns false when an import has finished but the user chose to hide the alert', () => { + jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({ [labelTitle]: true })); + + expect(shouldShowFinishedAlert(labelTitle, IMPORT_STATE.FINISHED)).toBe(false); + }); + + it('returns false when an import has not finished', () => { + jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({})); + + expect(shouldShowFinishedAlert(labelTitle, IMPORT_STATE.SCHEDULED)).toBe(false); + }); +}); + +describe('setFinishedAlertHideMap', () => { + const labelTitle = 'jira-import::ABC-1'; + const newLabelTitle = 'jira-import::JCP-1'; + + it('sets item to localStorage correctly', () => { + jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({ [labelTitle]: true })); + + setFinishedAlertHideMap(newLabelTitle); + + expect(localStorage.setItem).toHaveBeenCalledWith( + JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY, + JSON.stringify({ + [labelTitle]: true, + [newLabelTitle]: true, + }), + ); + }); +}); |