summaryrefslogtreecommitdiff
path: root/spec/frontend/deploy_freeze/store/mutations_spec.js
blob: 984105d66554cc27d406748e2e951ec4b20f7091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import * as types from '~/deploy_freeze/store/mutation_types';
import mutations from '~/deploy_freeze/store/mutations';
import state from '~/deploy_freeze/store/state';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { formatTimezone } from '~/lib/utils/datetime_utility';
import { freezePeriodsFixture } from '../helpers';
import {
  timezoneDataFixture,
  findTzByName,
} from '../../vue_shared/components/timezone_dropdown/helpers';

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', () => {
      const timezoneNames = {
        'Europe/Berlin': '[UTC + 2] Berlin',
        'Etc/UTC': '[UTC 0] UTC',
        'America/New_York': '[UTC - 4] Eastern Time (US & Canada)',
      };

      mutations[types.RECEIVE_FREEZE_PERIODS_SUCCESS](stateCopy, freezePeriodsFixture);

      const expectedFreezePeriods = freezePeriodsFixture.map((freezePeriod) => ({
        ...convertObjectPropsToCamelCase(freezePeriod),
        cronTimezone: {
          formattedTimezone: timezoneNames[freezePeriod.cron_timezone],
          identifier: freezePeriod.cron_timezone,
        },
      }));

      expect(stateCopy.freezePeriods).toMatchObject(expectedFreezePeriods);
    });
  });

  describe('SET_SELECTED_TIMEZONE', () => {
    it('should set the cron timezone', () => {
      const selectedTz = findTzByName('Pacific Time (US & Canada)');
      const timezone = {
        formattedTimezone: formatTimezone(selectedTz),
        identifier: selectedTz.identifier,
      };
      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 *');
    });
  });

  describe('SET_FREEZE_END_CRON', () => {
    it('should set freezeEndCron', () => {
      mutations[types.SET_FREEZE_END_CRON](stateCopy, '5 0 * 8 *');

      expect(stateCopy.freezeEndCron).toBe('5 0 * 8 *');
    });
  });

  describe('SET_SELECTED_ID', () => {
    it('should set selectedId', () => {
      mutations[types.SET_SELECTED_ID](stateCopy, 5);

      expect(stateCopy.selectedId).toBe(5);
    });
  });
});