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: 499cc59250d75383c92c3d1c80501321ffc4d90e (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
import { GlKeysetPagination } from '@gitlab/ui';
import { shallowMount } 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(GlKeysetPagination);

  const createComponent = (propsData = {}) => {
    wrapper = shallowMount(RunnerPagination, {
      propsData,
    });
  };

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

  describe('When in between pages', () => {
    const mockPageInfo = {
      startCursor: mockStartCursor,
      endCursor: mockEndCursor,
      hasPreviousPage: true,
      hasNextPage: true,
    };

    beforeEach(() => {
      createComponent({
        pageInfo: mockPageInfo,
      });
    });

    it('Contains the current page information', () => {
      expect(findPagination().props()).toMatchObject(mockPageInfo);
    });

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

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

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

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

  describe.each`
    page       | hasPreviousPage | hasNextPage
    ${'first'} | ${false}        | ${true}
    ${'last'}  | ${true}         | ${false}
  `('When on the $page page', ({ page, hasPreviousPage, hasNextPage }) => {
    const mockPageInfo = {
      startCursor: mockStartCursor,
      endCursor: mockEndCursor,
      hasPreviousPage,
      hasNextPage,
    };

    beforeEach(() => {
      createComponent({
        pageInfo: mockPageInfo,
      });
    });

    it(`Contains the ${page} page information`, () => {
      expect(findPagination().props()).toMatchObject(mockPageInfo);
    });
  });

  describe('When no other pages', () => {
    beforeEach(() => {
      createComponent({
        pageInfo: {
          hasPreviousPage: false,
          hasNextPage: false,
        },
      });
    });

    it('is not shown', () => {
      expect(findPagination().exists()).toBe(false);
    });
  });

  describe('When adding more attributes', () => {
    beforeEach(() => {
      createComponent({
        pageInfo: {
          hasPreviousPage: true,
          hasNextPage: false,
        },
        disabled: true,
      });
    });

    it('attributes are passed', () => {
      expect(findPagination().props('disabled')).toBe(true);
    });
  });
});