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

tags_spec.js « pages « harbor_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: 7e0f05e736bb760b2fe05073cece3fba4d715998 (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
120
121
122
123
124
125
import { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils';
import HarborTagsPage from '~/packages_and_registries/harbor_registry/pages/harbor_tags.vue';
import TagsHeader from '~/packages_and_registries/harbor_registry/components/tags/tags_header.vue';
import TagsList from '~/packages_and_registries/harbor_registry/components/tags/tags_list.vue';
import waitForPromises from 'helpers/wait_for_promises';
import { defaultConfig, harborTagsResponse, mockArtifactDetail } from '../mock_data';

let mockHarborTagsResponse;

jest.mock('~/rest_api', () => ({
  getHarborTags: () => mockHarborTagsResponse,
}));

describe('Harbor Tags page', () => {
  let wrapper;

  const findTagsHeader = () => wrapper.find(TagsHeader);
  const findTagsList = () => wrapper.find(TagsList);

  const waitForHarborTagsRequest = async () => {
    await waitForPromises();
    await nextTick();
  };

  const breadCrumbState = {
    updateName: jest.fn(),
    updateHref: jest.fn(),
  };

  const $route = {
    params: mockArtifactDetail,
  };

  const defaultHeaders = {
    'x-page': '1',
    'X-Per-Page': '20',
    'X-TOTAL': '1',
    'X-Total-Pages': '1',
  };

  const mountComponent = ({ endpoint = defaultConfig.endpoint } = {}) => {
    wrapper = shallowMount(HarborTagsPage, {
      mocks: {
        $route,
      },
      provide() {
        return {
          breadCrumbState,
          endpoint,
        };
      },
    });
  };

  beforeEach(() => {
    mockHarborTagsResponse = Promise.resolve({
      data: harborTagsResponse,
      headers: defaultHeaders,
    });
  });

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

  it('contains tags header', () => {
    mountComponent();

    expect(findTagsHeader().exists()).toBe(true);
  });

  it('contains tags list', () => {
    mountComponent();

    expect(findTagsList().exists()).toBe(true);
  });

  describe('header', () => {
    it('has the correct props', async () => {
      mountComponent();

      await waitForHarborTagsRequest();
      expect(findTagsHeader().props()).toMatchObject({
        artifactDetail: mockArtifactDetail,
        pageInfo: {
          page: 1,
          perPage: 20,
          total: 1,
          totalPages: 1,
        },
        tagsLoading: false,
      });
    });
  });

  describe('list', () => {
    it('has the correct props', async () => {
      mountComponent();

      await waitForHarborTagsRequest();
      expect(findTagsList().props()).toMatchObject({
        tags: [
          {
            repositoryId: 4,
            artifactId: 5,
            id: 4,
            name: 'latest',
            pullTime: '0001-01-01T00:00:00.000Z',
            pushTime: '2022-05-27T18:21:27.903Z',
            signed: false,
            immutable: false,
          },
        ],
        isLoading: false,
        pageInfo: {
          page: 1,
          perPage: 20,
          total: 1,
          totalPages: 1,
        },
      });
    });
  });
});