-
Notifications
You must be signed in to change notification settings - Fork 168
Expand file tree
/
Copy pathintents.steps.ts
More file actions
203 lines (185 loc) · 5.23 KB
/
intents.steps.ts
File metadata and controls
203 lines (185 loc) · 5.23 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { Given } from '@cucumber/cucumber';
import { CustomWorld } from '../world/index';
import { handleResolve } from '@finos/fdc3-testing';
import { Context } from '@finos/fdc3-context';
import { ContextMetadata, ResolveError } from '@finos/fdc3-standard';
import { IntentEvent } from '@finos/fdc3-schema/dist/generated/api/BrowserTypes';
Given('app {string}', function (this: CustomWorld, appStr: string) {
const [appId, instanceId] = appStr.split('/');
const app = { appId, instanceId };
this.messaging?.addAppIntentDetail({
app,
});
this.props[instanceId] = app;
});
Given('app {string} resolves intent {string}', function (this: CustomWorld, appStr: string, intent: string) {
const [appId, instanceId] = appStr.split('/');
const app = { appId, instanceId };
this.messaging?.addAppIntentDetail({
app,
intent,
});
this.props[instanceId] = app;
this.props[appId] = {
appId,
};
});
Given(
'app {string} resolves intent {string} with result type {string}',
function (this: CustomWorld, appStr: string, intent: string, resultType: string) {
const [appId, instanceId] = appStr.split('/');
const app = { appId, instanceId };
this.messaging?.addAppIntentDetail({
app,
intent,
resultType,
});
this.props[instanceId] = app;
this.props[appId] = {
appId,
};
}
);
Given(
'app {string} resolves intent {string} with context {string}',
function (this: CustomWorld, appStr: string, intent: string, context: string) {
const [appId, instanceId] = appStr.split('/');
const app = { appId, instanceId };
this.messaging?.addAppIntentDetail({
app,
intent,
context,
});
this.props[instanceId] = app;
this.props[appId] = {
appId,
};
}
);
Given(
'app {string} resolves intent {string} with context {string} and result type {string}',
function (this: CustomWorld, appStr: string, intent: string, context: string, resultType: string) {
const [appId, instanceId] = appStr.split('/');
const app = { appId, instanceId };
this.messaging?.addAppIntentDetail({
app,
intent,
context,
resultType,
});
this.props[instanceId] = app;
}
);
Given('Raise Intent returns a context of {string}', function (this: CustomWorld, result: string) {
this.messaging?.setIntentResult({
context: handleResolve(result, this),
});
});
Given('Raise Intent will throw a {string} error', function (this: CustomWorld, error: ResolveError) {
this.messaging?.setIntentResult({
error,
});
});
Given('Raise Intent returns no result', function (this: CustomWorld) {
this.messaging?.setIntentResult({});
});
Given('Raise Intent times out', function (this: CustomWorld) {
this.messaging?.setIntentResult({
timeout: true,
});
});
Given('Raise Intent returns an app channel', function (this: CustomWorld) {
this.messaging?.setIntentResult({
channel: {
type: 'app',
id: 'result-channel',
displayMetadata: {
color: 'purple',
name: 'Result Channel',
},
},
});
});
Given('Raise Intent returns a user channel', function (this: CustomWorld) {
this.messaging?.setIntentResult({
channel: {
type: 'user',
id: 'result-channel',
displayMetadata: {
color: 'purple',
name: 'Result Channel',
},
},
});
});
Given('Raise Intent returns a private channel', function (this: CustomWorld) {
this.messaging?.setIntentResult({
channel: {
type: 'private',
id: 'result-channel',
displayMetadata: {
color: 'purple',
name: 'Result Channel',
},
},
});
});
Given(
'{string} is a intentEvent message with intent {string} and context {string}',
function (this: CustomWorld, field: string, intent: string, context: string) {
const msg: IntentEvent = {
type: 'intentEvent',
meta: {
eventUuid: this.messaging!.createUUID(),
timestamp: new Date(),
},
payload: {
originatingApp: {
appId: 'some-app-id',
desktopAgent: 'some-desktop-agent',
},
context: handleResolve(context, this),
intent,
raiseIntentRequestUuid: 'request-id',
},
};
this.props[field] = msg;
}
);
Given('{string} pipes intent to {string}', function (this: CustomWorld, intentHandlerName: string, field: string) {
this.props[field] = [];
this.props[intentHandlerName] = (context: Context, metadata: ContextMetadata) => {
this.props[field].push({
context,
metadata,
});
};
});
Given('{string} returns a context item', function (this: CustomWorld, intentHandlerName: string) {
this.props[intentHandlerName] = async () => {
return {
type: 'fdc3.returned-intent',
id: {
in: 'one',
out: 'two',
},
};
};
});
Given('{string} returns a channel', function (this: CustomWorld, intentHandlerName: string) {
this.props[intentHandlerName] = async () => {
return {
type: 'private',
id: 'some-channel-id',
displayMetadata: {
color: 'ochre',
name: 'Some Channel',
},
};
};
});
Given('{string} returns a void promise', function (this: CustomWorld, intentHandlerName: string) {
this.props[intentHandlerName] = async () => {
return null;
};
});