Fix Build
[sdc/sdc-pubsub.git] / src / plugin-pubusb.spec.ts
1 import {PluginPubSub} from './plugin-pubsub';
2
3 declare const window: Window;
4
5 describe('BasePubSub Tests', () => {
6     let pluginPubSub: PluginPubSub;
7
8     let testSub: string = 'testSub';
9     let testParentUrl: string = 'http://127.0.0.1';
10     let testEventsToWait: Array<string> = ['CHECK_IN', 'WINDOW_OUT'];
11
12     beforeEach(() => {
13        pluginPubSub = new PluginPubSub(testSub, testParentUrl, testEventsToWait);
14     });
15
16     describe('constructor tests', () => {
17         it('should init class property', () => {
18             expect(pluginPubSub.subscribers.size).toBe(1);
19             expect(pluginPubSub.eventsCallbacks.length).toBe(0);
20             expect(pluginPubSub.eventsToWait.size).toBe(0);
21             expect(pluginPubSub.clientId).toBe('testSub');
22         });
23     });
24
25     describe('subscribe function tests', () => {
26         it('should call notify function with the PLUGIN_REGISTER event and the register data', () => {
27             pluginPubSub.notify = jest.fn();
28
29             let wantedRegisterData = {
30                 pluginId: testSub,
31                 eventsToWait: []
32             };
33
34             pluginPubSub.subscribe();
35
36             expect(pluginPubSub.notify).toHaveBeenCalledWith('PLUGIN_REGISTER', wantedRegisterData);
37         })
38     });
39
40     describe('unsubscribe function tests', () => {
41         it('should call notify function with the PLUGIN_UNREGISTER event and the unregister data', () => {
42             pluginPubSub.notify = jest.fn();
43
44             let wantedUnregisterData = {
45                 pluginId: testSub,
46             };
47
48             pluginPubSub.unsubscribe();
49
50             expect(pluginPubSub.notify).toHaveBeenCalledWith('PLUGIN_UNREGISTER', wantedUnregisterData);
51         })
52     });
53 });