summaryrefslogtreecommitdiff
path: root/spec/frontend/releases/components/releases_pagination_spec.js
blob: 1d47da31f380d1d054189b2345d45feeb1203672 (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
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import ReleasesPagination from '~/releases/components/releases_pagination.vue';
import ReleasesPaginationGraphql from '~/releases/components/releases_pagination_graphql.vue';
import ReleasesPaginationRest from '~/releases/components/releases_pagination_rest.vue';

const localVue = createLocalVue();
localVue.use(Vuex);

describe('~/releases/components/releases_pagination.vue', () => {
  let wrapper;

  const createComponent = (useGraphQLEndpoint) => {
    const store = new Vuex.Store({
      getters: {
        useGraphQLEndpoint: () => useGraphQLEndpoint,
      },
    });

    wrapper = shallowMount(ReleasesPagination, { store, localVue });
  };

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

  const findRestPagination = () => wrapper.find(ReleasesPaginationRest);
  const findGraphQlPagination = () => wrapper.find(ReleasesPaginationGraphql);

  describe('when one of necessary feature flags is disabled', () => {
    beforeEach(() => {
      createComponent(false);
    });

    it('renders the REST pagination component', () => {
      expect(findRestPagination().exists()).toBe(true);
      expect(findGraphQlPagination().exists()).toBe(false);
    });
  });

  describe('when all the necessary feature flags are enabled', () => {
    beforeEach(() => {
      createComponent(true);
    });

    it('renders the GraphQL pagination component', () => {
      expect(findGraphQlPagination().exists()).toBe(true);
      expect(findRestPagination().exists()).toBe(false);
    });
  });
});