-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathavailableActions.ts
73 lines (68 loc) · 1.42 KB
/
availableActions.ts
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
const commonActions = [
{
name: "wait",
description:
"Wait for 3 seconds before the next action. Useful when the page is loading.",
args: [],
},
{
name: "finish",
description: "Indicate the task is finished",
args: [],
},
{
name: "fail",
description: "Indicate that you are unable to complete the task",
args: [],
},
] as const;
export const availableActions = [
{
name: "click",
description: "Click on an element",
args: [
{
name: "elementId",
type: "string",
},
],
},
{
name: "setValue",
description: "Focus on and sets the value of an input element",
args: [
{
name: "elementId",
type: "string",
},
{
name: "value",
type: "string",
},
],
},
...commonActions,
] as const;
type AvailableAction = (typeof availableActions)[number];
type ArgsToObject<T extends ReadonlyArray<{ name: string; type: string }>> = {
[K in T[number]["name"]]: Extract<
T[number],
{ name: K }
>["type"] extends "number"
? number
: string;
};
export type ActionShape<
T extends {
name: string;
args: ReadonlyArray<{ name: string; type: string }>;
},
> = {
name: T["name"];
args: ArgsToObject<T["args"]>;
};
export type ActionPayload = {
[K in AvailableAction["name"]]: ActionShape<
Extract<AvailableAction, { name: K }>
>;
}[AvailableAction["name"]];