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