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

infrastructure_title_spec.js « components « list « components « infrastructure_registry « packages_and_registries « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 72d08d5683b4b12bd51ab65b5a9a42db29431c93 (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
import { shallowMount } from '@vue/test-utils';
import component from '~/packages_and_registries/infrastructure_registry/list/components/infrastructure_title.vue';
import MetadataItem from '~/vue_shared/components/registry/metadata_item.vue';
import TitleArea from '~/vue_shared/components/registry/title_area.vue';

describe('Infrastructure Title', () => {
  let wrapper;
  let store;

  const findTitleArea = () => wrapper.find(TitleArea);
  const findMetadataItem = () => wrapper.find(MetadataItem);

  const exampleProps = { helpUrl: 'http://example.gitlab.com/help' };

  const mountComponent = (propsData = exampleProps) => {
    wrapper = shallowMount(component, {
      store,
      propsData,
      stubs: {
        TitleArea,
      },
    });
  };

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

  describe('title area', () => {
    beforeEach(() => {
      mountComponent();
    });

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

    it('has the correct title', () => {
      expect(findTitleArea().props('title')).toBe('Infrastructure Registry');
    });

    describe('with no modules', () => {
      it('has no info message', () => {
        expect(findTitleArea().props('infoMessages')).toStrictEqual([]);
      });
    });

    describe('with at least one module', () => {
      beforeEach(() => {
        mountComponent({ ...exampleProps, count: 1 });
      });

      it('has an info message', () => {
        expect(findTitleArea().props('infoMessages')).toStrictEqual([
          {
            text: 'Publish and share your modules. %{docLinkStart}More information%{docLinkEnd}',
            link: exampleProps.helpUrl,
          },
        ]);
      });
    });
  });

  describe.each`
    count        | exist    | text
    ${null}      | ${false} | ${''}
    ${undefined} | ${false} | ${''}
    ${0}         | ${false} | ${''}
    ${1}         | ${true}  | ${'1 Module'}
    ${2}         | ${true}  | ${'2 Modules'}
  `('when count is $count metadata item', ({ count, exist, text }) => {
    beforeEach(() => {
      mountComponent({ ...exampleProps, count });
    });

    it(exist ? 'exists' : 'does not exist', () => {
      expect(findMetadataItem().exists()).toBe(exist);
    });

    if (exist) {
      it('has the correct props', () => {
        expect(findMetadataItem().props()).toMatchObject({
          icon: 'infrastructure-registry',
          text,
        });
      });
    }
  });
});