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

issues_list_app_spec.js « components « issues_list « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1053e8934c97e59ed087a796a39ce2f0421266d5 (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
import { shallowMount } from '@vue/test-utils';
import AxiosMockAdapter from 'axios-mock-adapter';
import waitForPromises from 'helpers/wait_for_promises';
import IssuableList from '~/issuable_list/components/issuable_list_root.vue';
import IssuesListApp from '~/issues_list/components/issues_list_app.vue';
import axios from '~/lib/utils/axios_utils';

describe('IssuesListApp component', () => {
  let axiosMock;
  let wrapper;

  const fullPath = 'path/to/project';
  const endpoint = 'api/endpoint';
  const state = 'opened';
  const xPage = 1;
  const xTotal = 25;
  const fetchIssuesResponse = {
    data: [],
    headers: {
      'x-page': xPage,
      'x-total': xTotal,
    },
  };

  const findIssuableList = () => wrapper.findComponent(IssuableList);

  const mountComponent = () =>
    shallowMount(IssuesListApp, {
      provide: {
        endpoint,
        fullPath,
      },
    });

  beforeEach(async () => {
    axiosMock = new AxiosMockAdapter(axios);
    axiosMock.onGet(endpoint).reply(200, fetchIssuesResponse.data, fetchIssuesResponse.headers);
    wrapper = mountComponent();
    await waitForPromises();
  });

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

  it('renders IssuableList', () => {
    expect(findIssuableList().props()).toMatchObject({
      namespace: fullPath,
      recentSearchesStorageKey: 'issues',
      searchInputPlaceholder: 'Search or filter results…',
      showPaginationControls: true,
      issuables: [],
      totalItems: xTotal,
      currentPage: xPage,
      previousPage: xPage - 1,
      nextPage: xPage + 1,
      urlParams: { page: xPage, state },
    });
  });

  describe('when "page-change" event is emitted', () => {
    const data = [{ id: 10, title: 'title', state }];
    const page = 2;
    const totalItems = 21;

    beforeEach(async () => {
      axiosMock.onGet(endpoint).reply(200, data, {
        'x-page': page,
        'x-total': totalItems,
      });

      findIssuableList().vm.$emit('page-change', page);

      await waitForPromises();
    });

    it('fetches issues with expected params', async () => {
      expect(axiosMock.history.get[1].params).toEqual({
        page,
        per_page: 20,
        state,
        with_labels_details: true,
      });
    });

    it('updates IssuableList with response data', () => {
      expect(findIssuableList().props()).toMatchObject({
        issuables: data,
        totalItems,
        currentPage: page,
        previousPage: page - 1,
        nextPage: page + 1,
        urlParams: { page, state },
      });
    });
  });
});