2019-10-22 14:06:35 -04:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue';
|
2019-12-11 07:08:10 -05:00
|
|
|
import { GlPagination } from '@gitlab/ui';
|
2016-12-08 19:37:00 -05:00
|
|
|
|
|
|
|
describe('Pagination component', () => {
|
2019-10-22 14:06:35 -04:00
|
|
|
let wrapper;
|
2017-07-07 17:23:13 -04:00
|
|
|
let spy;
|
2019-10-22 14:06:35 -04:00
|
|
|
|
|
|
|
const mountComponent = props => {
|
|
|
|
wrapper = shallowMount(TablePagination, {
|
|
|
|
propsData: props,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-03-17 13:30:32 -04:00
|
|
|
beforeEach(() => {
|
2019-10-22 14:06:35 -04:00
|
|
|
spy = jest.fn();
|
|
|
|
});
|
2016-12-13 12:38:51 -05:00
|
|
|
|
2019-10-22 14:06:35 -04:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
2016-12-13 12:52:07 -05:00
|
|
|
});
|
2016-12-13 12:38:51 -05:00
|
|
|
|
2017-07-07 17:23:13 -04:00
|
|
|
describe('render', () => {
|
2017-12-18 18:08:28 -05:00
|
|
|
it('should not render anything', () => {
|
2019-10-22 14:06:35 -04:00
|
|
|
mountComponent({
|
2017-12-18 18:08:28 -05:00
|
|
|
pageInfo: {
|
2019-02-27 08:32:08 -05:00
|
|
|
nextPage: NaN,
|
2017-12-18 18:08:28 -05:00
|
|
|
page: 1,
|
|
|
|
perPage: 20,
|
2019-02-27 08:32:08 -05:00
|
|
|
previousPage: NaN,
|
2017-12-18 18:08:28 -05:00
|
|
|
total: 15,
|
|
|
|
totalPages: 1,
|
|
|
|
},
|
|
|
|
change: spy,
|
|
|
|
});
|
|
|
|
|
2019-10-22 14:06:35 -04:00
|
|
|
expect(wrapper.isEmpty()).toBe(true);
|
2017-12-18 18:08:28 -05:00
|
|
|
});
|
|
|
|
|
2019-12-11 07:08:10 -05:00
|
|
|
it('renders if there is a next page', () => {
|
|
|
|
mountComponent({
|
|
|
|
pageInfo: {
|
|
|
|
nextPage: 2,
|
|
|
|
page: 1,
|
|
|
|
perPage: 20,
|
|
|
|
previousPage: NaN,
|
|
|
|
total: 15,
|
|
|
|
totalPages: 1,
|
|
|
|
},
|
|
|
|
change: spy,
|
2017-07-07 17:23:13 -04:00
|
|
|
});
|
2019-02-27 08:32:08 -05:00
|
|
|
|
2019-12-11 07:08:10 -05:00
|
|
|
expect(wrapper.isEmpty()).toBe(false);
|
2017-07-07 17:23:13 -04:00
|
|
|
});
|
|
|
|
|
2019-12-11 07:08:10 -05:00
|
|
|
it('renders if there is a prev page', () => {
|
|
|
|
mountComponent({
|
|
|
|
pageInfo: {
|
|
|
|
nextPage: NaN,
|
|
|
|
page: 2,
|
|
|
|
perPage: 20,
|
|
|
|
previousPage: 1,
|
|
|
|
total: 15,
|
|
|
|
totalPages: 1,
|
|
|
|
},
|
|
|
|
change: spy,
|
2017-07-07 17:23:13 -04:00
|
|
|
});
|
2019-02-27 08:32:08 -05:00
|
|
|
|
2019-12-11 07:08:10 -05:00
|
|
|
expect(wrapper.isEmpty()).toBe(false);
|
2017-07-07 17:23:13 -04:00
|
|
|
});
|
2019-12-11 07:08:10 -05:00
|
|
|
});
|
2017-07-07 17:23:13 -04:00
|
|
|
|
2019-12-11 07:08:10 -05:00
|
|
|
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,
|
2019-02-27 08:32:08 -05:00
|
|
|
});
|
2019-12-11 07:08:10 -05:00
|
|
|
wrapper.find(GlPagination).vm.$emit('input', 3);
|
|
|
|
expect(spy).toHaveBeenCalledWith(3);
|
2017-07-07 17:23:13 -04:00
|
|
|
});
|
2016-12-16 18:31:28 -05:00
|
|
|
});
|
|
|
|
});
|