debian-mirror-gitlab/spec/frontend/vue_shared/components/table_pagination_spec.js

91 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-01-01 13:55:28 +05:30
import { GlPagination } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { shallowMount } from '@vue/test-utils';
2020-10-24 23:57:45 +05:30
import TablePagination from '~/vue_shared/components/pagination/table_pagination.vue';
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
2021-03-08 18:12:59 +05:30
const mountComponent = (props) => {
2019-12-26 22:10:19 +05:30
wrapper = shallowMount(TablePagination, {
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,
});
2020-11-24 15:15:51 +05:30
expect(wrapper.html()).toBe('');
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-11-24 15:15:51 +05:30
expect(wrapper.find(GlPagination).exists()).toBe(true);
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-11-24 15:15:51 +05:30
expect(wrapper.find(GlPagination).exists()).toBe(true);
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
});
});