aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugin-pubusb.spec.ts
diff options
context:
space:
mode:
authorIdan Amit <idan.amit@intl.att.com>2019-01-03 18:18:37 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-01-06 09:18:00 +0000
commitbbeb590aaff56ff3364b852f6149b220581b58a1 (patch)
treec775c17faead68b8b7658516715a41a88476031c /src/plugin-pubusb.spec.ts
parent3cd900684dc33d5ca07e977df724a0c179a91fa9 (diff)
Fixed minor issues in sdc-pubusb
Change-Id: I9d667fbb1740376e686824335f2dbae242f8d00c Issue-ID: SDC-2032 Signed-off-by: Idan Amit <idan.amit@intl.att.com>
Diffstat (limited to 'src/plugin-pubusb.spec.ts')
-rw-r--r--src/plugin-pubusb.spec.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/plugin-pubusb.spec.ts b/src/plugin-pubusb.spec.ts
new file mode 100644
index 0000000..1eb6eda
--- /dev/null
+++ b/src/plugin-pubusb.spec.ts
@@ -0,0 +1,53 @@
+import {PluginPubSub} from './plugin-pubsub';
+
+declare const window: Window;
+
+describe('BasePubSub Tests', () => {
+ let pluginPubSub: PluginPubSub;
+
+ let testSub: string = 'testSub';
+ let testParentUrl: string = 'http://127.0.0.1';
+ let testEventsToWait: Array<string> = ['CHECK_IN', 'WINDOW_OUT'];
+
+ beforeEach(() => {
+ pluginPubSub = new PluginPubSub(testSub, testParentUrl, testEventsToWait);
+ });
+
+ describe('constructor tests', () => {
+ it('should init class property', () => {
+ expect(pluginPubSub.subscribers.size).toBe(1);
+ expect(pluginPubSub.eventsCallbacks.length).toBe(0);
+ expect(pluginPubSub.eventsToWait.size).toBe(0);
+ expect(pluginPubSub.clientId).toBe('testSub');
+ });
+ });
+
+ describe('subscribe function tests', () => {
+ it('should call notify function with the PLUGIN_REGISTER event and the register data', () => {
+ pluginPubSub.notify = jest.fn();
+
+ let wantedRegisterData = {
+ pluginId: testSub,
+ eventsToWait: []
+ };
+
+ pluginPubSub.subscribe();
+
+ expect(pluginPubSub.notify).toHaveBeenCalledWith('PLUGIN_REGISTER', wantedRegisterData);
+ })
+ });
+
+ describe('unsubscribe function tests', () => {
+ it('should call notify function with the PLUGIN_UNREGISTER event and the unregister data', () => {
+ pluginPubSub.notify = jest.fn();
+
+ let wantedUnregisterData = {
+ pluginId: testSub,
+ };
+
+ pluginPubSub.unsubscribe();
+
+ expect(pluginPubSub.notify).toHaveBeenCalledWith('PLUGIN_UNREGISTER', wantedUnregisterData);
+ })
+ });
+}); \ No newline at end of file