summaryrefslogtreecommitdiff
path: root/spec/frontend/registry/explorer/components/list_page/image_list_spec.js
blob: 03ba6ad7f80154e7a3658a738a88fd23f80c1f29 (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
import { shallowMount } from '@vue/test-utils';
import { GlPagination } from '@gitlab/ui';
import Component from '~/registry/explorer/components/list_page/image_list.vue';
import ImageListRow from '~/registry/explorer/components/list_page/image_list_row.vue';

import { imagesListResponse, imagePagination } from '../../mock_data';

describe('Image List', () => {
  let wrapper;

  const findRow = () => wrapper.findAll(ImageListRow);
  const findPagination = () => wrapper.find(GlPagination);

  const mountComponent = () => {
    wrapper = shallowMount(Component, {
      propsData: {
        images: imagesListResponse.data,
        pagination: imagePagination,
      },
    });
  };

  beforeEach(() => {
    mountComponent();
  });

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

  describe('list', () => {
    it('contains one list element for each image', () => {
      expect(findRow().length).toBe(imagesListResponse.data.length);
    });

    it('when delete event is emitted on the row it emits up a delete event', () => {
      findRow()
        .at(0)
        .vm.$emit('delete', 'foo');
      expect(wrapper.emitted('delete')).toEqual([['foo']]);
    });
  });

  describe('pagination', () => {
    it('exists', () => {
      expect(findPagination().exists()).toBe(true);
    });

    it('is wired to the correct pagination props', () => {
      const pagination = findPagination();
      expect(pagination.props('perPage')).toBe(imagePagination.perPage);
      expect(pagination.props('totalItems')).toBe(imagePagination.total);
      expect(pagination.props('value')).toBe(imagePagination.page);
    });

    it('emits a pageChange event when the page change', () => {
      findPagination().vm.$emit(GlPagination.model.event, 2);
      expect(wrapper.emitted('pageChange')).toEqual([[2]]);
    });
  });
});