Repository navigation
Expand file tree
/
Copy pathaction_test.ts
More file actions
99 lines (91 loc) · 3.7 KB
/
Copy pathaction_test.ts
File metadata and controls
99 lines (91 loc) · 3.7 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
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
import { assertEquals } from "@std/assert";
import { type AssertTrue, assertType, type IsExact } from "@std/testing/types";
import { DenopsStub } from "@denops/test/stub";
import type { DetailUnit } from "./item.ts";
import {
type Action,
composeActions,
defineAction,
type InvokeParams,
} from "./action.ts";
Deno.test("defineAction", async (t) => {
await t.step("without type contraint", () => {
const action = defineAction((_denops, params) => {
type _ = AssertTrue<IsExact<typeof params, InvokeParams<DetailUnit>>>;
});
assertType<IsExact<typeof action, Action<DetailUnit>>>(true);
});
await t.step("with type contraint", () => {
type C = { a: string };
const action = defineAction<C>((_denops, params) => {
type _ = AssertTrue<IsExact<typeof params, InvokeParams<C>>>;
});
assertType<IsExact<typeof action, Action<C>>>(true);
});
});
Deno.test("composeActions", async (t) => {
await t.step("with bear actions", async (t) => {
await t.step("actions are invoked in order", async () => {
const results: string[] = [];
const action1 = defineAction(() => void results.push("action1"));
const action2 = defineAction(() => void results.push("action2"));
const action3 = defineAction(() => void results.push("action3"));
const action = composeActions(action2, action1, action3);
const denops = new DenopsStub();
const params = {
item: undefined,
selectedItems: [],
filteredItems: [],
};
await action.invoke(denops, params, {});
assertEquals(results, ["action2", "action1", "action3"]);
});
await t.step("without type contraint", () => {
const action1 = defineAction(() => {});
const action2 = defineAction(() => {});
const action3 = defineAction(() => {});
const action = composeActions(action2, action1, action3);
assertType<IsExact<typeof action, Action<DetailUnit>>>(true);
});
await t.step("with type contraint", () => {
type C = { a: string };
const action1 = defineAction<C>(() => {});
const action2 = defineAction<C>(() => {});
const action3 = defineAction<C>(() => {});
const action = composeActions(action2, action1, action3);
assertType<IsExact<typeof action, Action<C>>>(true);
});
});
await t.step("with derivable actions", async (t) => {
await t.step("actions are invoked in order", async () => {
const results: string[] = [];
const action1 = () => defineAction(() => void results.push("action1"));
const action2 = () => defineAction(() => void results.push("action2"));
const action3 = () => defineAction(() => void results.push("action3"));
const action = composeActions(action2, action1, action3);
const denops = new DenopsStub();
const params = {
item: undefined,
selectedItems: [],
filteredItems: [],
};
await action.invoke(denops, params, {});
assertEquals(results, ["action2", "action1", "action3"]);
});
await t.step("without type contraint", () => {
const action1 = () => defineAction(() => {});
const action2 = () => defineAction(() => {});
const action3 = () => defineAction(() => {});
const action = composeActions(action2, action1, action3);
assertType<IsExact<typeof action, Action<DetailUnit>>>(true);
});
await t.step("with type contraint", () => {
type C = { a: string };
const action1 = () => defineAction<C>(() => {});
const action2 = () => defineAction<C>(() => {});
const action3 = () => defineAction<C>(() => {});
const action = composeActions(action2, action1, action3);
assertType<IsExact<typeof action, Action<C>>>(true);
});
});
});