diff options
Diffstat (limited to 'spec/frontend/deploy_freeze')
4 files changed, 75 insertions, 4 deletions
diff --git a/spec/frontend/deploy_freeze/components/deploy_freeze_table_spec.js b/spec/frontend/deploy_freeze/components/deploy_freeze_table_spec.js index 168ddcfeacc..403d0dce3fc 100644 --- a/spec/frontend/deploy_freeze/components/deploy_freeze_table_spec.js +++ b/spec/frontend/deploy_freeze/components/deploy_freeze_table_spec.js @@ -1,3 +1,4 @@ +import { GlModal } from '@gitlab/ui'; import { createLocalVue, mount } from '@vue/test-utils'; import Vuex from 'vuex'; import DeployFreezeTable from '~/deploy_freeze/components/deploy_freeze_table.vue'; @@ -29,6 +30,8 @@ describe('Deploy freeze table', () => { const findAddDeployFreezeButton = () => wrapper.find('[data-testid="add-deploy-freeze"]'); const findEditDeployFreezeButton = () => wrapper.find('[data-testid="edit-deploy-freeze"]'); const findDeployFreezeTable = () => wrapper.find('[data-testid="deploy-freeze-table"]'); + const findDeleteDeployFreezeButton = () => wrapper.find('[data-testid="delete-deploy-freeze"]'); + const findDeleteDeployFreezeModal = () => wrapper.findComponent(GlModal); beforeEach(() => { createComponent(); @@ -73,6 +76,29 @@ describe('Deploy freeze table', () => { store.state.freezePeriods[0], ); }); + + it('displays delete deploy freeze button', () => { + expect(findDeleteDeployFreezeButton().exists()).toBe(true); + }); + + it('confirms a user wants to delete a deploy freeze', async () => { + const [{ freezeStart, freezeEnd, cronTimezone }] = store.state.freezePeriods; + await findDeleteDeployFreezeButton().trigger('click'); + const modal = findDeleteDeployFreezeModal(); + expect(modal.text()).toContain( + `Deploy freeze from ${freezeStart} to ${freezeEnd} in ${cronTimezone.formattedTimezone} will be removed.`, + ); + }); + + it('deletes the freeze period on confirmation', async () => { + await findDeleteDeployFreezeButton().trigger('click'); + const modal = findDeleteDeployFreezeModal(); + modal.vm.$emit('primary'); + expect(store.dispatch).toHaveBeenCalledWith( + 'deleteFreezePeriod', + store.state.freezePeriods[0], + ); + }); }); }); diff --git a/spec/frontend/deploy_freeze/helpers.js b/spec/frontend/deploy_freeze/helpers.js index bfb84142662..598f14d45f6 100644 --- a/spec/frontend/deploy_freeze/helpers.js +++ b/spec/frontend/deploy_freeze/helpers.js @@ -1,7 +1,7 @@ import { secondsToHours } from '~/lib/utils/datetime_utility'; export const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze_periods.json'); -export const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json'); +export const timezoneDataFixture = getJSONFixture('/timezones/short.json'); export const findTzByName = (identifier = '') => timezoneDataFixture.find(({ name }) => name.toLowerCase() === identifier.toLowerCase()); diff --git a/spec/frontend/deploy_freeze/store/actions_spec.js b/spec/frontend/deploy_freeze/store/actions_spec.js index 6bc9c4d374c..ad67afdce75 100644 --- a/spec/frontend/deploy_freeze/store/actions_spec.js +++ b/spec/frontend/deploy_freeze/store/actions_spec.js @@ -5,6 +5,7 @@ import * as actions from '~/deploy_freeze/store/actions'; import * as types from '~/deploy_freeze/store/mutation_types'; import getInitialState from '~/deploy_freeze/store/state'; import createFlash from '~/flash'; +import * as logger from '~/lib/logger'; import axios from '~/lib/utils/axios_utils'; import { freezePeriodsFixture, timezoneDataFixture } from '../helpers'; @@ -12,6 +13,7 @@ jest.mock('~/api.js'); jest.mock('~/flash.js'); describe('deploy freeze store actions', () => { + const freezePeriodFixture = freezePeriodsFixture[0]; let mock; let state; @@ -24,6 +26,7 @@ describe('deploy freeze store actions', () => { Api.freezePeriods.mockResolvedValue({ data: freezePeriodsFixture }); Api.createFreezePeriod.mockResolvedValue(); Api.updateFreezePeriod.mockResolvedValue(); + Api.deleteFreezePeriod.mockResolvedValue(); }); afterEach(() => { @@ -195,4 +198,46 @@ describe('deploy freeze store actions', () => { ); }); }); + + describe('deleteFreezePeriod', () => { + it('dispatch correct actions on deleting a freeze period', () => { + testAction( + actions.deleteFreezePeriod, + freezePeriodFixture, + state, + [ + { type: 'REQUEST_DELETE_FREEZE_PERIOD', payload: freezePeriodFixture.id }, + { type: 'RECEIVE_DELETE_FREEZE_PERIOD_SUCCESS', payload: freezePeriodFixture.id }, + ], + [], + () => + expect(Api.deleteFreezePeriod).toHaveBeenCalledWith( + state.projectId, + freezePeriodFixture.id, + ), + ); + }); + + it('should show flash error and set error in state on delete failure', () => { + jest.spyOn(logger, 'logError').mockImplementation(); + const error = new Error(); + Api.deleteFreezePeriod.mockRejectedValue(error); + + testAction( + actions.deleteFreezePeriod, + freezePeriodFixture, + state, + [ + { type: 'REQUEST_DELETE_FREEZE_PERIOD', payload: freezePeriodFixture.id }, + { type: 'RECEIVE_DELETE_FREEZE_PERIOD_ERROR', payload: freezePeriodFixture.id }, + ], + [], + () => { + expect(createFlash).toHaveBeenCalled(); + + expect(logger.logError).toHaveBeenCalledWith('Unable to delete deploy freeze', error); + }, + ); + }); + }); }); diff --git a/spec/frontend/deploy_freeze/store/mutations_spec.js b/spec/frontend/deploy_freeze/store/mutations_spec.js index f8683489340..878a755088c 100644 --- a/spec/frontend/deploy_freeze/store/mutations_spec.js +++ b/spec/frontend/deploy_freeze/store/mutations_spec.js @@ -28,9 +28,9 @@ describe('Deploy freeze mutations', () => { describe('RECEIVE_FREEZE_PERIODS_SUCCESS', () => { it('should set freeze periods and format timezones from identifiers to names', () => { const timezoneNames = { - 'Europe/Berlin': 'Berlin', - 'Etc/UTC': 'UTC', - 'America/New_York': 'Eastern Time (US & Canada)', + 'Europe/Berlin': '[UTC 2] Berlin', + 'Etc/UTC': '[UTC 0] UTC', + 'America/New_York': '[UTC -4] Eastern Time (US & Canada)', }; mutations[types.RECEIVE_FREEZE_PERIODS_SUCCESS](stateCopy, freezePeriodsFixture); |