Skip to content

Commit 670dc0d

Browse files
committed
add dragelment getCursor and align tests
1 parent 06565e0 commit 670dc0d

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
var dragElement = require('@src/components/dragelement');
2+
3+
4+
describe('dragElement.getCursor', function() {
5+
'use strict';
6+
7+
var getCursor = dragElement.getCursor;
8+
9+
it('should return sw-resize when x < 1/3, y < 1/3', function() {
10+
var cursor = getCursor(0.2, 0);
11+
expect(cursor).toEqual('sw-resize');
12+
13+
cursor = getCursor(1, 0, 'left');
14+
expect(cursor).toEqual('sw-resize', 'with left xanchor');
15+
16+
cursor = getCursor(0.3, 1, null, 'bottom');
17+
expect(cursor).toEqual('sw-resize', 'with bottom yanchor');
18+
});
19+
20+
it('should return s-resize when 1/3 < x < 2/3, y < 1/3', function() {
21+
var cursor = getCursor(0.4, 0.3);
22+
expect(cursor).toEqual('s-resize');
23+
24+
cursor = getCursor(0, 0, 'center');
25+
expect(cursor).toEqual('s-resize', 'with center xanchor');
26+
27+
cursor = getCursor(0.63, 1, null, 'bottom');
28+
expect(cursor).toEqual('s-resize', 'with bottom yanchor');
29+
});
30+
31+
it('should return se-resize when x > 2/3, y < 1/3', function() {
32+
var cursor = getCursor(0.9, 0.1);
33+
expect(cursor).toEqual('se-resize');
34+
35+
cursor = getCursor(0, 0, 'right');
36+
expect(cursor).toEqual('se-resize', 'with right xanchor');
37+
38+
cursor = getCursor(0.63, 1, null, 'bottom');
39+
expect(cursor).toEqual('s-resize', 'with bottom yanchor');
40+
});
41+
42+
it('should return w-resize when x < 1/3, 1/3 < y < 2/3', function() {
43+
var cursor = getCursor(0.1, 0.4);
44+
expect(cursor).toEqual('w-resize');
45+
46+
cursor = getCursor(0.9, 0.5, 'left');
47+
expect(cursor).toEqual('w-resize', 'with left xanchor');
48+
49+
cursor = getCursor(0.1, 0.1, null, 'middle');
50+
expect(cursor).toEqual('w-resize', 'with middle yanchor');
51+
});
52+
53+
it('should return move when 1/3 < x < 2/3, 1/3 < y < 2/3', function() {
54+
var cursor = getCursor(0.4, 0.4);
55+
expect(cursor).toEqual('move');
56+
57+
cursor = getCursor(0.9, 0.5, 'center');
58+
expect(cursor).toEqual('move', 'with center xanchor');
59+
60+
cursor = getCursor(0.4, 0.1, null, 'middle');
61+
expect(cursor).toEqual('move', 'with middle yanchor');
62+
});
63+
64+
it('should return e-resize when x > 1/3, 1/3 < y < 2/3', function() {
65+
var cursor = getCursor(0.8, 0.4);
66+
expect(cursor).toEqual('e-resize');
67+
68+
cursor = getCursor(0.09, 0.5, 'right');
69+
expect(cursor).toEqual('e-resize', 'with right xanchor');
70+
71+
cursor = getCursor(0.9, 0.1, null, 'middle');
72+
expect(cursor).toEqual('e-resize', 'with middle yanchor');
73+
});
74+
75+
it('should return nw-resize when x > 1/3, y > 2/3', function() {
76+
var cursor = getCursor(0.2, 0.7);
77+
expect(cursor).toEqual('nw-resize');
78+
79+
cursor = getCursor(0.9, 0.9, 'left');
80+
expect(cursor).toEqual('nw-resize', 'with left xanchor');
81+
82+
cursor = getCursor(0.1, 0.1, null, 'top');
83+
expect(cursor).toEqual('nw-resize', 'with top yanchor');
84+
});
85+
86+
it('should return nw-resize when 1/3 < x < 2/3, y > 2/3', function() {
87+
var cursor = getCursor(0.4, 0.7);
88+
expect(cursor).toEqual('n-resize');
89+
90+
cursor = getCursor(0.9, 0.9, 'center');
91+
expect(cursor).toEqual('n-resize', 'with center xanchor');
92+
93+
cursor = getCursor(0.5, 0.1, null, 'top');
94+
expect(cursor).toEqual('n-resize', 'with top yanchor');
95+
});
96+
97+
it('should return nw-resize when x > 2/3, y > 2/3', function() {
98+
var cursor = getCursor(0.7, 0.7);
99+
expect(cursor).toEqual('ne-resize');
100+
101+
cursor = getCursor(0.09, 0.9, 'right');
102+
expect(cursor).toEqual('ne-resize', 'with right xanchor');
103+
104+
cursor = getCursor(0.8, 0.1, null, 'top');
105+
expect(cursor).toEqual('ne-resize', 'with top yanchor');
106+
});
107+
});
108+
109+
describe('dragElement.align', function() {
110+
'use strict';
111+
112+
var align = dragElement.align;
113+
114+
it('should return min value if anchor is set to \'bottom\' or \'left\'', function() {
115+
var al = align(0, 1, 0, 1, 'bottom');
116+
expect(al).toEqual(0);
117+
118+
al = align(0, 1, 0, 1, 'left');
119+
expect(al).toEqual(0);
120+
});
121+
122+
it('should return max value if anchor is set to \'top\' or \'right\'', function() {
123+
var al = align(0, 1, 0, 1, 'top');
124+
expect(al).toEqual(1);
125+
126+
al = align(0, 1, 0, 1, 'right');
127+
expect(al).toEqual(1);
128+
});
129+
130+
it('should return center value if anchor is set to \'middle\' or \'center\'', function() {
131+
var al = align(0, 1, 0, 1, 'middle');
132+
expect(al).toEqual(0.5);
133+
134+
al = align(0, 1, 0, 1, 'center');
135+
expect(al).toEqual(0.5);
136+
});
137+
138+
it('should return center value if anchor is set to \'middle\' or \'center\'', function() {
139+
var al = align(0, 1, 0, 1, 'middle');
140+
expect(al).toEqual(0.5);
141+
142+
al = align(0, 1, 0, 1, 'center');
143+
expect(al).toEqual(0.5);
144+
});
145+
146+
it('should return min value ', function() {
147+
var al = align(0, 1, 0, 1);
148+
expect(al).toEqual(0);
149+
});
150+
151+
it('should return max value ', function() {
152+
var al = align(1, 1, 0, 1);
153+
expect(al).toEqual(2);
154+
});
155+
});

0 commit comments

Comments
 (0)