Commit 1a04efe4 authored by jakeburden's avatar jakeburden

Replace mock freeze period with fixture

parent cd6560ec
......@@ -4,7 +4,7 @@ import { GlButton, GlModal } from '@gitlab/ui';
import DeployFreezeModal from '~/deploy_freeze/components/deploy_freeze_modal.vue';
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
import createStore from '~/deploy_freeze/store';
import { mockDeployFreezePayload, mockTimezoneData } from '../mock_data';
import { mockTimezoneData } from '../mock_data';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -12,6 +12,7 @@ localVue.use(Vuex);
describe('Deploy freeze modal', () => {
let wrapper;
let store;
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze-periods.json');
beforeEach(() => {
store = createStore({
......@@ -57,7 +58,7 @@ describe('Deploy freeze modal', () => {
describe('Adding a new deploy freeze', () => {
beforeEach(() => {
const { freeze_start, freeze_end, cron_timezone } = mockDeployFreezePayload;
const { freeze_start, freeze_end, cron_timezone } = freezePeriodsFixture[0];
setInput(freeze_start, freeze_end, cron_timezone);
});
......@@ -79,7 +80,7 @@ describe('Deploy freeze modal', () => {
describe('when the cron state is valid', () => {
beforeEach(() => {
const { freeze_start, freeze_end, cron_timezone } = mockDeployFreezePayload;
const { freeze_start, freeze_end, cron_timezone } = freezePeriodsFixture[0];
setInput(freeze_start, freeze_end, cron_timezone);
});
......
......@@ -2,7 +2,7 @@ import Vuex from 'vuex';
import { createLocalVue, mount } from '@vue/test-utils';
import DeployFreezeTable from '~/deploy_freeze/components/deploy_freeze_table.vue';
import createStore from '~/deploy_freeze/store';
import { mockFreezePeriods, mockTimezoneData } from '../mock_data';
import { mockTimezoneData } from '../mock_data';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -50,11 +50,12 @@ describe('Deploy freeze table', () => {
});
it('displays data', () => {
store.state.freezePeriods = mockFreezePeriods;
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze-periods.json');
store.state.freezePeriods = freezePeriodsFixture;
return wrapper.vm.$nextTick(() => {
const tableRows = findDeployFreezeTable().findAll('tbody tr');
expect(tableRows.length).toBe(mockFreezePeriods.length);
expect(tableRows.length).toBe(freezePeriodsFixture.length);
expect(findEmptyFreezePeriods().exists()).toBe(false);
});
});
......
......@@ -6,7 +6,7 @@ import createFlash from '~/flash';
import getInitialState from '~/deploy_freeze/store/state';
import * as actions from '~/deploy_freeze/store/actions';
import * as types from '~/deploy_freeze/store/mutation_types';
import { mockTimezoneData, mockFreezePeriods } from '../mock_data';
import { mockTimezoneData } from '../mock_data';
jest.mock('~/api.js');
jest.mock('~/flash.js');
......@@ -14,6 +14,7 @@ jest.mock('~/flash.js');
describe('deploy freeze store actions', () => {
let mock;
let state;
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze-periods.json');
beforeEach(() => {
mock = new MockAdapter(axios);
......@@ -21,7 +22,7 @@ describe('deploy freeze store actions', () => {
projectId: '8',
timezoneData: mockTimezoneData,
});
Api.freezePeriods.mockResolvedValue({ data: mockFreezePeriods });
Api.freezePeriods.mockResolvedValue({ data: freezePeriodsFixture });
Api.createFreezePeriod.mockResolvedValue();
});
......@@ -97,7 +98,7 @@ describe('deploy freeze store actions', () => {
state,
[
{ type: types.REQUEST_FREEZE_PERIODS },
{ type: types.RECEIVE_FREEZE_PERIODS_SUCCESS, payload: mockFreezePeriods },
{ type: types.RECEIVE_FREEZE_PERIODS_SUCCESS, payload: freezePeriodsFixture },
],
[],
);
......
import state from '~/deploy_freeze/store/state';
import mutations from '~/deploy_freeze/store/mutations';
import * as types from '~/deploy_freeze/store/mutation_types';
import { mockFreezePeriods, mockTimezoneData } from '../mock_data';
import { mockTimezoneData } from '../mock_data';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
describe('Deploy freeze mutations', () => {
......@@ -27,10 +27,11 @@ describe('Deploy freeze mutations', () => {
describe('RECEIVE_FREEZE_PERIODS_SUCCESS', () => {
it('should set freeze periods and format timezones from identifiers to names', () => {
const timezoneNames = ['Eastern Time (US & Canada)', 'UTC', 'Berlin'];
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze-periods.json');
mutations[types.RECEIVE_FREEZE_PERIODS_SUCCESS](stateCopy, mockFreezePeriods);
mutations[types.RECEIVE_FREEZE_PERIODS_SUCCESS](stateCopy, freezePeriodsFixture);
const expectedFreezePeriods = mockFreezePeriods.map((freezePeriod, index) => ({
const expectedFreezePeriods = freezePeriodsFixture.map((freezePeriod, index) => ({
...convertObjectPropsToCamelCase(freezePeriod),
cronTimezone: timezoneNames[index],
}));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment