2019-08-09 13:51:28 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import PagesBlock from '@/components/common/PagesBlock.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-08-09 13:51:28 +01:00
|
|
|
import { Page } from '@/types/pagination';
|
2021-08-05 12:07:45 +01:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2019-08-09 13:51:28 +01:00
|
|
|
|
|
|
|
describe('Pagination.vue', () => {
|
|
|
|
it('renders correctly without props', () => {
|
|
|
|
const wrapper = shallowMount(PagesBlock);
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with props', () => {
|
2022-04-07 12:04:24 +01:00
|
|
|
const callbackSpy = jest.fn();
|
2019-08-09 13:51:28 +01:00
|
|
|
const pagesArray: Page[] = [];
|
2021-08-02 19:17:49 +01:00
|
|
|
const SELECTED_PAGE_INDEX = 3;
|
2019-08-09 13:51:28 +01:00
|
|
|
|
|
|
|
for (let i = 1; i <= 4; i++) {
|
|
|
|
pagesArray.push(new Page(i, callbackSpy));
|
|
|
|
}
|
|
|
|
|
|
|
|
const wrapper = shallowMount(PagesBlock, {
|
|
|
|
propsData: {
|
|
|
|
pages: pagesArray,
|
2019-09-23 12:31:42 +01:00
|
|
|
isSelected: (i: number) => i === SELECTED_PAGE_INDEX,
|
2019-09-13 15:58:18 +01:00
|
|
|
},
|
2019-08-09 13:51:28 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.findAll('span').length).toBe(4);
|
|
|
|
expect(wrapper.findAll('span').at(2).classes().includes('selected')).toBe(true);
|
|
|
|
});
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
it('behaves correctly on page click', () => {
|
2022-04-07 12:04:24 +01:00
|
|
|
const callbackSpy = jest.fn();
|
2019-09-09 11:33:39 +01:00
|
|
|
const pagesArray: Page[] = [];
|
2019-08-09 13:51:28 +01:00
|
|
|
|
|
|
|
for (let i = 1; i <= 3; i++) {
|
|
|
|
pagesArray.push(new Page(i, callbackSpy));
|
|
|
|
}
|
|
|
|
|
|
|
|
const wrapper = shallowMount(PagesBlock, {
|
|
|
|
propsData: {
|
|
|
|
pages: pagesArray,
|
2019-09-23 12:31:42 +01:00
|
|
|
isSelected: () => false,
|
2019-09-13 15:58:18 +01:00
|
|
|
},
|
2019-08-09 13:51:28 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.findAll('span').at(1).trigger('click');
|
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
expect(callbackSpy).toHaveBeenCalledTimes(1);
|
2019-08-09 13:51:28 +01:00
|
|
|
});
|
|
|
|
});
|