Commit e1daa10f authored by Ezekiel Kigbo's avatar Ezekiel Kigbo Committed by David O'Regan

Moves timezone fixture and helpers to new file

Moves the fixture generated data for the deploy
freeze specs to a shared helper for reuse.
parent fa883dba
......@@ -4,6 +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 { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -11,8 +12,6 @@ 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({
......
......@@ -4,6 +4,7 @@ import DeployFreezeSettings from '~/deploy_freeze/components/deploy_freeze_setti
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 { timezoneDataFixture } from '../helpers';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -11,7 +12,6 @@ localVue.use(Vuex);
describe('Deploy freeze settings', () => {
let wrapper;
let store;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => {
store = createStore({
......
......@@ -2,6 +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 { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -9,7 +10,6 @@ localVue.use(Vuex);
describe('Deploy freeze table', () => {
let wrapper;
let store;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
const createComponent = () => {
store = createStore({
......@@ -50,7 +50,6 @@ describe('Deploy freeze table', () => {
});
it('displays data', () => {
const freezePeriodsFixture = getJSONFixture('/api/freeze-periods/freeze_periods.json');
store.state.freezePeriods = freezePeriodsFixture;
return wrapper.vm.$nextTick(() => {
......
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlDropdownItem, GlDropdown } from '@gitlab/ui';
import { secondsToHours } from '~/lib/utils/datetime_utility';
import TimezoneDropdown from '~/vue_shared/components/timezone_dropdown.vue';
import createStore from '~/deploy_freeze/store';
import { findTzByName, formatTz, timezoneDataFixture } from '../helpers';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -11,12 +11,6 @@ localVue.use(Vuex);
describe('Deploy freeze timezone dropdown', () => {
let wrapper;
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) => {
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';
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 { freezePeriodsFixture, timezoneDataFixture } from '../helpers';
jest.mock('~/api.js');
jest.mock('~/flash.js');
......@@ -13,8 +14,6 @@ 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);
......
......@@ -2,10 +2,10 @@ import state from '~/deploy_freeze/store/state';
import mutations from '~/deploy_freeze/store/mutations';
import * as types from '~/deploy_freeze/store/mutation_types';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { findTzByName, formatTz, freezePeriodsFixture, timezoneDataFixture } from '../helpers';
describe('Deploy freeze mutations', () => {
let stateCopy;
const timezoneDataFixture = getJSONFixture('/api/freeze-periods/timezone_data.json');
beforeEach(() => {
stateCopy = state({
......@@ -28,7 +28,6 @@ describe('Deploy freeze mutations', () => {
describe('RECEIVE_FREEZE_PERIODS_SUCCESS', () => {
it('should set freeze periods and format timezones from identifiers to names', () => {
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);
......@@ -43,9 +42,10 @@ describe('Deploy freeze mutations', () => {
describe('SET_SELECTED_TIMEZONE', () => {
it('should set the cron timezone', () => {
const selectedTz = findTzByName('Pacific Time (US & Canada)');
const timezone = {
formattedTimezone: '[UTC -7] Pacific Time (US & Canada)',
identifier: 'America/Los_Angeles',
formattedTimezone: formatTz(selectedTz),
identifier: selectedTz.identifier,
};
mutations[types.SET_SELECTED_TIMEZONE](stateCopy, timezone);
......
......@@ -17,6 +17,15 @@ RSpec.describe 'Freeze Periods (JavaScript fixtures)' do
remove_repository(project)
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
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