-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.test.js
123 lines (93 loc) · 2.16 KB
/
events.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
require = require("esm")(module);
const fs = require("fs");
const path = require("path");
const mock = require("./mocks.mjs");
const Ulysses = require("../src/main.mjs").default;
const fires = JSON.parse(
fs.readFileSync(path.resolve(__dirname, "../docs/examples/data/fires-2018.json"))
);
let story;
let map;
beforeEach(() => {
map = new mock.Map();
story = new Ulysses({ map, steps: fires });
});
describe("tests for events", () => {
test("register a listener", () => {
story.on("step", e => {});
});
test("listen for a step", () => {
story.on("step", e => {
expect(e.step).toBe(1);
expect(e.feature).toBe(fires.features[1]);
});
story.step(1);
expect(story.current).toBe(1);
});
test("listen for next", () => {
story.on("next", e => {
expect(e.step).toBe(-1);
expect(e.feature).toBe(undefined);
});
story.next();
expect(story.current).toBe(0);
});
test("listen for previous", () => {
story.step(3);
expect(story.current).toBe(3);
story.on("previous", e => {
expect(e.step).toBe(3);
expect(e.feature).toBe(fires.features[3]);
});
story.previous();
expect(story.current).toBe(2);
});
test("listen for start", () => {
let started = false;
story.on("start", e => {
started = true;
});
story.next();
expect(started).toBe(true);
});
test("listen for start on step 0", () => {
let started = false;
story.on("start", e => {
started = true;
});
story.step(0);
expect(started).toBe(true);
});
test("only start once", () => {
let count = 0;
story.on("start", e => {
count++;
});
story.next();
expect(count).toBe(1);
});
test("listen for end", () => {
let ended = false;
story.on("end", e => {
ended = true;
});
story.step(story.length - 1);
expect(ended).toBe(true);
});
test("listen for destroy", () => {
let destroyed = false;
story.on("destroy", () => {
destroyed = true;
});
story.destroy();
expect(destroyed).toBe(true);
});
test("create and listen for a custom event", () => {
let success = false;
story.on("success", e => {
success = e.success;
});
story.trigger("success", { success: true });
expect(success).toBe(true);
});
});