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

tags_table_spec.js « details_page « components « explorer « registry « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a60a362dcfe860f74eebc82b0436b5683bd335fc (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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import { mount } from '@vue/test-utils';
import stubChildren from 'helpers/stub_children';
import component from '~/registry/explorer/components/details_page/tags_table.vue';
import { tagsListResponse } from '../../mock_data';

describe('tags_table', () => {
  let wrapper;
  const tags = [...tagsListResponse.data];

  const findMainCheckbox = () => wrapper.find('[data-testid="mainCheckbox"]');
  const findFirstRowItem = testid => wrapper.find(`[data-testid="${testid}"]`);
  const findBulkDeleteButton = () => wrapper.find('[data-testid="bulkDeleteButton"]');
  const findAllDeleteButtons = () => wrapper.findAll('[data-testid="singleDeleteButton"]');
  const findAllCheckboxes = () => wrapper.findAll('[data-testid="rowCheckbox"]');
  const findCheckedCheckboxes = () => findAllCheckboxes().filter(c => c.attributes('checked'));
  const findFirsTagColumn = () => wrapper.find('.js-tag-column');
  const findFirstTagNameText = () => wrapper.find('[data-testid="rowNameText"]');

  const findLoaderSlot = () => wrapper.find('[data-testid="loaderSlot"]');
  const findEmptySlot = () => wrapper.find('[data-testid="emptySlot"]');

  const mountComponent = (propsData = { tags, isDesktop: true }) => {
    wrapper = mount(component, {
      stubs: {
        ...stubChildren(component),
        GlTable: false,
      },
      propsData,
      slots: {
        loader: '<div data-testid="loaderSlot"></div>',
        empty: '<div data-testid="emptySlot"></div>',
      },
    });
  };

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

  it.each([
    'rowCheckbox',
    'rowName',
    'rowShortRevision',
    'rowSize',
    'rowTime',
    'singleDeleteButton',
  ])('%s exist in the table', element => {
    mountComponent();

    expect(findFirstRowItem(element).exists()).toBe(true);
  });

  describe('header checkbox', () => {
    it('exists', () => {
      mountComponent();
      expect(findMainCheckbox().exists()).toBe(true);
    });

    it('if selected selects all the rows', () => {
      mountComponent();
      findMainCheckbox().vm.$emit('change');
      return wrapper.vm.$nextTick().then(() => {
        expect(findMainCheckbox().attributes('checked')).toBeTruthy();
        expect(findCheckedCheckboxes()).toHaveLength(tags.length);
      });
    });

    it('if deselect deselects all the row', () => {
      mountComponent();
      findMainCheckbox().vm.$emit('change');
      return wrapper.vm
        .$nextTick()
        .then(() => {
          expect(findMainCheckbox().attributes('checked')).toBeTruthy();
          findMainCheckbox().vm.$emit('change');
          return wrapper.vm.$nextTick();
        })
        .then(() => {
          expect(findMainCheckbox().attributes('checked')).toBe(undefined);
          expect(findCheckedCheckboxes()).toHaveLength(0);
        });
    });
  });

  describe('row checkbox', () => {
    beforeEach(() => {
      mountComponent();
    });

    it('selecting and deselecting the checkbox works as intended', () => {
      findFirstRowItem('rowCheckbox').vm.$emit('change');
      return wrapper.vm
        .$nextTick()
        .then(() => {
          expect(wrapper.vm.selectedItems).toEqual([tags[0].name]);
          expect(findFirstRowItem('rowCheckbox').attributes('checked')).toBeTruthy();
          findFirstRowItem('rowCheckbox').vm.$emit('change');
          return wrapper.vm.$nextTick();
        })
        .then(() => {
          expect(wrapper.vm.selectedItems.length).toBe(0);
          expect(findFirstRowItem('rowCheckbox').attributes('checked')).toBe(undefined);
        });
    });
  });

  describe('header delete button', () => {
    beforeEach(() => {
      mountComponent();
    });

    it('exists', () => {
      expect(findBulkDeleteButton().exists()).toBe(true);
    });

    it('is disabled if no item is selected', () => {
      expect(findBulkDeleteButton().attributes('disabled')).toBe('true');
    });

    it('is enabled if at least one item is selected', () => {
      expect(findBulkDeleteButton().attributes('disabled')).toBe('true');
      findFirstRowItem('rowCheckbox').vm.$emit('change');
      return wrapper.vm.$nextTick().then(() => {
        expect(findBulkDeleteButton().attributes('disabled')).toBeFalsy();
      });
    });

    describe('on click', () => {
      it('when one item is selected', () => {
        findFirstRowItem('rowCheckbox').vm.$emit('change');
        findBulkDeleteButton().vm.$emit('click');
        expect(wrapper.emitted('delete')).toEqual([[['centos6']]]);
      });

      it('when multiple items are selected', () => {
        findMainCheckbox().vm.$emit('change');
        findBulkDeleteButton().vm.$emit('click');

        expect(wrapper.emitted('delete')).toEqual([[tags.map(t => t.name)]]);
      });
    });
  });

  describe('row delete button', () => {
    beforeEach(() => {
      mountComponent();
    });

    it('exists', () => {
      expect(
        findAllDeleteButtons()
          .at(0)
          .exists(),
      ).toBe(true);
    });

    it('is disabled if the item has no destroy_path', () => {
      expect(
        findAllDeleteButtons()
          .at(1)
          .attributes('disabled'),
      ).toBe('true');
    });

    it('on click', () => {
      findAllDeleteButtons()
        .at(0)
        .vm.$emit('click');

      expect(wrapper.emitted('delete')).toEqual([[['centos6']]]);
    });
  });

  describe('name cell', () => {
    it('tag column has a tooltip with the tag name', () => {
      mountComponent();
      expect(findFirstTagNameText().attributes('title')).toBe(tagsListResponse.data[0].name);
    });

    describe('on desktop viewport', () => {
      beforeEach(() => {
        mountComponent();
      });

      it('table header has class w-25', () => {
        expect(findFirsTagColumn().classes()).toContain('w-25');
      });

      it('tag column has the mw-m class', () => {
        expect(findFirstRowItem('rowName').classes()).toContain('mw-m');
      });
    });

    describe('on mobile viewport', () => {
      beforeEach(() => {
        mountComponent({ tags, isDesktop: false });
      });

      it('table header does not have class w-25', () => {
        expect(findFirsTagColumn().classes()).not.toContain('w-25');
      });

      it('tag column has the gl-justify-content-end class', () => {
        expect(findFirstRowItem('rowName').classes()).toContain('gl-justify-content-end');
      });
    });
  });

  describe('last updated cell', () => {
    let timeCell;

    beforeEach(() => {
      mountComponent();
      timeCell = findFirstRowItem('rowTime');
    });

    it('displays the time in string format', () => {
      expect(timeCell.text()).toBe('2 years ago');
    });

    it('has a tooltip timestamp', () => {
      expect(timeCell.attributes('title')).toBe('Sep 19, 2017 1:45pm GMT+0000');
    });
  });

  describe('empty state slot', () => {
    describe('when the table is empty', () => {
      beforeEach(() => {
        mountComponent({ tags: [], isDesktop: true });
      });

      it('does not show table rows', () => {
        expect(findFirstTagNameText().exists()).toBe(false);
      });

      it('has the empty state slot', () => {
        expect(findEmptySlot().exists()).toBe(true);
      });
    });

    describe('when the table is not empty', () => {
      beforeEach(() => {
        mountComponent({ tags, isDesktop: true });
      });

      it('does show table rows', () => {
        expect(findFirstTagNameText().exists()).toBe(true);
      });

      it('does not show the empty state', () => {
        expect(findEmptySlot().exists()).toBe(false);
      });
    });
  });

  describe('loader slot', () => {
    describe('when the data is loading', () => {
      beforeEach(() => {
        mountComponent({ isLoading: true, tags });
      });

      it('show the loader', () => {
        expect(findLoaderSlot().exists()).toBe(true);
      });

      it('does not show the table rows', () => {
        expect(findFirstTagNameText().exists()).toBe(false);
      });
    });

    describe('when the data is not loading', () => {
      beforeEach(() => {
        mountComponent({ isLoading: false, tags });
      });

      it('does not show the loader', () => {
        expect(findLoaderSlot().exists()).toBe(false);
      });

      it('shows the table rows', () => {
        expect(findFirstTagNameText().exists()).toBe(true);
      });
    });
  });
});