-
Notifications
You must be signed in to change notification settings - Fork 14
/
fdc3.open.ts
109 lines (86 loc) · 3.65 KB
/
fdc3.open.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
import { OpenError, Context } from "@finos/fdc3";
import { assert, expect } from "chai";
import APIDocumentation from "../apiDocuments";
const appBName = "MockApp";
const appBId = "MockAppId";
// 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) => {
await window.fdc3.getOrCreateChannel("FDC3-Conformance-Channel");
await window.fdc3.joinChannel("FDC3-Conformance-Channel");
const listener = await window.fdc3.addContextListener(
contextType,
(context) => {
resolve(context);
listener.unsubscribe();
}
);
});
return messageReceived;
};
const openDocs = "\r\nDocumentation: " + APIDocumentation.open + "\r\nCause";
/**
* Details on the mock apps used in these tests can be found in /mock/README.md
*/
export default () =>
describe("fdc3.open", () => {
it("Can open app B from app A with no context and string as target", async () => {
const result = createReceiver("fdc3-conformance-opened");
await window.fdc3.open(appBName);
await result;
});
it("Can open app B from app A with no context and AppMetadata (name) as target", async () => {
const result = createReceiver("fdc3-conformance-opened");
await window.fdc3.open({ name: appBName });
await result;
});
it("Can open app B from app A with no context and AppMetadata (name and appId) as target", async () => {
const result = createReceiver("fdc3-conformance-opened");
await window.fdc3.open({ name: appBName, appId: appBId });
await result;
});
it("Receive AppNotFound error when targeting non-existent app name as target", async () => {
try {
await window.fdc3.open("ThisAppDoesNotExist");
assert.fail("No error was not thrown", openDocs);
} catch (ex) {
expect(ex).to.have.property("message", OpenError.AppNotFound, openDocs);
}
});
it("Receive AppNotFound error when targeting non-existent app AppMetadata (name) as target", async () => {
try {
await window.fdc3.open({ name: "ThisAppDoesNotExist" });
assert.fail("No error was not thrown", openDocs);
} catch (ex) {
expect(ex).to.have.property("message", OpenError.AppNotFound, openDocs);
}
});
it("Receive AppNotFound error when targeting non-existent app AppMetadata (name and appId) as target", async () => {
try {
await window.fdc3.open({
name: "ThisAppDoesNotExist",
appId: "ThisAppDoesNotExist",
});
assert.fail("No error was not thrown", openDocs);
} catch (ex) {
expect(ex).to.have.property("message", OpenError.AppNotFound, openDocs);
}
});
it("Can open app B from app A with context and AppMetadata (name) as target", async () => {
const receiver = createReceiver("fdc3-conformance-context-received");
await window.fdc3.open(
{ name: appBName },
{ name: "context", type: "fdc3.testReceiver" }
);
const receivedValue = (await receiver) as any;
expect(receivedValue.context.name).to.eq("context", openDocs);
expect(receivedValue.context.type).to.eq("fdc3.testReceiver", openDocs);
});
it("Can open app B from app A with invalid context and AppMetadata (name) as target", async () => {
const receiver = createReceiver("fdc3-conformance-context-received");
const malformedContext = {} as any;
await window.fdc3.open({ name: appBName }, malformedContext);
await receiver;
});
});