-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverse-path.test.js
68 lines (56 loc) · 1.55 KB
/
reverse-path.test.js
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
const PointType = window.PointType = {
CORNER: 1,
SMOOTH: 2,
}
const path = {
selectedPathPoints: [],
typename: 'PathItem',
}
const alert = window.alert = jest.fn()
beforeEach(() => {
window.documents = [document]
window.selection = [path]
jest.resetModules()
})
it('should alert if no document is open or no item is selected', () => {
window.documents = []
window.selection = []
require('./reverse-path')
expect(alert).toHaveBeenCalledWith('Select item(s) to reverse', 'Error')
})
it('should alert if a selected item type is not supported', () => {
const item = { typename: 'unknown' }
window.selection = [item]
require('./reverse-path')
expect(alert).toHaveBeenCalledWith('Unsupported item of type unknown', 'Error')
})
it('should reverse selected path', () => {
const from = {
anchor: [0, 0],
leftDirection: [-5, 5],
pointType: PointType.SMOOTH,
rightDirection: [5, -5],
}
const to = {
anchor: [10, 0],
leftDirection: [5, -5],
pointType: PointType.SMOOTH,
rightDirection: [15, 5],
}
path.selectedPathPoints = [from, to]
require('./reverse-path')
expect(path.selectedPathPoints).toEqual([
{
anchor: [10, 0],
leftDirection: [15, 5],
pointType: PointType.SMOOTH,
rightDirection: [5, -5],
},
{
anchor: [0, 0],
leftDirection: [5, -5],
pointType: PointType.SMOOTH,
rightDirection: [-5, 5],
},
])
})