Commit 03ce0e54 authored by Nathan Friend's avatar Nathan Friend

Merge branch 'frontend-replace-deploy-freeze-mock_data-with-frontend-fixture' into 'master'

Replace deploy freeze mock_data usage with frontend fixture

See merge request gitlab-org/gitlab!38532
parents 10c47da3 42d8e421
......@@ -4,7 +4,6 @@ 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';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -12,11 +11,13 @@ localVue.use(Vuex);
describe('Deploy freeze modal', () => {
let wrapper;
let store;
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze_periods.json');
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => {
store = createStore({
projectId: '8',
timezoneData: mockTimezoneData,
timezoneData: timezoneDataFixture,
});
wrapper = shallowMount(DeployFreezeModal, {
attachToDocument: true,
......@@ -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);
});
......
......@@ -3,9 +3,7 @@ import { createLocalVue, shallowMount } from '@vue/test-utils';
import DeployFreezeSettings from '~/deploy_freeze/components/deploy_freeze_settings.vue';
import DeployFreezeTable from '~/deploy_freeze/components/deploy_freeze_table.vue';
import DeployFreezeModal from '~/deploy_freeze/components/deploy_freeze_modal.vue';
import createStore from '~/deploy_freeze/store';
import { mockTimezoneData } from '../mock_data';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -13,11 +11,12 @@ localVue.use(Vuex);
describe('Deploy freeze settings', () => {
let wrapper;
let store;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => {
store = createStore({
projectId: '8',
timezoneData: mockTimezoneData,
timezoneData: timezoneDataFixture,
});
jest.spyOn(store, 'dispatch').mockImplementation();
wrapper = shallowMount(DeployFreezeSettings, {
......
......@@ -2,7 +2,6 @@ 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';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -10,11 +9,12 @@ localVue.use(Vuex);
describe('Deploy freeze table', () => {
let wrapper;
let store;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
const createComponent = () => {
store = createStore({
projectId: '8',
timezoneData: mockTimezoneData,
timezoneData: timezoneDataFixture,
});
jest.spyOn(store, 'dispatch').mockImplementation();
wrapper = mount(DeployFreezeTable, {
......@@ -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);
});
});
......
......@@ -2,7 +2,6 @@ import Vuex from 'vuex';
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import createStore from '~/deploy_freeze/store';
import { mockTimezoneData } from '../mock_data';
import { GlDeprecatedDropdownItem, GlNewDropdown } from '@gitlab/ui';
......@@ -12,18 +11,19 @@ localVue.use(Vuex);
describe('Deploy freeze timezone dropdown', () => {
let wrapper;
let store;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
const createComponent = (searchTerm, selectedTimezone) => {
store = createStore({
projectId: '8',
timezoneData: mockTimezoneData,
timezoneData: timezoneDataFixture,
});
wrapper = shallowMount(TimezoneDropdown, {
store,
localVue,
propsData: {
value: selectedTimezone,
timezoneData: mockTimezoneData,
timezoneData: timezoneDataFixture,
},
});
......@@ -54,7 +54,7 @@ describe('Deploy freeze timezone dropdown', () => {
});
it('renders all timezones when search term is empty', () => {
expect(findAllDropdownItems()).toHaveLength(mockTimezoneData.length);
expect(findAllDropdownItems()).toHaveLength(timezoneDataFixture.length);
});
});
......
This diff is collapsed.
......@@ -6,7 +6,6 @@ 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';
jest.mock('~/api.js');
jest.mock('~/flash.js');
......@@ -14,14 +13,16 @@ jest.mock('~/flash.js');
describe('deploy freeze store actions', () => {
let mock;
let state;
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze_periods.json');
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => {
mock = new MockAdapter(axios);
state = getInitialState({
projectId: '8',
timezoneData: mockTimezoneData,
timezoneData: timezoneDataFixture,
});
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 { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
describe('Deploy freeze mutations', () => {
let stateCopy;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => {
stateCopy = state({
projectId: '8',
timezoneData: mockTimezoneData,
timezoneData: timezoneDataFixture,
});
});
......@@ -26,11 +27,12 @@ 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 timezoneNames = ['Berlin', 'UTC', 'Eastern Time (US & Canada)'];
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