-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
rectangle.test.js
79 lines (69 loc) · 1.98 KB
/
rectangle.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
69
70
71
72
73
74
75
76
77
78
79
import test from "ava";
import Rectangle from "./rectangle.js";
test.beforeEach((t) => {
t.context = new Rectangle([-20, 20], 123, 22, {
origin: Rectangle.origins.center,
});
});
test("constructor", (t) => {
t.is(t.context.width, 123);
t.is(t.context.height, 22);
t.is(t.context.options.origin, Rectangle.origins.center);
const defaultRectangle = new Rectangle();
t.is(defaultRectangle.width, 0);
t.is(defaultRectangle.height, 0);
});
test("trace", (t) => {
const path = {
rect: (...params) => {
t.deepEqual(params, [0, 0, 123, 22]);
},
};
t.plan(1);
t.context.trace(path);
});
test("trace rounded", (t) => {
t.context.options.rounded = 11;
const path = {
roundRect: (...params) => {
t.deepEqual(params, [0, 0, 123, 22, 11]);
},
};
t.plan(1);
t.context.trace(path);
});
test("getOrigin", (t) => {
const { origins } = Rectangle;
const expected = {
[origins.topLeft]: [0, 0],
[origins.topCenter]: [-123 / 2, 0],
[origins.topRight]: [-123, 0],
[origins.centerLeft]: [0, -22 / 2],
[origins.center]: [-123 / 2, -22 / 2],
[origins.centerRight]: [-123, -22 / 2],
[origins.bottomLeft]: [0, -22],
[origins.bottomCenter]: [-123 / 2, -22],
[origins.bottomRight]: [-123, -22],
};
Object.keys(expected).forEach((origin) => {
t.context.options.origin = origin;
const defaultOrigin = t.context.getOrigin();
t.is(defaultOrigin.x, expected[origin][0]);
t.is(defaultOrigin.y, expected[origin][1]);
});
});
test("toJSON", (t) => {
const json = t.context.toJSON();
t.is(json.width, 123);
t.is(json.height, 22);
t.is(json.constructor, "Rectangle");
});
test("from", (t) => {
const definition = {
width: 42,
height: 666,
};
const rectangle = Rectangle.from(definition);
t.is(rectangle.width, 42);
t.is(rectangle.height, 666);
});