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

runner_pagination_spec.js « components « runner « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e144b52ceb3a984ff34fe20c4f7b9fb61182a201 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { GlPagination } from '@gitlab/ui';
import { mount } from '@vue/test-utils';
import RunnerPagination from '~/runner/components/runner_pagination.vue';

const mockStartCursor = 'START_CURSOR';
const mockEndCursor = 'END_CURSOR';

describe('RunnerPagination', () => {
  let wrapper;

  const findPagination = () => wrapper.findComponent(GlPagination);

  const createComponent = ({ page = 1, hasPreviousPage = false, hasNextPage = true } = {}) => {
    wrapper = mount(RunnerPagination, {
      propsData: {
        value: {
          page,
        },
        pageInfo: {
          hasPreviousPage,
          hasNextPage,
          startCursor: mockStartCursor,
          endCursor: mockEndCursor,
        },
      },
    });
  };

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

  describe('When on the first page', () => {
    beforeEach(() => {
      createComponent({
        page: 1,
        hasPreviousPage: false,
        hasNextPage: true,
      });
    });

    it('Contains the current page information', () => {
      expect(findPagination().props('value')).toBe(1);
      expect(findPagination().props('prevPage')).toBe(null);
      expect(findPagination().props('nextPage')).toBe(2);
    });

    it('Goes to the second page', () => {
      findPagination().vm.$emit('input', 2);

      expect(wrapper.emitted('input')[0]).toEqual([
        {
          after: mockEndCursor,
          page: 2,
        },
      ]);
    });
  });

  describe('When in between pages', () => {
    beforeEach(() => {
      createComponent({
        page: 2,
        hasPreviousPage: true,
        hasNextPage: true,
      });
    });

    it('Contains the current page information', () => {
      expect(findPagination().props('value')).toBe(2);
      expect(findPagination().props('prevPage')).toBe(1);
      expect(findPagination().props('nextPage')).toBe(3);
    });

    it('Shows the next and previous pages', () => {
      const links = findPagination().findAll('a');

      expect(links).toHaveLength(2);
      expect(links.at(0).text()).toBe('Previous');
      expect(links.at(1).text()).toBe('Next');
    });

    it('Goes to the last page', () => {
      findPagination().vm.$emit('input', 3);

      expect(wrapper.emitted('input')[0]).toEqual([
        {
          after: mockEndCursor,
          page: 3,
        },
      ]);
    });

    it('Goes to the first page', () => {
      findPagination().vm.$emit('input', 1);

      expect(wrapper.emitted('input')[0]).toEqual([
        {
          page: 1,
        },
      ]);
    });
  });

  describe('When in the last page', () => {
    beforeEach(() => {
      createComponent({
        page: 3,
        hasPreviousPage: true,
        hasNextPage: false,
      });
    });

    it('Contains the current page', () => {
      expect(findPagination().props('value')).toBe(3);
      expect(findPagination().props('prevPage')).toBe(2);
      expect(findPagination().props('nextPage')).toBe(null);
    });
  });

  describe('When only one page', () => {
    beforeEach(() => {
      createComponent({
        page: 1,
        hasPreviousPage: false,
        hasNextPage: false,
      });
    });

    it('does not display pagination', () => {
      expect(wrapper.html()).toBe('');
    });

    it('Contains the current page', () => {
      expect(findPagination().props('value')).toBe(1);
    });

    it('Shows no more page buttons', () => {
      expect(findPagination().props('prevPage')).toBe(null);
      expect(findPagination().props('nextPage')).toBe(null);
    });
  });
});