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

image_list_spec.js « components « explorer « registry « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12f0fbe0c87c949f8d85065e91f157959fe1c94e (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
import { shallowMount } from '@vue/test-utils';
import { GlPagination } from '@gitlab/ui';
import Component from '~/registry/explorer/components/image_list.vue';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import { RouterLink } from '../stubs';
import { imagesListResponse, imagePagination } from '../mock_data';

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

  const firstElement = imagesListResponse.data[0];

  const findDeleteBtn = () => wrapper.find('[data-testid="deleteImageButton"]');
  const findRowItems = () => wrapper.findAll('[data-testid="rowItem"]');
  const findDetailsLink = () => wrapper.find('[data-testid="detailsLink"]');
  const findClipboardButton = () => wrapper.find(ClipboardButton);
  const findPagination = () => wrapper.find(GlPagination);

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

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

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

  it('contains a link to the details page', () => {
    const link = findDetailsLink();
    expect(link.html()).toContain(firstElement.path);
    expect(link.props('to').name).toBe('details');
  });

  it('contains a clipboard button', () => {
    const button = findClipboardButton();
    expect(button.exists()).toBe(true);
    expect(button.props('text')).toBe(firstElement.location);
    expect(button.props('title')).toBe(firstElement.location);
  });

  it('should be possible to delete a repo', () => {
    const deleteBtn = findDeleteBtn();
    expect(deleteBtn.exists()).toBe(true);
  });

  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', () => {
      wrapper.setData({ currentPage: 2 });
      expect(wrapper.emitted('pageChange')).toEqual([[2]]);
    });
  });
});