Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js')
-rw-r--r--spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js71
1 files changed, 59 insertions, 12 deletions
diff --git a/spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js b/spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js
index d8ce184940a..7c46c280d46 100644
--- a/spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js
+++ b/spec/frontend/deploy_freeze/components/deploy_freeze_modal_spec.js
@@ -1,13 +1,16 @@
import { GlButton, GlModal } from '@gitlab/ui';
-import { createLocalVue, shallowMount } from '@vue/test-utils';
+import { shallowMount } from '@vue/test-utils';
+import Vue from 'vue';
import Vuex from 'vuex';
+import Api from '~/api';
import DeployFreezeModal from '~/deploy_freeze/components/deploy_freeze_modal.vue';
import createStore from '~/deploy_freeze/store';
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
import { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
-const localVue = createLocalVue();
-localVue.use(Vuex);
+jest.mock('~/api');
+
+Vue.use(Vuex);
describe('Deploy freeze modal', () => {
let wrapper;
@@ -23,18 +26,19 @@ describe('Deploy freeze modal', () => {
stubs: {
GlModal,
},
- localVue,
store,
});
});
- const findModal = () => wrapper.find(GlModal);
- const addDeployFreezeButton = () => findModal().findAll(GlButton).at(1);
+ const findModal = () => wrapper.findComponent(GlModal);
+ const submitDeployFreezeButton = () => findModal().findAllComponents(GlButton).at(1);
- const setInput = (freezeStartCron, freezeEndCron, selectedTimezone) => {
+ const setInput = (freezeStartCron, freezeEndCron, selectedTimezone, id = '') => {
store.state.freezeStartCron = freezeStartCron;
store.state.freezeEndCron = freezeEndCron;
store.state.selectedTimezone = selectedTimezone;
+ store.state.selectedTimezoneIdentifier = selectedTimezone;
+ store.state.selectedId = id;
wrapper.find('#deploy-freeze-start').trigger('input');
wrapper.find('#deploy-freeze-end').trigger('input');
@@ -48,18 +52,36 @@ describe('Deploy freeze modal', () => {
describe('Basic interactions', () => {
it('button is disabled when freeze period is invalid', () => {
- expect(addDeployFreezeButton().attributes('disabled')).toBeTruthy();
+ expect(submitDeployFreezeButton().attributes('disabled')).toBeTruthy();
});
});
describe('Adding a new deploy freeze', () => {
+ const { freeze_start, freeze_end, cron_timezone } = freezePeriodsFixture[0];
+
beforeEach(() => {
- const { freeze_start, freeze_end, cron_timezone } = freezePeriodsFixture[0];
setInput(freeze_start, freeze_end, cron_timezone);
});
it('button is enabled when valid freeze period settings are present', () => {
- expect(addDeployFreezeButton().attributes('disabled')).toBeUndefined();
+ expect(submitDeployFreezeButton().attributes('disabled')).toBeUndefined();
+ });
+
+ it('should display Add deploy freeze', () => {
+ expect(findModal().props('title')).toBe('Add deploy freeze');
+ expect(submitDeployFreezeButton().text()).toBe('Add deploy freeze');
+ });
+
+ it('should call the add deploy freze API', () => {
+ Api.createFreezePeriod.mockResolvedValue();
+ findModal().vm.$emit('primary');
+
+ expect(Api.createFreezePeriod).toHaveBeenCalledTimes(1);
+ expect(Api.createFreezePeriod).toHaveBeenCalledWith(store.state.projectId, {
+ freeze_start,
+ freeze_end,
+ cron_timezone,
+ });
});
});
@@ -70,7 +92,7 @@ describe('Deploy freeze modal', () => {
});
it('disables the add deploy freeze button', () => {
- expect(addDeployFreezeButton().attributes('disabled')).toBeTruthy();
+ expect(submitDeployFreezeButton().attributes('disabled')).toBeTruthy();
});
});
@@ -81,7 +103,32 @@ describe('Deploy freeze modal', () => {
});
it('does not disable the submit button', () => {
- expect(addDeployFreezeButton().attributes('disabled')).toBeFalsy();
+ expect(submitDeployFreezeButton().attributes('disabled')).toBeFalsy();
+ });
+ });
+ });
+
+ describe('Editing an existing deploy freeze', () => {
+ const { freeze_start, freeze_end, cron_timezone, id } = freezePeriodsFixture[0];
+ beforeEach(() => {
+ setInput(freeze_start, freeze_end, cron_timezone, id);
+ });
+
+ it('should display Edit deploy freeze', () => {
+ expect(findModal().props('title')).toBe('Edit deploy freeze');
+ expect(submitDeployFreezeButton().text()).toBe('Save deploy freeze');
+ });
+
+ it('should call the update deploy freze API', () => {
+ Api.updateFreezePeriod.mockResolvedValue();
+ findModal().vm.$emit('primary');
+
+ expect(Api.updateFreezePeriod).toHaveBeenCalledTimes(1);
+ expect(Api.updateFreezePeriod).toHaveBeenCalledWith(store.state.projectId, {
+ id,
+ freeze_start,
+ freeze_end,
+ cron_timezone,
});
});
});