summaryrefslogtreecommitdiff
path: root/spec/frontend/packages_and_registries/dependency_proxy/components/manifest_list_spec.js
blob: 9e4c747a1bda9fc44f053068a6072fcfa472762a (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
import { GlKeysetPagination } from '@gitlab/ui';
import { stripTypenames } from 'helpers/graphql_helpers';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ManifestRow from '~/packages_and_registries/dependency_proxy/components/manifest_row.vue';

import Component from '~/packages_and_registries/dependency_proxy/components/manifests_list.vue';
import {
  proxyManifests,
  pagination,
} from 'jest/packages_and_registries/dependency_proxy/mock_data';

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

  const defaultProps = {
    manifests: proxyManifests(),
    pagination: stripTypenames(pagination()),
  };

  const createComponent = (propsData = defaultProps) => {
    wrapper = shallowMountExtended(Component, {
      propsData,
    });
  };

  const findRows = () => wrapper.findAllComponents(ManifestRow);
  const findPagination = () => wrapper.findComponent(GlKeysetPagination);

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

  it('has the correct title', () => {
    createComponent();

    expect(wrapper.text()).toContain(Component.i18n.listTitle);
  });

  it('shows a row for every manifest', () => {
    createComponent();

    expect(findRows().length).toBe(defaultProps.manifests.length);
  });

  it('binds a manifest to each row', () => {
    createComponent();

    expect(findRows().at(0).props()).toMatchObject({
      manifest: defaultProps.manifests[0],
    });
  });

  describe('pagination', () => {
    it('is hidden when there is no next or prev pages', () => {
      createComponent({ ...defaultProps, pagination: {} });

      expect(findPagination().exists()).toBe(false);
    });

    it('has the correct props', () => {
      createComponent();

      expect(findPagination().props()).toMatchObject({
        ...defaultProps.pagination,
      });
    });

    it('emits the next-page event', () => {
      createComponent();

      findPagination().vm.$emit('next');

      expect(wrapper.emitted('next-page')).toEqual([[]]);
    });

    it('emits the prev-page event', () => {
      createComponent();

      findPagination().vm.$emit('prev');

      expect(wrapper.emitted('prev-page')).toEqual([[]]);
    });
  });
});