debian-mirror-gitlab/spec/frontend/releases/components/releases_pagination_rest_spec.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { GlPagination } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import * as commonUtils from '~/lib/utils/common_utils';
2020-11-24 15:15:51 +05:30
import ReleasesPaginationRest from '~/releases/components/releases_pagination_rest.vue';
import createStore from '~/releases/stores';
import createListModule from '~/releases/stores/modules/list';
commonUtils.historyPushState = jest.fn();
const localVue = createLocalVue();
localVue.use(Vuex);
describe('~/releases/components/releases_pagination_rest.vue', () => {
let wrapper;
let listModule;
const projectId = 19;
2021-03-08 18:12:59 +05:30
const createComponent = (pageInfo) => {
2020-11-24 15:15:51 +05:30
listModule = createListModule({ projectId });
2021-01-03 14:25:43 +05:30
listModule.state.restPageInfo = pageInfo;
2020-11-24 15:15:51 +05:30
2021-01-03 14:25:43 +05:30
listModule.actions.fetchReleases = jest.fn();
2020-11-24 15:15:51 +05:30
wrapper = mount(ReleasesPaginationRest, {
store: createStore({
modules: {
list: listModule,
},
featureFlags: {},
}),
localVue,
});
};
const findGlPagination = () => wrapper.find(GlPagination);
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
describe('when a page number is clicked', () => {
const newPage = 2;
beforeEach(() => {
createComponent({
perPage: 20,
page: 1,
total: 40,
totalPages: 2,
nextPage: 2,
});
findGlPagination().vm.$emit('input', newPage);
});
2021-01-03 14:25:43 +05:30
it('calls fetchReleases with the correct page', () => {
expect(listModule.actions.fetchReleases.mock.calls).toEqual([
2020-11-24 15:15:51 +05:30
[expect.anything(), { page: newPage }],
]);
});
it('calls historyPushState with the new URL', () => {
expect(commonUtils.historyPushState.mock.calls).toEqual([
[expect.stringContaining(`?page=${newPage}`)],
]);
});
});
});