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
84
85
86
|
import { mount } from '@vue/test-utils';
import PanelResizer from '~/vue_shared/components/panel_resizer.vue';
describe('Panel Resizer component', () => {
let wrapper;
const triggerEvent = (eventName, el = wrapper.element, clientX = 0) => {
const event = document.createEvent('MouseEvents');
event.initMouseEvent(
eventName,
true,
true,
window,
1,
clientX,
0,
clientX,
0,
false,
false,
false,
false,
0,
null,
);
el.dispatchEvent(event);
};
it('should render a div element with the correct classes and styles', () => {
wrapper = mount(PanelResizer, {
propsData: {
startSize: 100,
side: 'left',
},
});
expect(wrapper.element.tagName).toEqual('DIV');
expect(wrapper.classes().sort()).toStrictEqual([
'drag-handle',
'position-absolute',
'position-bottom-0',
'position-left-0',
'position-top-0',
]);
expect(wrapper.element.getAttribute('style')).toBe('cursor: ew-resize;');
});
it('should render a div element with the correct classes for a right side panel', () => {
wrapper = mount(PanelResizer, {
propsData: {
startSize: 100,
side: 'right',
},
});
expect(wrapper.element.tagName).toEqual('DIV');
expect(wrapper.classes().sort()).toStrictEqual([
'drag-handle',
'position-absolute',
'position-bottom-0',
'position-right-0',
'position-top-0',
]);
});
it('drag the resizer', () => {
wrapper = mount(PanelResizer, {
propsData: {
startSize: 100,
side: 'left',
},
});
triggerEvent('mousedown');
triggerEvent('mousemove', document);
triggerEvent('mouseup', document);
expect(wrapper.emitted()).toEqual({
'resize-start': [[100]],
'update:size': [[100]],
'resize-end': [[100]],
});
});
});
|