Commit 7e20027b authored by David O'Regan's avatar David O'Regan

Merge branch 'ek-mock-deploy-freeze-time' into 'master'

Mock deploy freeze time for frontend fixture

See merge request gitlab-org/gitlab!46942
parents 57d49ae0 e1daa10f
...@@ -4,6 +4,7 @@ import { GlButton, GlModal } from '@gitlab/ui'; ...@@ -4,6 +4,7 @@ import { GlButton, GlModal } from '@gitlab/ui';
import DeployFreezeModal from '~/deploy_freeze/components/deploy_freeze_modal.vue'; import DeployFreezeModal from '~/deploy_freeze/components/deploy_freeze_modal.vue';
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue'; import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
import createStore from '~/deploy_freeze/store'; import createStore from '~/deploy_freeze/store';
import { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -11,8 +12,6 @@ localVue.use(Vuex); ...@@ -11,8 +12,6 @@ localVue.use(Vuex);
describe('Deploy freeze modal', () => { describe('Deploy freeze modal', () => {
let wrapper; let wrapper;
let store; let store;
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze_periods.json');
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => { beforeEach(() => {
store = createStore({ store = createStore({
......
...@@ -4,6 +4,7 @@ import DeployFreezeSettings from '~/deploy_freeze/components/deploy_freeze_setti ...@@ -4,6 +4,7 @@ import DeployFreezeSettings from '~/deploy_freeze/components/deploy_freeze_setti
import DeployFreezeTable from '~/deploy_freeze/components/deploy_freeze_table.vue'; import DeployFreezeTable from '~/deploy_freeze/components/deploy_freeze_table.vue';
import DeployFreezeModal from '~/deploy_freeze/components/deploy_freeze_modal.vue'; import DeployFreezeModal from '~/deploy_freeze/components/deploy_freeze_modal.vue';
import createStore from '~/deploy_freeze/store'; import createStore from '~/deploy_freeze/store';
import { timezoneDataFixture } from '../helpers';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -11,7 +12,6 @@ localVue.use(Vuex); ...@@ -11,7 +12,6 @@ localVue.use(Vuex);
describe('Deploy freeze settings', () => { describe('Deploy freeze settings', () => {
let wrapper; let wrapper;
let store; let store;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => { beforeEach(() => {
store = createStore({ store = createStore({
......
...@@ -2,6 +2,7 @@ import Vuex from 'vuex'; ...@@ -2,6 +2,7 @@ import Vuex from 'vuex';
import { createLocalVue, mount } from '@vue/test-utils'; import { createLocalVue, mount } from '@vue/test-utils';
import DeployFreezeTable from '~/deploy_freeze/components/deploy_freeze_table.vue'; import DeployFreezeTable from '~/deploy_freeze/components/deploy_freeze_table.vue';
import createStore from '~/deploy_freeze/store'; import createStore from '~/deploy_freeze/store';
import { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -9,7 +10,6 @@ localVue.use(Vuex); ...@@ -9,7 +10,6 @@ localVue.use(Vuex);
describe('Deploy freeze table', () => { describe('Deploy freeze table', () => {
let wrapper; let wrapper;
let store; let store;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
const createComponent = () => { const createComponent = () => {
store = createStore({ store = createStore({
...@@ -50,7 +50,6 @@ describe('Deploy freeze table', () => { ...@@ -50,7 +50,6 @@ describe('Deploy freeze table', () => {
}); });
it('displays data', () => { it('displays data', () => {
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze_periods.json');
store.state.freezePeriods = freezePeriodsFixture; store.state.freezePeriods = freezePeriodsFixture;
return wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
......
import Vuex from 'vuex'; import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlDropdownItem, GlDropdown } from '@gitlab/ui'; import { GlDropdownItem, GlDropdown } from '@gitlab/ui';
import { secondsToHours } from '~/lib/utils/datetime_utility';
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue'; import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
import createStore from '~/deploy_freeze/store'; import createStore from '~/deploy_freeze/store';
import { findTzByName, formatTz, timezoneDataFixture } from '../helpers';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -11,12 +11,6 @@ localVue.use(Vuex); ...@@ -11,12 +11,6 @@ localVue.use(Vuex);
describe('Deploy freeze timezone dropdown', () => { describe('Deploy freeze timezone dropdown', () => {
let wrapper; let wrapper;
let store; let store;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
const findTzByName = (identifier = '') =>
timezoneDataFixture.find(({ name }) => name.toLowerCase() === identifier.toLowerCase());
const formatTz = ({ offset, name }) => `[UTC ${secondsToHours(offset)}] ${name}`;
const createComponent = (searchTerm, selectedTimezone) => { const createComponent = (searchTerm, selectedTimezone) => {
store = createStore({ store = createStore({
......
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 findTzByName = (identifier = '') =>
timezoneDataFixture.find(({ name }) => name.toLowerCase() === identifier.toLowerCase());
export const formatTz = ({ offset, name }) => `[UTC ${secondsToHours(offset)}] ${name}`;
...@@ -6,6 +6,7 @@ import { deprecatedCreateFlash as createFlash } from '~/flash'; ...@@ -6,6 +6,7 @@ import { deprecatedCreateFlash as createFlash } from '~/flash';
import getInitialState from '~/deploy_freeze/store/state'; import getInitialState from '~/deploy_freeze/store/state';
import * as actions from '~/deploy_freeze/store/actions'; import * as actions from '~/deploy_freeze/store/actions';
import * as types from '~/deploy_freeze/store/mutation_types'; import * as types from '~/deploy_freeze/store/mutation_types';
import { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
jest.mock('~/api.js'); jest.mock('~/api.js');
jest.mock('~/flash.js'); jest.mock('~/flash.js');
...@@ -13,8 +14,6 @@ jest.mock('~/flash.js'); ...@@ -13,8 +14,6 @@ jest.mock('~/flash.js');
describe('deploy freeze store actions', () => { describe('deploy freeze store actions', () => {
let mock; let mock;
let state; let state;
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze_periods.json');
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
......
...@@ -2,10 +2,10 @@ import state from '~/deploy_freeze/store/state'; ...@@ -2,10 +2,10 @@ import state from '~/deploy_freeze/store/state';
import mutations from '~/deploy_freeze/store/mutations'; import mutations from '~/deploy_freeze/store/mutations';
import * as types from '~/deploy_freeze/store/mutation_types'; import * as types from '~/deploy_freeze/store/mutation_types';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { findTzByName, formatTz, freezePeriodsFixture, timezoneDataFixture } from '../helpers';
describe('Deploy freeze mutations', () => { describe('Deploy freeze mutations', () => {
let stateCopy; let stateCopy;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => { beforeEach(() => {
stateCopy = state({ stateCopy = state({
...@@ -28,7 +28,6 @@ describe('Deploy freeze mutations', () => { ...@@ -28,7 +28,6 @@ describe('Deploy freeze mutations', () => {
describe('RECEIVE_FREEZE_PERIODS_SUCCESS', () => { describe('RECEIVE_FREEZE_PERIODS_SUCCESS', () => {
it('should set freeze periods and format timezones from identifiers to names', () => { it('should set freeze periods and format timezones from identifiers to names', () => {
const timezoneNames = ['Berlin', 'UTC', 'Eastern Time (US & Canada)']; const timezoneNames = ['Berlin', 'UTC', 'Eastern Time (US & Canada)'];
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze_periods.json');
mutations[types.RECEIVE_FREEZE_PERIODS_SUCCESS](stateCopy, freezePeriodsFixture); mutations[types.RECEIVE_FREEZE_PERIODS_SUCCESS](stateCopy, freezePeriodsFixture);
...@@ -43,9 +42,10 @@ describe('Deploy freeze mutations', () => { ...@@ -43,9 +42,10 @@ describe('Deploy freeze mutations', () => {
describe('SET_SELECTED_TIMEZONE', () => { describe('SET_SELECTED_TIMEZONE', () => {
it('should set the cron timezone', () => { it('should set the cron timezone', () => {
const selectedTz = findTzByName('Pacific Time (US & Canada)');
const timezone = { const timezone = {
formattedTimezone: '[UTC -7] Pacific Time (US & Canada)', formattedTimezone: formatTz(selectedTz),
identifier: 'America/Los_Angeles', identifier: selectedTz.identifier,
}; };
mutations[types.SET_SELECTED_TIMEZONE](stateCopy, timezone); mutations[types.SET_SELECTED_TIMEZONE](stateCopy, timezone);
......
...@@ -17,6 +17,15 @@ RSpec.describe 'Freeze Periods (JavaScript fixtures)' do ...@@ -17,6 +17,15 @@ RSpec.describe 'Freeze Periods (JavaScript fixtures)' do
remove_repository(project) remove_repository(project)
end end
around do |example|
freeze_time do
# Mock time to sept 19 (intl. talk like a pirate day)
Timecop.travel(2020, 9, 19)
example.run
end
end
describe API::FreezePeriods, '(JavaScript fixtures)', type: :request do describe API::FreezePeriods, '(JavaScript fixtures)', type: :request do
include ApiHelpers include ApiHelpers
......
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