2020-10-24 23:57:45 +05:30
|
|
|
import { GlButton, GlModal } from '@gitlab/ui';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Vue from 'vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Vuex from 'vuex';
|
2021-04-29 21:17:54 +05:30
|
|
|
import Api from '~/api';
|
2020-10-24 23:57:45 +05:30
|
|
|
import DeployFreezeModal from '~/deploy_freeze/components/deploy_freeze_modal.vue';
|
|
|
|
import createStore from '~/deploy_freeze/store';
|
2021-03-11 19:13:27 +05:30
|
|
|
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
jest.mock('~/api');
|
|
|
|
|
|
|
|
Vue.use(Vuex);
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
describe('Deploy freeze modal', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore({
|
|
|
|
projectId: '8',
|
|
|
|
timezoneData: timezoneDataFixture,
|
|
|
|
});
|
|
|
|
wrapper = shallowMount(DeployFreezeModal, {
|
2021-03-08 18:12:59 +05:30
|
|
|
attachTo: document.body,
|
2020-10-24 23:57:45 +05:30
|
|
|
stubs: {
|
|
|
|
GlModal,
|
|
|
|
},
|
|
|
|
store,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const findModal = () => wrapper.findComponent(GlModal);
|
|
|
|
const submitDeployFreezeButton = () => findModal().findAllComponents(GlButton).at(1);
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const setInput = (freezeStartCron, freezeEndCron, selectedTimezone, id = '') => {
|
2020-10-24 23:57:45 +05:30
|
|
|
store.state.freezeStartCron = freezeStartCron;
|
|
|
|
store.state.freezeEndCron = freezeEndCron;
|
|
|
|
store.state.selectedTimezone = selectedTimezone;
|
2021-04-29 21:17:54 +05:30
|
|
|
store.state.selectedTimezoneIdentifier = selectedTimezone;
|
|
|
|
store.state.selectedId = id;
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
wrapper.find('#deploy-freeze-start').trigger('input');
|
|
|
|
wrapper.find('#deploy-freeze-end').trigger('input');
|
|
|
|
wrapper.find(TimezoneDropdown).trigger('input');
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Basic interactions', () => {
|
|
|
|
it('button is disabled when freeze period is invalid', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(submitDeployFreezeButton().attributes('disabled')).toBeTruthy();
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Adding a new deploy freeze', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
const { freeze_start, freeze_end, cron_timezone } = freezePeriodsFixture[0];
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
setInput(freeze_start, freeze_end, cron_timezone);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('button is enabled when valid freeze period settings are present', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
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,
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Validations', () => {
|
|
|
|
describe('when the cron state is invalid', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setInput('invalid cron', 'invalid cron', 'invalid timezone');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disables the add deploy freeze button', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(submitDeployFreezeButton().attributes('disabled')).toBeTruthy();
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when the cron state is valid', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
const { freeze_start, freeze_end, cron_timezone } = freezePeriodsFixture[0];
|
|
|
|
setInput(freeze_start, freeze_end, cron_timezone);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not disable the submit button', () => {
|
2021-04-29 21:17:54 +05:30
|
|
|
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,
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|