-
-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathgetPostMessageStream.test.ts
More file actions
96 lines (86 loc) · 3.1 KB
/
Copy pathgetPostMessageStream.test.ts
File metadata and controls
96 lines (86 loc) · 3.1 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
import { ProviderConstants } from '../constants';
import { RemoteConnection } from '../services/RemoteConnection';
import { getPostMessageStream } from './getPostMessageStream';
import { RemoteCommunicationPostMessageStream } from './RemoteCommunicationPostMessageStream';
jest.mock('../services/RemoteConnection');
jest.mock('./RemoteCommunicationPostMessageStream');
describe('getPostMessageStream', () => {
const mockRemoteConnection = RemoteConnection as jest.MockedClass<
typeof RemoteConnection
>;
const mockPostMessageStream =
RemoteCommunicationPostMessageStream as jest.MockedClass<
typeof RemoteCommunicationPostMessageStream
>;
beforeEach(() => {
jest.clearAllMocks();
});
it('should throw an error if remoteConnection is missing', () => {
expect(() =>
getPostMessageStream({
name: ProviderConstants.CONTENT_SCRIPT,
remoteConnection: undefined,
debug: false,
} as any),
).toThrow('Missing remote connection parameter');
});
it('should return a new RemoteCommunicationPostMessageStream if all parameters are present', () => {
const fakeConnector = {};
const fakePlatformManager = {};
mockRemoteConnection.mockImplementation(
() =>
({
getConnector: jest.fn().mockReturnValue(fakeConnector),
getPlatformManager: jest.fn().mockReturnValue(fakePlatformManager),
state: {
deeplinkProtocol: false,
},
} as any),
);
const result = getPostMessageStream({
name: ProviderConstants.CONTENT_SCRIPT,
remoteConnection: new RemoteConnection({
getConnector: jest.fn().mockReturnValue(fakeConnector),
} as any),
debug: false,
} as any);
expect(result).toBeInstanceOf(RemoteCommunicationPostMessageStream);
expect(mockPostMessageStream).toHaveBeenCalledWith({
name: ProviderConstants.CONTENT_SCRIPT,
remote: fakeConnector,
deeplinkProtocol: false,
platformManager: fakePlatformManager,
});
});
it('should pass hideReturnToAppNotification from remoteConnection state', () => {
const fakeConnector = {};
const fakePlatformManager = {};
const hideReturnToAppNotification = true;
mockRemoteConnection.mockImplementation(
() =>
({
getConnector: jest.fn().mockReturnValue(fakeConnector),
getPlatformManager: jest.fn().mockReturnValue(fakePlatformManager),
state: {
deeplinkProtocol: false,
hideReturnToAppNotification,
},
} as any),
);
const result = getPostMessageStream({
name: ProviderConstants.CONTENT_SCRIPT,
remoteConnection: new RemoteConnection({
getConnector: jest.fn().mockReturnValue(fakeConnector),
} as any),
debug: false,
} as any);
expect(result).toBeInstanceOf(RemoteCommunicationPostMessageStream);
expect(mockPostMessageStream).toHaveBeenCalledWith({
name: ProviderConstants.CONTENT_SCRIPT,
remote: fakeConnector,
deeplinkProtocol: false,
platformManager: fakePlatformManager,
hideReturnToAppNotification,
});
});
});