-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathselect.test.js
72 lines (57 loc) · 1.84 KB
/
select.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
import test from "ava";
import MouseEvent from "@pencil.js/mouse-event";
import Select from "./select.js";
test.beforeEach((t) => {
t.context = new Select([0, 0], [
undefined, "B", "C",
], {
value: 1,
});
});
test("constructor", (t) => {
t.is(t.context.optionsList.length, 3);
t.context.optionsList.forEach(option => t.is(option.constructor.name, "Text"));
t.false(t.context.optionsContainer.options.shown);
t.throws(() => new Select([0, 0], []));
});
test("option events", (t) => {
t.context.value = 1;
const firstOption = t.context.optionsList[0];
firstOption.fire(new MouseEvent(MouseEvent.events.click, firstOption));
t.is(t.context.value, 0);
firstOption.fire(new MouseEvent(MouseEvent.events.hover, firstOption));
t.is(firstOption.parent.options.fill, t.context.options.hover);
firstOption.fire(new MouseEvent(MouseEvent.events.leave, firstOption));
t.is(firstOption.parent.options.fill, t.context.options.fill);
});
test("get and set value", (t) => {
t.context.value = 5;
t.is(t.context.value, 2);
t.is(t.context.display.text, "C");
});
test("click", (t) => {
t.context.click();
t.true(t.context.optionsContainer.options.shown);
t.context.optionsContainer.hide();
t.context.display.fire(new MouseEvent(MouseEvent.events.click, t.context.display));
t.true(t.context.optionsContainer.options.shown);
});
test("toJSON", (t) => {
const json = t.context.toJSON();
t.deepEqual(json.values, ["", "B", "C"]);
});
test("from", (t) => {
const definition = {
position: [1, 2],
values: ["1", "2", "3"],
options: {
value: 1,
},
};
const select = Select.from(definition);
t.is(select.optionsList.length, 3);
t.is(select.options.value, 1);
});
test("MARGIN", (t) => {
t.is(Select.MARGIN, 0.2);
});