-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathmodal.test.js
More file actions
61 lines (54 loc) · 1.67 KB
/
modal.test.js
File metadata and controls
61 lines (54 loc) · 1.67 KB
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
import flushPromises from "flush-promises";
import { collectionCreatorModalSetup } from "./modal";
jest.mock("app");
describe("modal.js", () => {
let showOptions = null;
let hidden = false;
const mockApp = {
modal: {
show(showOptions_) {
showOptions = showOptions_;
},
hide() {
hidden = true;
},
},
};
let options;
let showEl;
let resolution;
let rejected;
describe("collectionCreatorModalSetup", () => {
beforeEach(() => {
hidden = false;
rejected = false;
const object = collectionCreatorModalSetup({}, mockApp);
options = object.options;
showEl = object.showEl;
object.promise
.catch((rejection_) => {
rejected = true;
})
.then((resolution_) => {
resolution = resolution_;
});
});
it("should create showEl and resolve oncreate", async () => {
expect(showOptions).toBe(null);
showEl();
expect(showOptions.title).toContain("Create a collection");
expect(hidden).toBeFalsy();
options.oncreate(null, "testres");
await flushPromises();
expect(resolution).toEqual("testres");
expect(hidden).toBeTruthy();
});
it("should hide oncancel", async () => {
expect(hidden).toBeFalsy();
options.oncancel();
await flushPromises();
expect(hidden).toBeTruthy();
expect(rejected).toBeTruthy();
});
});
});