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

additional_metadata_spec.js « components « details « packages « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 111e4205abbe0e54a0961b8869824f92a6257092 (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
import { shallowMount } from '@vue/test-utils';
import { GlLink, GlSprintf } from '@gitlab/ui';
import DetailsRow from '~/vue_shared/components/registry/details_row.vue';
import component from '~/packages/details/components/additional_metadata.vue';

import { mavenPackage, conanPackage, nugetPackage, npmPackage } from '../../mock_data';

describe('Package Additional Metadata', () => {
  let wrapper;
  const defaultProps = {
    packageEntity: { ...mavenPackage },
  };

  const mountComponent = props => {
    wrapper = shallowMount(component, {
      propsData: { ...defaultProps, ...props },
      stubs: {
        DetailsRow,
        GlSprintf,
      },
    });
  };

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

  const findTitle = () => wrapper.find('[data-testid="title"]');
  const findMainArea = () => wrapper.find('[data-testid="main"]');
  const findNugetSource = () => wrapper.find('[data-testid="nuget-source"]');
  const findNugetLicense = () => wrapper.find('[data-testid="nuget-license"]');
  const findConanRecipe = () => wrapper.find('[data-testid="conan-recipe"]');
  const findMavenApp = () => wrapper.find('[data-testid="maven-app"]');
  const findMavenGroup = () => wrapper.find('[data-testid="maven-group"]');
  const findElementLink = container => container.find(GlLink);

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

    const title = findTitle();

    expect(title.exists()).toBe(true);
    expect(title.text()).toBe('Additional Metadata');
  });

  describe.each`
    packageEntity   | visible  | metadata
    ${mavenPackage} | ${true}  | ${'maven_metadatum'}
    ${conanPackage} | ${true}  | ${'conan_metadatum'}
    ${nugetPackage} | ${true}  | ${'nuget_metadatum'}
    ${npmPackage}   | ${false} | ${null}
  `('Component visibility', ({ packageEntity, visible, metadata }) => {
    it(`Is ${visible} that the component markup is visible when the package is ${packageEntity.package_type}`, () => {
      mountComponent({ packageEntity });

      expect(findTitle().exists()).toBe(visible);
      expect(findMainArea().exists()).toBe(visible);
    });

    it(`The component is hidden if ${metadata} is missing`, () => {
      mountComponent({ packageEntity: { ...packageEntity, [metadata]: null } });

      expect(findTitle().exists()).toBe(false);
      expect(findMainArea().exists()).toBe(false);
    });
  });

  describe('nuget metadata', () => {
    beforeEach(() => {
      mountComponent({ packageEntity: nugetPackage });
    });

    it.each`
      name         | finderFunction      | text                                                | link             | icon
      ${'source'}  | ${findNugetSource}  | ${'Source project located at project-foo-url'}      | ${'project_url'} | ${'project'}
      ${'license'} | ${findNugetLicense} | ${'License information located at license-foo-url'} | ${'license_url'} | ${'license'}
    `('$name element', ({ finderFunction, text, link, icon }) => {
      const element = finderFunction();
      expect(element.exists()).toBe(true);
      expect(element.text()).toBe(text);
      expect(element.props('icon')).toBe(icon);
      expect(findElementLink(element).attributes('href')).toBe(nugetPackage.nuget_metadatum[link]);
    });
  });

  describe('conan metadata', () => {
    beforeEach(() => {
      mountComponent({ packageEntity: conanPackage });
    });

    it.each`
      name        | finderFunction     | text                                                        | icon
      ${'recipe'} | ${findConanRecipe} | ${'Recipe: conan-package/1.0.0@conan+conan-package/stable'} | ${'information-o'}
    `('$name element', ({ finderFunction, text, icon }) => {
      const element = finderFunction();
      expect(element.exists()).toBe(true);
      expect(element.text()).toBe(text);
      expect(element.props('icon')).toBe(icon);
    });
  });

  describe('maven metadata', () => {
    beforeEach(() => {
      mountComponent();
    });

    it.each`
      name       | finderFunction    | text                         | icon
      ${'app'}   | ${findMavenApp}   | ${'App name: test-app'}      | ${'information-o'}
      ${'group'} | ${findMavenGroup} | ${'App group: com.test.app'} | ${'information-o'}
    `('$name element', ({ finderFunction, text, icon }) => {
      const element = finderFunction();
      expect(element.exists()).toBe(true);
      expect(element.text()).toBe(text);
      expect(element.props('icon')).toBe(icon);
    });
  });
});