|
| 1 | +import { Action, Communicator, setupPostQuecast } from '@wikia/post-quecast'; |
| 2 | +import { transformIntoHostStub } from '../../src/models/host.stub'; |
| 3 | +import { dispatchAction } from './dispatch-action'; |
| 4 | + |
| 5 | +describe('dispatchAction', () => { |
| 6 | + const dateMock = jest.spyOn(Date, 'now'); |
| 7 | + let communicatorDefault: Communicator; |
| 8 | + let communicatorOther: Communicator; |
| 9 | + |
| 10 | + beforeEach(() => { |
| 11 | + dateMock.mockReturnValue(10); |
| 12 | + transformIntoHostStub(window); |
| 13 | + setupPostQuecast(); |
| 14 | + communicatorDefault = new Communicator(); |
| 15 | + communicatorOther = new Communicator({ channelId: 'other channel' }); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should receive dispatched message', () => { |
| 19 | + const resultsDefault: Action = []; |
| 20 | + const resultsOther: Action = []; |
| 21 | + |
| 22 | + communicatorDefault.addListener((a) => resultsDefault.push(a)); |
| 23 | + communicatorOther.addListener((a) => resultsOther.push(a)); |
| 24 | + |
| 25 | + dispatchAction({ type: 'action A' }); |
| 26 | + dispatchAction({ type: 'action B', payload: 'some data' }); |
| 27 | + dispatchAction({ type: 'action C' }, 'other channel'); |
| 28 | + |
| 29 | + expect(resultsDefault).toEqual([ |
| 30 | + { type: 'action A', timestamp: 10 }, |
| 31 | + { type: 'action B', payload: 'some data', timestamp: 10 }, |
| 32 | + ]); |
| 33 | + expect(resultsOther).toEqual([{ type: 'action C', timestamp: 10 }]); |
| 34 | + }); |
| 35 | +}); |
0 commit comments