summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/table_pagination_spec.js
blob: 12c47637358fdb05b3089969233f3ce96005dd41 (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 { GlPagination } from '@gitlab/ui';
import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue';

describe('Pagination component', () => {
  let wrapper;
  let spy;

  const mountComponent = (props) => {
    wrapper = shallowMount(TablePagination, {
      propsData: props,
    });
  };

  beforeEach(() => {
    spy = jest.fn();
  });

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

  describe('render', () => {
    it('should not render anything', () => {
      mountComponent({
        pageInfo: {
          nextPage: NaN,
          page: 1,
          perPage: 20,
          previousPage: NaN,
          total: 15,
          totalPages: 1,
        },
        change: spy,
      });

      expect(wrapper.html()).toBe('');
    });

    it('renders if there is a next page', () => {
      mountComponent({
        pageInfo: {
          nextPage: 2,
          page: 1,
          perPage: 20,
          previousPage: NaN,
          total: 15,
          totalPages: 1,
        },
        change: spy,
      });

      expect(wrapper.find(GlPagination).exists()).toBe(true);
    });

    it('renders if there is a prev page', () => {
      mountComponent({
        pageInfo: {
          nextPage: NaN,
          page: 2,
          perPage: 20,
          previousPage: 1,
          total: 15,
          totalPages: 1,
        },
        change: spy,
      });

      expect(wrapper.find(GlPagination).exists()).toBe(true);
    });
  });

  describe('events', () => {
    it('calls change method when page changes', () => {
      mountComponent({
        pageInfo: {
          nextPage: NaN,
          page: 2,
          perPage: 20,
          previousPage: 1,
          total: 15,
          totalPages: 1,
        },
        change: spy,
      });
      wrapper.find(GlPagination).vm.$emit('input', 3);
      expect(spy).toHaveBeenCalledWith(3);
    });
  });
});