1 import {PluginPubSub} from './plugin-pubsub';
3 declare const window: Window;
5 describe('BasePubSub Tests', () => {
6 let pluginPubSub: PluginPubSub;
8 let testSub: string = 'testSub';
9 let testParentUrl: string = 'http://127.0.0.1';
10 let testEventsToWait: Array<string> = ['CHECK_IN', 'WINDOW_OUT'];
13 pluginPubSub = new PluginPubSub(testSub, testParentUrl, testEventsToWait);
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');
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();
29 let wantedRegisterData = {
34 pluginPubSub.subscribe();
36 expect(pluginPubSub.notify).toHaveBeenCalledWith('PLUGIN_REGISTER', wantedRegisterData);
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();
44 let wantedUnregisterData = {
48 pluginPubSub.unsubscribe();
50 expect(pluginPubSub.notify).toHaveBeenCalledWith('PLUGIN_UNREGISTER', wantedUnregisterData);