diff options
Diffstat (limited to 'spec/frontend/jira_import')
7 files changed, 621 insertions, 166 deletions
diff --git a/spec/frontend/jira_import/components/__snapshots__/jira_import_form_spec.js.snap b/spec/frontend/jira_import/components/__snapshots__/jira_import_form_spec.js.snap new file mode 100644 index 00000000000..975c31bb59c --- /dev/null +++ b/spec/frontend/jira_import/components/__snapshots__/jira_import_form_spec.js.snap @@ -0,0 +1,277 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`JiraImportForm table body shows correct information in each cell 1`] = ` +<table + aria-busy="false" + aria-colcount="3" + class="table b-table gl-table b-table-fixed" + role="table" +> + <!----> + <!----> + <thead + class="" + role="rowgroup" + > + <!----> + <tr + class="" + role="row" + > + <th + aria-colindex="1" + class="" + role="columnheader" + scope="col" + > + Jira display name + </th> + <th + aria-colindex="2" + aria-label="Arrow" + class="" + role="columnheader" + scope="col" + /> + <th + aria-colindex="3" + class="" + role="columnheader" + scope="col" + > + GitLab username + </th> + </tr> + </thead> + <tbody + role="rowgroup" + > + <!----> + <tr + class="" + role="row" + > + <td + aria-colindex="1" + class="" + role="cell" + > + Jane Doe + </td> + <td + aria-colindex="2" + class="" + role="cell" + > + <svg + aria-label="Will be mapped to" + class="gl-icon s16" + data-testid="arrow-right-icon" + > + <use + href="#arrow-right" + /> + </svg> + </td> + <td + aria-colindex="3" + class="" + role="cell" + > + <div + aria-label="The GitLab user to which the Jira user Jane Doe will be mapped" + class="dropdown b-dropdown gl-new-dropdown w-100 btn-group" + > + <!----> + <button + aria-expanded="false" + aria-haspopup="true" + class="btn dropdown-toggle btn-default btn-md gl-button gl-dropdown-toggle" + type="button" + > + <!----> + + <span + class="gl-new-dropdown-button-text" + > + janedoe + </span> + + <svg + class="dropdown-chevron gl-icon s16" + data-testid="chevron-down-icon" + > + <use + href="#chevron-down" + /> + </svg> + </button> + <ul + class="dropdown-menu" + role="menu" + tabindex="-1" + > + <!----> + + <div + class="gl-search-box-by-type m-2" + > + <svg + class="gl-search-box-by-type-search-icon gl-icon s16" + data-testid="search-icon" + > + <use + href="#search" + /> + </svg> + + <input + aria-label="Search" + class="gl-form-input gl-search-box-by-type-input form-control" + placeholder="Search" + type="text" + /> + + <div + class="gl-search-box-by-type-right-icons" + > + <!----> + + <!----> + </div> + </div> + + <li + class="gl-new-dropdown-text text-secondary" + role="presentation" + > + <p + class="b-dropdown-text" + > + + No matches found + + </p> + </li> + + </ul> + </div> + </td> + </tr> + <tr + class="" + role="row" + > + <td + aria-colindex="1" + class="" + role="cell" + > + Fred Chopin + </td> + <td + aria-colindex="2" + class="" + role="cell" + > + <svg + aria-label="Will be mapped to" + class="gl-icon s16" + data-testid="arrow-right-icon" + > + <use + href="#arrow-right" + /> + </svg> + </td> + <td + aria-colindex="3" + class="" + role="cell" + > + <div + aria-label="The GitLab user to which the Jira user Fred Chopin will be mapped" + class="dropdown b-dropdown gl-new-dropdown w-100 btn-group" + > + <!----> + <button + aria-expanded="false" + aria-haspopup="true" + class="btn dropdown-toggle btn-default btn-md gl-button gl-dropdown-toggle" + type="button" + > + <!----> + + <span + class="gl-new-dropdown-button-text" + > + mrgitlab + </span> + + <svg + class="dropdown-chevron gl-icon s16" + data-testid="chevron-down-icon" + > + <use + href="#chevron-down" + /> + </svg> + </button> + <ul + class="dropdown-menu" + role="menu" + tabindex="-1" + > + <!----> + + <div + class="gl-search-box-by-type m-2" + > + <svg + class="gl-search-box-by-type-search-icon gl-icon s16" + data-testid="search-icon" + > + <use + href="#search" + /> + </svg> + + <input + aria-label="Search" + class="gl-form-input gl-search-box-by-type-input form-control" + placeholder="Search" + type="text" + /> + + <div + class="gl-search-box-by-type-right-icons" + > + <!----> + + <!----> + </div> + </div> + + <li + class="gl-new-dropdown-text text-secondary" + role="presentation" + > + <p + class="b-dropdown-text" + > + + No matches found + + </p> + </li> + + </ul> + </div> + </td> + </tr> + <!----> + <!----> + </tbody> + <!----> +</table> +`; diff --git a/spec/frontend/jira_import/components/jira_import_app_spec.js b/spec/frontend/jira_import/components/jira_import_app_spec.js index a21b89f6517..074f9842512 100644 --- a/spec/frontend/jira_import/components/jira_import_app_spec.js +++ b/spec/frontend/jira_import/components/jira_import_app_spec.js @@ -1,88 +1,19 @@ import { GlAlert, GlLoadingIcon } from '@gitlab/ui'; import { mount, shallowMount } from '@vue/test-utils'; +import AxiosMockAdapter from 'axios-mock-adapter'; import Vue from 'vue'; +import axios from '~/lib/utils/axios_utils'; import JiraImportApp from '~/jira_import/components/jira_import_app.vue'; import JiraImportForm from '~/jira_import/components/jira_import_form.vue'; import JiraImportProgress from '~/jira_import/components/jira_import_progress.vue'; import JiraImportSetup from '~/jira_import/components/jira_import_setup.vue'; import initiateJiraImportMutation from '~/jira_import/queries/initiate_jira_import.mutation.graphql'; - -const mountComponent = ({ - isJiraConfigured = true, - errorMessage = '', - selectedProject = 'MTG', - showAlert = false, - isInProgress = false, - loading = false, - mutate = jest.fn(() => Promise.resolve()), - mountType, -} = {}) => { - const mountFunction = mountType === 'mount' ? mount : shallowMount; - - return mountFunction(JiraImportApp, { - propsData: { - inProgressIllustration: 'in-progress-illustration.svg', - isJiraConfigured, - issuesPath: 'gitlab-org/gitlab-test/-/issues', - jiraIntegrationPath: 'gitlab-org/gitlab-test/-/services/jira/edit', - projectPath: 'gitlab-org/gitlab-test', - setupIllustration: 'setup-illustration.svg', - }, - data() { - return { - errorMessage, - showAlert, - selectedProject, - jiraImportDetails: { - isInProgress, - imports: [ - { - jiraProjectKey: 'MTG', - scheduledAt: '2020-04-08T10:11:12+00:00', - scheduledBy: { - name: 'John Doe', - }, - }, - { - jiraProjectKey: 'MSJP', - scheduledAt: '2020-04-09T13:14:15+00:00', - scheduledBy: { - name: 'Jimmy Doe', - }, - }, - { - jiraProjectKey: 'MTG', - scheduledAt: '2020-04-09T16:17:18+00:00', - scheduledBy: { - name: 'Jane Doe', - }, - }, - ], - mostRecentImport: { - jiraProjectKey: 'MTG', - scheduledAt: '2020-04-09T16:17:18+00:00', - scheduledBy: { - name: 'Jane Doe', - }, - }, - projects: [ - { text: 'My Jira Project (MJP)', value: 'MJP' }, - { text: 'My Second Jira Project (MSJP)', value: 'MSJP' }, - { text: 'Migrate to GitLab (MTG)', value: 'MTG' }, - ], - }, - }; - }, - mocks: { - $apollo: { - loading, - mutate, - }, - }, - }); -}; +import getJiraUserMappingMutation from '~/jira_import/queries/get_jira_user_mapping.mutation.graphql'; +import { imports, issuesPath, jiraIntegrationPath, jiraProjects, userMappings } from '../mock_data'; describe('JiraImportApp', () => { + let axiosMock; + let mutateSpy; let wrapper; const getFormComponent = () => wrapper.find(JiraImportForm); @@ -95,7 +26,64 @@ describe('JiraImportApp', () => { const getLoadingIcon = () => wrapper.find(GlLoadingIcon); + const mountComponent = ({ + isJiraConfigured = true, + errorMessage = '', + selectedProject = 'MTG', + showAlert = false, + isInProgress = false, + loading = false, + mutate = mutateSpy, + mountFunction = shallowMount, + } = {}) => + mountFunction(JiraImportApp, { + propsData: { + inProgressIllustration: 'in-progress-illustration.svg', + isJiraConfigured, + issuesPath, + jiraIntegrationPath, + projectId: '5', + projectPath: 'gitlab-org/gitlab-test', + setupIllustration: 'setup-illustration.svg', + }, + data() { + return { + isSubmitting: false, + selectedProject, + userMappings, + errorMessage, + showAlert, + jiraImportDetails: { + isInProgress, + imports, + mostRecentImport: imports[imports.length - 1], + projects: jiraProjects, + }, + }; + }, + mocks: { + $apollo: { + loading, + mutate, + }, + }, + }); + + beforeEach(() => { + axiosMock = new AxiosMockAdapter(axios); + mutateSpy = jest.fn(() => + Promise.resolve({ + data: { + jiraImportStart: { errors: [] }, + jiraImportUsers: { jiraUsers: [], errors: [] }, + }, + }), + ); + }); + afterEach(() => { + axiosMock.restore(); + mutateSpy.mockRestore(); wrapper.destroy(); wrapper = null; }); @@ -223,7 +211,7 @@ describe('JiraImportApp', () => { }); it('shows warning alert to explain project MTG has been imported 2 times before', () => { - wrapper = mountComponent({ mountType: 'mount' }); + wrapper = mountComponent({ mountFunction: mount }); expect(getAlert().text()).toBe( 'You have imported from this project 2 times before. Each new import will create duplicate issues.', @@ -248,9 +236,7 @@ describe('JiraImportApp', () => { describe('initiating a Jira import', () => { it('calls the mutation with the expected arguments', () => { - const mutate = jest.fn(() => Promise.resolve()); - - wrapper = mountComponent({ mutate }); + wrapper = mountComponent(); const mutationArguments = { mutation: initiateJiraImportMutation, @@ -258,13 +244,23 @@ describe('JiraImportApp', () => { input: { jiraProjectKey: 'MTG', projectPath: 'gitlab-org/gitlab-test', + usersMapping: [ + { + jiraAccountId: 'aei23f98f-q23fj98qfj', + gitlabId: 15, + }, + { + jiraAccountId: 'fu39y8t34w-rq3u289t3h4i', + gitlabId: undefined, + }, + ], }, }, }; getFormComponent().vm.$emit('initiateJiraImport', 'MTG'); - expect(mutate).toHaveBeenCalledWith(expect.objectContaining(mutationArguments)); + expect(mutateSpy).toHaveBeenCalledWith(expect.objectContaining(mutationArguments)); }); it('shows alert message with error message on error', () => { @@ -283,19 +279,53 @@ describe('JiraImportApp', () => { }); }); - it('can dismiss alert message', () => { - wrapper = mountComponent({ - errorMessage: 'There was an error importing the Jira project.', - showAlert: true, - selectedProject: null, + describe('alert', () => { + it('can be dismissed', () => { + wrapper = mountComponent({ + errorMessage: 'There was an error importing the Jira project.', + showAlert: true, + selectedProject: null, + }); + + expect(getAlert().exists()).toBe(true); + + getAlert().vm.$emit('dismiss'); + + return Vue.nextTick().then(() => { + expect(getAlert().exists()).toBe(false); + }); }); + }); - expect(getAlert().exists()).toBe(true); + describe('on mount', () => { + it('makes a GraphQL mutation call to get user mappings', () => { + wrapper = mountComponent(); - getAlert().vm.$emit('dismiss'); + const mutationArguments = { + mutation: getJiraUserMappingMutation, + variables: { + input: { + projectPath: 'gitlab-org/gitlab-test', + startAt: 1, + }, + }, + }; + + expect(mutateSpy).toHaveBeenCalledWith(expect.objectContaining(mutationArguments)); + }); + + it('does not make a GraphQL mutation call to get user mappings when Jira is not configured', () => { + wrapper = mountComponent({ isJiraConfigured: false }); + + expect(mutateSpy).not.toHaveBeenCalled(); + }); + + it('shows error message when there is an error with the GraphQL mutation call', () => { + const mutate = jest.fn(() => Promise.reject()); + + wrapper = mountComponent({ mutate }); - return Vue.nextTick().then(() => { - expect(getAlert().exists()).toBe(false); + expect(getAlert().exists()).toBe(true); }); }); }); diff --git a/spec/frontend/jira_import/components/jira_import_form_spec.js b/spec/frontend/jira_import/components/jira_import_form_spec.js index dea94e7bf1f..685b0288e92 100644 --- a/spec/frontend/jira_import/components/jira_import_form_spec.js +++ b/spec/frontend/jira_import/components/jira_import_form_spec.js @@ -1,44 +1,51 @@ -import { GlAvatar, GlButton, GlFormSelect, GlLabel } from '@gitlab/ui'; +import { GlButton, GlFormSelect, GlLabel, GlTable } from '@gitlab/ui'; +import { getByRole } from '@testing-library/dom'; import { mount, shallowMount } from '@vue/test-utils'; +import AxiosMockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; import JiraImportForm from '~/jira_import/components/jira_import_form.vue'; - -const importLabel = 'jira-import::MTG-1'; -const value = 'MTG'; - -const mountComponent = ({ mountType } = {}) => { - const mountFunction = mountType === 'mount' ? mount : shallowMount; - - return mountFunction(JiraImportForm, { - propsData: { - importLabel, - issuesPath: 'gitlab-org/gitlab-test/-/issues', - jiraProjects: [ - { - text: 'My Jira Project', - value: 'MJP', - }, - { - text: 'My Second Jira Project', - value: 'MSJP', - }, - { - text: 'Migrate to GitLab', - value: 'MTG', - }, - ], - value, - }, - }); -}; +import { issuesPath, jiraProjects, userMappings } from '../mock_data'; describe('JiraImportForm', () => { + let axiosMock; let wrapper; + const currentUsername = 'mrgitlab'; + const importLabel = 'jira-import::MTG-1'; + const value = 'MTG'; + const getSelectDropdown = () => wrapper.find(GlFormSelect); const getCancelButton = () => wrapper.findAll(GlButton).at(1); + const getHeader = name => getByRole(wrapper.element, 'columnheader', { name }); + + const mountComponent = ({ isSubmitting = false, mountFunction = shallowMount } = {}) => + mountFunction(JiraImportForm, { + propsData: { + importLabel, + isSubmitting, + issuesPath, + jiraProjects, + projectId: '5', + userMappings, + value, + }, + data: () => ({ + isFetching: false, + searchTerm: '', + selectState: null, + users: [], + }), + currentUsername, + }); + + beforeEach(() => { + axiosMock = new AxiosMockAdapter(axios); + }); + afterEach(() => { + axiosMock.restore(); wrapper.destroy(); wrapper = null; }); @@ -51,16 +58,22 @@ describe('JiraImportForm', () => { }); it('contains a list of Jira projects to select from', () => { - wrapper = mountComponent({ mountType: 'mount' }); - - const optionItems = ['My Jira Project', 'My Second Jira Project', 'Migrate to GitLab']; + wrapper = mountComponent({ mountFunction: mount }); getSelectDropdown() .findAll('option') .wrappers.forEach((optionEl, index) => { - expect(optionEl.text()).toBe(optionItems[index]); + expect(optionEl.text()).toBe(jiraProjects[index].text); }); }); + + it('emits an "input" event when the input select value changes', () => { + wrapper = mountComponent(); + + getSelectDropdown().vm.$emit('change', value); + + expect(wrapper.emitted('input')[0]).toEqual([value]); + }); }); describe('form information', () => { @@ -72,64 +85,90 @@ describe('JiraImportForm', () => { expect(wrapper.find(GlLabel).props('title')).toBe(importLabel); }); + it('shows a heading for the user mapping section', () => { + expect( + getByRole(wrapper.element, 'heading', { name: 'Jira-GitLab user mapping template' }), + ).toBeTruthy(); + }); + it('shows information to the user', () => { expect(wrapper.find('p').text()).toBe( - "For each Jira issue successfully imported, we'll create a new GitLab issue with the following data:", + 'Jira users have been matched with similar GitLab users. This can be overwritten by selecting a GitLab user from the dropdown in the "GitLab username" column. If it wasn\'t possible to match a Jira user with a GitLab user, the dropdown defaults to the user conducting the import.', ); }); + }); - it('shows jira.issue.summary for the Title', () => { - expect(wrapper.find('[id="jira-project-title"]').text()).toBe('jira.issue.summary'); - }); + describe('table', () => { + describe('headers', () => { + beforeEach(() => { + wrapper = mountComponent({ mountFunction: mount }); + }); - it('shows an avatar for the Reporter', () => { - expect(wrapper.contains(GlAvatar)).toBe(true); - }); + it('has a "Jira display name" column', () => { + expect(getHeader('Jira display name')).toBeTruthy(); + }); - it('shows jira.issue.description.content for the Description', () => { - expect(wrapper.find('[id="jira-project-description"]').text()).toBe( - 'jira.issue.description.content', - ); - }); - }); + it('has an "arrow" column', () => { + expect(getHeader('Arrow')).toBeTruthy(); + }); - describe('Next button', () => { - beforeEach(() => { - wrapper = mountComponent(); + it('has a "GitLab username" column', () => { + expect(getHeader('GitLab username')).toBeTruthy(); + }); }); - it('is shown', () => { - expect(wrapper.find(GlButton).text()).toBe('Next'); + describe('body', () => { + it('shows all user mappings', () => { + wrapper = mountComponent({ mountFunction: mount }); + + expect(wrapper.find(GlTable).findAll('tbody tr').length).toBe(userMappings.length); + }); + + it('shows correct information in each cell', () => { + wrapper = mountComponent({ mountFunction: mount }); + + expect(wrapper.find(GlTable).element).toMatchSnapshot(); + }); }); }); - describe('Cancel button', () => { - beforeEach(() => { - wrapper = mountComponent(); - }); + describe('buttons', () => { + describe('"Continue" button', () => { + it('is shown', () => { + wrapper = mountComponent(); - it('is shown', () => { - expect(getCancelButton().text()).toBe('Cancel'); - }); + expect(wrapper.find(GlButton).text()).toBe('Continue'); + }); + + it('is in loading state when the form is submitting', async () => { + wrapper = mountComponent({ isSubmitting: true }); - it('links to the Issues page', () => { - expect(getCancelButton().attributes('href')).toBe('gitlab-org/gitlab-test/-/issues'); + expect(wrapper.find(GlButton).props('loading')).toBe(true); + }); }); - }); - it('emits an "input" event when the input select value changes', () => { - wrapper = mountComponent({ mountType: 'mount' }); + describe('"Cancel" button', () => { + beforeEach(() => { + wrapper = mountComponent(); + }); - getSelectDropdown().vm.$emit('change', value); + it('is shown', () => { + expect(getCancelButton().text()).toBe('Cancel'); + }); - expect(wrapper.emitted('input')[0]).toEqual([value]); + it('links to the Issues page', () => { + expect(getCancelButton().attributes('href')).toBe(issuesPath); + }); + }); }); - it('emits an "initiateJiraImport" event with the selected dropdown value when submitted', () => { - wrapper = mountComponent(); + describe('form', () => { + it('emits an "initiateJiraImport" event with the selected dropdown value when submitted', () => { + wrapper = mountComponent(); - wrapper.find('form').trigger('submit'); + wrapper.find('form').trigger('submit'); - expect(wrapper.emitted('initiateJiraImport')[0]).toEqual([value]); + expect(wrapper.emitted('initiateJiraImport')[0]).toEqual([value]); + }); }); }); diff --git a/spec/frontend/jira_import/components/jira_import_progress_spec.js b/spec/frontend/jira_import/components/jira_import_progress_spec.js index 3ccf14554e1..ed7e1824fa3 100644 --- a/spec/frontend/jira_import/components/jira_import_progress_spec.js +++ b/spec/frontend/jira_import/components/jira_import_progress_spec.js @@ -1,14 +1,13 @@ import { GlEmptyState } from '@gitlab/ui'; import { mount, shallowMount } from '@vue/test-utils'; import JiraImportProgress from '~/jira_import/components/jira_import_progress.vue'; - -const illustration = 'illustration.svg'; -const importProject = 'JIRAPROJECT'; -const issuesPath = 'gitlab-org/gitlab-test/-/issues'; +import { illustration, issuesPath } from '../mock_data'; describe('JiraImportProgress', () => { let wrapper; + const importProject = 'JIRAPROJECT'; + const getGlEmptyStateProp = attribute => wrapper.find(GlEmptyState).props(attribute); const getParagraphText = () => wrapper.find('p').text(); diff --git a/spec/frontend/jira_import/components/jira_import_setup_spec.js b/spec/frontend/jira_import/components/jira_import_setup_spec.js index aa94dc4f503..7c84d4a166a 100644 --- a/spec/frontend/jira_import/components/jira_import_setup_spec.js +++ b/spec/frontend/jira_import/components/jira_import_setup_spec.js @@ -1,9 +1,7 @@ import { GlEmptyState } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import JiraImportSetup from '~/jira_import/components/jira_import_setup.vue'; - -const illustration = 'illustration.svg'; -const jiraIntegrationPath = 'gitlab-org/gitlab-test/-/services/jira/edit'; +import { illustration, jiraIntegrationPath } from '../mock_data'; describe('JiraImportSetup', () => { let wrapper; diff --git a/spec/frontend/jira_import/mock_data.js b/spec/frontend/jira_import/mock_data.js index e82ab53cb6f..a7447221b15 100644 --- a/spec/frontend/jira_import/mock_data.js +++ b/spec/frontend/jira_import/mock_data.js @@ -70,3 +70,56 @@ export const jiraImportMutationResponse = { __typename: 'JiraImportStartPayload', }, }; + +export const issuesPath = 'gitlab-org/gitlab-test/-/issues'; + +export const jiraIntegrationPath = 'gitlab-org/gitlab-test/-/services/jira/edit'; + +export const illustration = 'illustration.svg'; + +export const jiraProjects = [ + { text: 'My Jira Project (MJP)', value: 'MJP' }, + { text: 'My Second Jira Project (MSJP)', value: 'MSJP' }, + { text: 'Migrate to GitLab (MTG)', value: 'MTG' }, +]; + +export const imports = [ + { + jiraProjectKey: 'MTG', + scheduledAt: '2020-04-08T10:11:12+00:00', + scheduledBy: { + name: 'John Doe', + }, + }, + { + jiraProjectKey: 'MSJP', + scheduledAt: '2020-04-09T13:14:15+00:00', + scheduledBy: { + name: 'Jimmy Doe', + }, + }, + { + jiraProjectKey: 'MTG', + scheduledAt: '2020-04-09T16:17:18+00:00', + scheduledBy: { + name: 'Jane Doe', + }, + }, +]; + +export const userMappings = [ + { + jiraAccountId: 'aei23f98f-q23fj98qfj', + jiraDisplayName: 'Jane Doe', + jiraEmail: 'janedoe@example.com', + gitlabId: 15, + gitlabUsername: 'janedoe', + }, + { + jiraAccountId: 'fu39y8t34w-rq3u289t3h4i', + jiraDisplayName: 'Fred Chopin', + jiraEmail: 'fredchopin@example.com', + gitlabId: undefined, + gitlabUsername: undefined, + }, +]; 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, + }), + ); + }); +}); |