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

78 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-09-04 21:01:54 +05:30
import { mount, createLocalVue } from '@vue/test-utils';
import { GlPagination } from '@gitlab/ui';
2018-12-05 23:21:45 +05:30
import PaginationLinks from '~/vue_shared/components/pagination_links.vue';
2019-09-04 21:01:54 +05:30
import {
PREV,
NEXT,
LABEL_FIRST_PAGE,
LABEL_PREV_PAGE,
LABEL_NEXT_PAGE,
LABEL_LAST_PAGE,
} from '~/vue_shared/components/pagination/constants';
const localVue = createLocalVue();
2018-12-05 23:21:45 +05:30
describe('Pagination links component', () => {
const pageInfo = {
page: 3,
perPage: 5,
total: 30,
};
const translations = {
2019-09-04 21:01:54 +05:30
prevText: PREV,
nextText: NEXT,
labelFirstPage: LABEL_FIRST_PAGE,
labelPrevPage: LABEL_PREV_PAGE,
labelNextPage: LABEL_NEXT_PAGE,
labelLastPage: LABEL_LAST_PAGE,
2018-12-05 23:21:45 +05:30
};
2019-09-04 21:01:54 +05:30
let wrapper;
2018-12-05 23:21:45 +05:30
let glPagination;
2019-09-04 21:01:54 +05:30
let changeMock;
2018-12-05 23:21:45 +05:30
2019-09-04 21:01:54 +05:30
const createComponent = () => {
changeMock = jest.fn();
wrapper = mount(PaginationLinks, {
propsData: {
change: changeMock,
pageInfo,
},
localVue,
sync: false,
2018-12-13 13:39:08 +05:30
});
2019-09-04 21:01:54 +05:30
};
beforeEach(() => {
createComponent();
glPagination = wrapper.find(GlPagination);
2018-12-05 23:21:45 +05:30
});
afterEach(() => {
2019-09-04 21:01:54 +05:30
wrapper.destroy();
2018-12-05 23:21:45 +05:30
});
it('should provide translated text to GitLab UI pagination', () => {
2018-12-13 13:39:08 +05:30
Object.entries(translations).forEach(entry => {
2019-09-04 21:01:54 +05:30
expect(glPagination.vm[entry[0]]).toBe(entry[1]);
2018-12-13 13:39:08 +05:30
});
2018-12-05 23:21:45 +05:30
});
2019-09-04 21:01:54 +05:30
it('should call change when page changes', () => {
wrapper.find('a').trigger('click');
expect(changeMock).toHaveBeenCalled();
2018-12-05 23:21:45 +05:30
});
it('should pass page from pageInfo to GitLab UI pagination', () => {
2019-09-04 21:01:54 +05:30
expect(glPagination.vm.value).toBe(pageInfo.page);
2018-12-05 23:21:45 +05:30
});
it('should pass per page from pageInfo to GitLab UI pagination', () => {
2019-09-04 21:01:54 +05:30
expect(glPagination.vm.perPage).toBe(pageInfo.perPage);
2018-12-05 23:21:45 +05:30
});
it('should pass total items from pageInfo to GitLab UI pagination', () => {
2019-09-04 21:01:54 +05:30
expect(glPagination.vm.totalItems).toBe(pageInfo.total);
2018-12-05 23:21:45 +05:30
});
});