-
Notifications
You must be signed in to change notification settings - Fork 14
/
fdc3.raiseIntent.ts
170 lines (154 loc) · 5.4 KB
/
fdc3.raiseIntent.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
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
import { Context, raiseIntent, ResolveError } from "@finos/fdc3";
import { assert, expect } from "chai";
import APIDocumentation from "../apiDocuments";
// creates a channel and subscribes for broadcast contexts. This is
// used by the 'mock app' to send messages back to the test runner for validation
const createReceiver = (contextType: string) => {
const messageReceived = new Promise<Context>(async (resolve) => {
const listener = await window.fdc3.addContextListener(
contextType,
(context) => {
resolve(context);
listener.unsubscribe();
}
);
});
return messageReceived;
};
const raiseIntentDocs =
"\r\nDocumentation: " + APIDocumentation.raiseIntent + "\r\nCause";
/**
* Details on the mock apps used in these tests can be found in /mock/README.md
*/
export default () =>
describe("fdc3.raiseIntent", () => {
before(async () => {
await window.fdc3.getOrCreateChannel("fdc3.raiseIntent");
await window.fdc3.joinChannel("fdc3.raiseIntent");
});
const broadcastCloseWindow = async () => {
await window.fdc3.broadcast({ type: "closeWindow" });
return new Promise<void>((resolve) => setTimeout(() => resolve(), 1000)); // Wait until close window event is handled
};
beforeEach(async () => {
await broadcastCloseWindow();
});
afterEach(async () => {
await broadcastCloseWindow();
});
it("Should start app intent-b when raising intent 'sharedTestingIntent1' with context 'testContextY'", async () => {
const result = createReceiver("fdc3-intent-b-opened");
const intentResolution = await window.fdc3.raiseIntent(
"sharedTestingIntent1",
{
type: "testContextY",
}
);
expect(intentResolution.source).to.eq("IntentAppBId", raiseIntentDocs);
await result;
});
it("Should start app intent-a when targeted by raising intent 'aTestingIntent' with context 'testContextX'", async () => {
const result = createReceiver("fdc3-intent-a-opened");
const intentResolution = await window.fdc3.raiseIntent(
"aTestingIntent",
{
type: "testContextX",
},
"IntentAppA"
);
expect(intentResolution.source).to.eq("IntentAppAId", raiseIntentDocs);
await result;
});
it("Should start app intent-a when targeted (name and appId) by raising intent 'aTestingIntent' with context 'testContextX'", async () => {
const result = createReceiver("fdc3-intent-a-opened");
const intentResolution = await window.fdc3.raiseIntent(
"aTestingIntent",
{
type: "testContextX",
},
{ name: "IntentAppA", appId: "IntentAppAId" }
);
expect(intentResolution.source).to.eq("IntentAppAId", raiseIntentDocs);
await result;
});
it("Should start app intent-a when targeted (name) by raising intent 'aTestingIntent' with context 'testContextX'", async () => {
const result = createReceiver("fdc3-intent-a-opened");
const intentResolution = await window.fdc3.raiseIntent(
"aTestingIntent",
{
type: "testContextX",
},
{ name: "IntentAppA" }
);
expect(intentResolution.source).to.eq("IntentAppAId", raiseIntentDocs);
await result;
});
it("Should fail to raise intent when targeted app intent-a, context 'testContextY' and intent 'aTestingIntent' do not correlate", async () => {
try {
await window.fdc3.raiseIntent(
"aTestingIntent",
{
type: "testContextY",
},
"IntentAppA"
);
assert.fail("Error was not thrown");
} catch (ex) {
expect(ex).to.have.property("message", ResolveError.NoAppsFound);
}
});
it("Should fail to raise intent when targeted app intent-a (name and appId), context 'testContextY' and intent 'aTestingIntent' do not correlate", async () => {
try {
await window.fdc3.raiseIntent(
"aTestingIntent",
{
type: "testContextY",
},
{ name: "IntentAppA", appId: "IntentAppAId" }
);
assert.fail("Error was not thrown", raiseIntentDocs);
} catch (ex) {
expect(ex).to.have.property(
"message",
ResolveError.NoAppsFound,
raiseIntentDocs
);
}
});
it("Should fail to raise intent when targeted app intent-a (name), context 'testContextY' and intent 'aTestingIntent' do not correlate", async () => {
try {
await window.fdc3.raiseIntent(
"aTestingIntent",
{
type: "testContextY",
},
{ name: "IntentAppA" }
);
assert.fail("Error was not thrown", raiseIntentDocs);
} catch (ex) {
expect(ex).to.have.property(
"message",
ResolveError.NoAppsFound,
raiseIntentDocs
);
}
});
it("Should fail to raise intent when targeted app intent-c, context 'testContextX' and intent 'aTestingIntent' do not correlate", async () => {
try {
await window.fdc3.raiseIntent(
"aTestingIntent",
{
type: "testContextX",
},
"IntentAppC"
);
assert.fail("Error was not thrown", raiseIntentDocs);
} catch (ex) {
expect(ex).to.have.property(
"message",
ResolveError.NoAppsFound,
raiseIntentDocs
);
}
});
});