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

states_table_spec.js « components « terraform « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12a44452717951c3c1a8f9bd6f01d71d99d39355 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import { GlBadge, GlLoadingIcon, GlTooltip } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import { useFakeDate } from 'helpers/fake_date';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import StatesTable from '~/terraform/components/states_table.vue';
import StateActions from '~/terraform/components/states_table_actions.vue';

describe('StatesTable', () => {
  let wrapper;
  useFakeDate([2020, 10, 15]);

  const defaultProps = {
    states: [
      {
        _showDetails: true,
        errorMessages: ['State 1 has errored'],
        name: 'state-1',
        loadingLock: false,
        loadingRemove: false,
        lockedAt: '2020-10-13T00:00:00Z',
        lockedByUser: {
          name: 'user-1',
        },
        updatedAt: '2020-10-13T00:00:00Z',
        latestVersion: null,
      },
      {
        _showDetails: false,
        errorMessages: [],
        name: 'state-2',
        loadingLock: true,
        loadingRemove: false,
        lockedAt: null,
        lockedByUser: null,
        updatedAt: '2020-10-10T00:00:00Z',
        latestVersion: null,
      },
      {
        _showDetails: false,
        errorMessages: [],
        name: 'state-3',
        loadingLock: true,
        loadingRemove: false,
        lockedAt: '2020-10-10T00:00:00Z',
        lockedByUser: {
          name: 'user-2',
        },
        updatedAt: '2020-10-10T00:00:00Z',
        latestVersion: {
          updatedAt: '2020-10-11T00:00:00Z',
          createdByUser: {
            name: 'user-3',
          },
          job: {
            detailedStatus: {
              detailsPath: '/job-path-3',
              group: 'failed',
              icon: 'status_failed',
              label: 'failed',
              text: 'failed',
            },
            pipeline: {
              id: 'gid://gitlab/Ci::Pipeline/3',
              path: '/pipeline-path-3',
            },
          },
        },
      },
      {
        _showDetails: true,
        errorMessages: ['State 4 has errored'],
        name: 'state-4',
        loadingLock: false,
        loadingRemove: false,
        lockedAt: '2020-10-10T00:00:00Z',
        lockedByUser: null,
        updatedAt: '2020-10-10T00:00:00Z',
        latestVersion: {
          updatedAt: '2020-10-09T00:00:00Z',
          createdByUser: null,
          job: {
            detailedStatus: {
              detailsPath: '/job-path-4',
              group: 'passed',
              icon: 'status_success',
              label: 'passed',
              text: 'passed',
            },
            pipeline: {
              id: 'gid://gitlab/Ci::Pipeline/4',
              path: '/pipeline-path-4',
            },
          },
        },
      },
      {
        _showDetails: false,
        errorMessages: [],
        name: 'state-5',
        loadingLock: false,
        loadingRemove: true,
        lockedAt: null,
        lockedByUser: null,
        updatedAt: '2020-10-10T00:00:00Z',
        latestVersion: null,
      },
      {
        _showDetails: false,
        errorMessages: [],
        name: 'state-6',
        loadingLock: false,
        loadingRemove: false,
        lockedAt: null,
        lockedByUser: null,
        updatedAt: '2020-10-10T00:00:00Z',
        deletedAt: '2022-02-02T00:00:00Z',
        latestVersion: null,
      },
    ],
  };

  const createComponent = async (propsData = defaultProps) => {
    wrapper = extendedWrapper(
      mount(StatesTable, {
        propsData,
        provide: { projectPath: 'path/to/project' },
        directives: {
          GlTooltip: createMockDirective(),
        },
      }),
    );
    await nextTick();
  };

  const findActions = () => wrapper.findAllComponents(StateActions);

  beforeEach(() => {
    return createComponent();
  });

  afterEach(() => {
    wrapper.destroy();
    wrapper = null;
  });

  it.each`
    name         | toolTipText                            | hasBadge | loading  | lineNumber
    ${'state-1'} | ${'Locked by user-1 2 days ago'}       | ${true}  | ${false} | ${0}
    ${'state-2'} | ${'Locking state'}                     | ${false} | ${true}  | ${1}
    ${'state-3'} | ${'Unlocking state'}                   | ${false} | ${true}  | ${2}
    ${'state-4'} | ${'Locked by Unknown User 5 days ago'} | ${true}  | ${false} | ${3}
    ${'state-5'} | ${'Removing'}                          | ${false} | ${true}  | ${4}
    ${'state-6'} | ${'Deletion in progress'}              | ${true}  | ${false} | ${5}
  `(
    'displays the name and locked information "$name" for line "$lineNumber"',
    ({ name, toolTipText, hasBadge, loading, lineNumber }) => {
      const states = wrapper.findAll('[data-testid="terraform-states-table-name"]');
      const state = states.at(lineNumber);

      expect(state.text()).toContain(name);
      expect(state.find(GlBadge).exists()).toBe(hasBadge);
      expect(state.find(GlLoadingIcon).exists()).toBe(loading);

      if (hasBadge) {
        const badge = wrapper.findByTestId(`state-badge-${name}`);

        expect(getBinding(badge.element, 'gl-tooltip')).toBeDefined();
        expect(badge.attributes('title')).toMatchInterpolatedText(toolTipText);
      }
    },
  );

  it.each`
    updateTime                     | lineNumber
    ${'updated 2 days ago'}        | ${0}
    ${'updated 5 days ago'}        | ${1}
    ${'user-3 updated 4 days ago'} | ${2}
    ${'updated 6 days ago'}        | ${3}
  `('displays the time "$updateTime" for line "$lineNumber"', ({ updateTime, lineNumber }) => {
    const states = wrapper.findAll('[data-testid="terraform-states-table-updated"]');

    const state = states.at(lineNumber);

    expect(state.text()).toMatchInterpolatedText(updateTime);
  });

  it.each`
    pipelineText              | toolTipAdded | lineNumber
    ${''}                     | ${false}     | ${0}
    ${''}                     | ${false}     | ${1}
    ${'#3 failed Job status'} | ${true}      | ${2}
    ${'#4 passed Job status'} | ${true}      | ${3}
  `(
    'displays the pipeline information for line "$lineNumber"',
    ({ pipelineText, toolTipAdded, lineNumber }) => {
      const states = wrapper.findAll('[data-testid="terraform-states-table-pipeline"]');
      const state = states.at(lineNumber);

      expect(state.find(GlTooltip).exists()).toBe(toolTipAdded);
      expect(state.text()).toMatchInterpolatedText(pipelineText);
    },
  );

  it('displays no actions dropdown', () => {
    expect(findActions().length).toEqual(0);
  });

  it.each`
    errorMessage                               | lineNumber
    ${defaultProps.states[0].errorMessages[0]} | ${0}
    ${defaultProps.states[3].errorMessages[0]} | ${1}
  `('displays table error message "$errorMessage"', ({ errorMessage, lineNumber }) => {
    const states = wrapper.findAll('[data-testid="terraform-states-table-error"]');
    const state = states.at(lineNumber);

    expect(state.text()).toBe(errorMessage);
  });

  describe('when user is a terraform administrator', () => {
    beforeEach(() => {
      return createComponent({
        terraformAdmin: true,
        ...defaultProps,
      });
    });

    it('displays an actions dropdown for each state', () => {
      expect(findActions().length).toEqual(defaultProps.states.length);
    });
  });
});