debian-mirror-gitlab/spec/frontend/deploy_freeze/store/mutations_spec.js

88 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import * as types from '~/deploy_freeze/store/mutation_types';
2021-03-11 19:13:27 +05:30
import mutations from '~/deploy_freeze/store/mutations';
import state from '~/deploy_freeze/store/state';
2020-10-24 23:57:45 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2021-01-29 00:20:46 +05:30
import { findTzByName, formatTz, freezePeriodsFixture, timezoneDataFixture } from '../helpers';
2020-10-24 23:57:45 +05:30
describe('Deploy freeze mutations', () => {
let stateCopy;
beforeEach(() => {
stateCopy = state({
projectId: '8',
timezoneData: timezoneDataFixture,
});
});
describe('RESET_MODAL', () => {
it('should reset modal state', () => {
mutations[types.RESET_MODAL](stateCopy);
expect(stateCopy.freezeStartCron).toBe('');
expect(stateCopy.freezeEndCron).toBe('');
expect(stateCopy.selectedTimezone).toBe('');
expect(stateCopy.selectedTimezoneIdentifier).toBe('');
});
});
describe('RECEIVE_FREEZE_PERIODS_SUCCESS', () => {
it('should set freeze periods and format timezones from identifiers to names', () => {
2021-06-08 01:23:25 +05:30
const timezoneNames = {
'Europe/Berlin': 'Berlin',
'Etc/UTC': 'UTC',
'America/New_York': 'Eastern Time (US & Canada)',
};
2020-10-24 23:57:45 +05:30
mutations[types.RECEIVE_FREEZE_PERIODS_SUCCESS](stateCopy, freezePeriodsFixture);
2021-06-08 01:23:25 +05:30
const expectedFreezePeriods = freezePeriodsFixture.map((freezePeriod) => ({
2020-10-24 23:57:45 +05:30
...convertObjectPropsToCamelCase(freezePeriod),
2021-04-29 21:17:54 +05:30
cronTimezone: {
2021-06-08 01:23:25 +05:30
formattedTimezone: timezoneNames[freezePeriod.cron_timezone],
identifier: freezePeriod.cron_timezone,
2021-04-29 21:17:54 +05:30
},
2020-10-24 23:57:45 +05:30
}));
expect(stateCopy.freezePeriods).toMatchObject(expectedFreezePeriods);
});
});
describe('SET_SELECTED_TIMEZONE', () => {
it('should set the cron timezone', () => {
2021-01-29 00:20:46 +05:30
const selectedTz = findTzByName('Pacific Time (US & Canada)');
2020-10-24 23:57:45 +05:30
const timezone = {
2021-01-29 00:20:46 +05:30
formattedTimezone: formatTz(selectedTz),
identifier: selectedTz.identifier,
2020-10-24 23:57:45 +05:30
};
mutations[types.SET_SELECTED_TIMEZONE](stateCopy, timezone);
expect(stateCopy.selectedTimezone).toEqual(timezone.formattedTimezone);
expect(stateCopy.selectedTimezoneIdentifier).toEqual(timezone.identifier);
});
});
describe('SET_FREEZE_START_CRON', () => {
it('should set freezeStartCron', () => {
mutations[types.SET_FREEZE_START_CRON](stateCopy, '5 0 * 8 *');
expect(stateCopy.freezeStartCron).toBe('5 0 * 8 *');
});
});
2021-04-29 21:17:54 +05:30
describe('SET_FREEZE_END_CRON', () => {
2020-10-24 23:57:45 +05:30
it('should set freezeEndCron', () => {
mutations[types.SET_FREEZE_END_CRON](stateCopy, '5 0 * 8 *');
expect(stateCopy.freezeEndCron).toBe('5 0 * 8 *');
});
});
2021-04-29 21:17:54 +05:30
describe('SET_SELECTED_ID', () => {
it('should set selectedId', () => {
mutations[types.SET_SELECTED_ID](stateCopy, 5);
expect(stateCopy.selectedId).toBe(5);
});
});
2020-10-24 23:57:45 +05:30
});