1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/* global Mousetrap */
import 'mousetrap';
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import DesignNavigation from '~/design_management/components/toolbar/design_navigation.vue';
import { DESIGN_ROUTE_NAME } from '~/design_management/router/constants';
const push = jest.fn();
const $router = {
push,
};
const $route = {
path: '/designs/design-2',
query: {},
};
describe('Design management pagination component', () => {
let wrapper;
function createComponent() {
wrapper = shallowMount(DesignNavigation, {
propsData: {
id: '2',
},
mocks: {
$router,
$route,
},
});
}
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
});
it('hides components when designs are empty', () => {
expect(wrapper.element).toMatchSnapshot();
});
it('renders navigation buttons', async () => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData({
designCollection: { designs: [{ id: '1' }, { id: '2' }] },
});
await nextTick();
expect(wrapper.element).toMatchSnapshot();
});
describe('keyboard buttons navigation', () => {
beforeEach(() => {
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
wrapper.setData({
designCollection: { designs: [{ filename: '1' }, { filename: '2' }, { filename: '3' }] },
});
});
it('routes to previous design on Left button', () => {
Mousetrap.trigger('left');
expect(push).toHaveBeenCalledWith({
name: DESIGN_ROUTE_NAME,
params: { id: '1' },
query: {},
});
});
it('routes to next design on Right button', () => {
Mousetrap.trigger('right');
expect(push).toHaveBeenCalledWith({
name: DESIGN_ROUTE_NAME,
params: { id: '3' },
query: {},
});
});
});
});
|