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

pagination_links_spec.js « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad82aee009859a88db5b5738c85ca2e553648d0f (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
import { mount } from '@vue/test-utils';
import { GlPagination } from '@gitlab/ui';
import PaginationLinks from '~/vue_shared/components/pagination_links.vue';
import {
  PREV,
  NEXT,
  LABEL_FIRST_PAGE,
  LABEL_PREV_PAGE,
  LABEL_NEXT_PAGE,
  LABEL_LAST_PAGE,
} from '~/vue_shared/components/pagination/constants';

describe('Pagination links component', () => {
  const pageInfo = {
    page: 3,
    perPage: 5,
    total: 30,
  };
  const translations = {
    prevText: PREV,
    nextText: NEXT,
    labelFirstPage: LABEL_FIRST_PAGE,
    labelPrevPage: LABEL_PREV_PAGE,
    labelNextPage: LABEL_NEXT_PAGE,
    labelLastPage: LABEL_LAST_PAGE,
  };

  let wrapper;
  let glPagination;
  let changeMock;

  const createComponent = () => {
    changeMock = jest.fn();
    wrapper = mount(PaginationLinks, {
      propsData: {
        change: changeMock,
        pageInfo,
      },
    });
  };

  beforeEach(() => {
    createComponent();
    glPagination = wrapper.find(GlPagination);
  });

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

  it('should provide translated text to GitLab UI pagination', () => {
    Object.entries(translations).forEach((entry) => {
      expect(glPagination.vm[entry[0]]).toBe(entry[1]);
    });
  });

  it('should call change when page changes', () => {
    wrapper.find('a').trigger('click');
    expect(changeMock).toHaveBeenCalled();
  });

  it('should pass page from pageInfo to GitLab UI pagination', () => {
    expect(glPagination.vm.value).toBe(pageInfo.page);
  });

  it('should pass per page from pageInfo to GitLab UI pagination', () => {
    expect(glPagination.vm.perPage).toBe(pageInfo.perPage);
  });

  it('should pass total items from pageInfo to GitLab UI pagination', () => {
    expect(glPagination.vm.totalItems).toBe(pageInfo.total);
  });
});