aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plugin-pubusb.spec.ts
blob: 1eb6edaf57ed913c2df9e0d753b168dd79dbdbce (plain)
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
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);
        })
    });
});