Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deploy_freeze_alert_spec.js « environments « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b7202253e61df0a8abd73799767380ffdd1c1540 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { GlAlert, GlLink } from '@gitlab/ui';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import DeployFreezeAlert from '~/environments/components/deploy_freeze_alert.vue';
import deployFreezesQuery from '~/environments/graphql/queries/deploy_freezes.query.graphql';
import { formatDate } from '~/lib/utils/datetime/date_format_utility';

const ENVIRONMENT_NAME = 'staging';

Vue.use(VueApollo);
describe('~/environments/components/deploy_freeze_alert.vue', () => {
  let wrapper;

  const createWrapper = (deployFreezes = []) => {
    const mockApollo = createMockApollo([
      [
        deployFreezesQuery,
        jest.fn().mockResolvedValue({
          data: {
            project: {
              id: '1',
              __typename: 'Project',
              environment: {
                id: '1',
                __typename: 'Environment',
                deployFreezes,
              },
            },
          },
        }),
      ],
    ]);
    wrapper = mountExtended(DeployFreezeAlert, {
      apolloProvider: mockApollo,
      provide: {
        projectFullPath: 'gitlab-org/gitlab',
      },
      propsData: {
        name: ENVIRONMENT_NAME,
      },
    });
  };

  describe('with deploy freezes', () => {
    let deployFreezes;
    let alert;

    beforeEach(async () => {
      deployFreezes = [
        {
          __typename: 'CiFreezePeriod',
          startTime: new Date('2020-02-01'),
          endTime: new Date('2020-02-02'),
        },
        {
          __typename: 'CiFreezePeriod',
          startTime: new Date('2020-01-01'),
          endTime: new Date('2020-01-02'),
        },
      ];

      createWrapper(deployFreezes);

      await waitForPromises();

      alert = wrapper.findComponent(GlAlert);
    });

    it('shows an alert', () => {
      expect(alert.exists()).toBe(true);
    });

    it('shows the start time of the most recent freeze period', () => {
      expect(alert.text()).toContain(`from ${formatDate(deployFreezes[1].startTime)}`);
    });

    it('shows the end time of the most recent freeze period', () => {
      expect(alert.text()).toContain(`to ${formatDate(deployFreezes[1].endTime)}`);
    });

    it('shows a link to the docs', () => {
      const link = alert.findComponent(GlLink);
      expect(link.attributes('href')).toBe(
        '/help/user/project/releases/index#prevent-unintentional-releases-by-setting-a-deploy-freeze',
      );
      expect(link.text()).toBe('deploy freeze documentation');
    });
  });

  describe('without deploy freezes', () => {
    let deployFreezes;
    let alert;

    beforeEach(async () => {
      deployFreezes = [];

      createWrapper(deployFreezes);

      await waitForPromises();

      alert = wrapper.findComponent(GlAlert);
    });

    it('does not show an alert', () => {
      expect(alert.exists()).toBe(false);
    });
  });
});