|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +import assert from 'assert'; |
| 4 | +import sinon from 'sinon'; |
| 5 | + |
| 6 | +import configureStore from '../../app/store/configurePlayerStore'; |
| 7 | +import mapStoreToDocument from '../../app/store/mapStoreToDocument'; |
| 8 | +import { SET_FULLSCREEN } from '../../app/actions/setFullscreen'; |
| 9 | + |
| 10 | +const store = configureStore(); |
| 11 | +const sandbox = sinon.sandbox.create(); |
| 12 | + |
| 13 | +function createDocument(params) { |
| 14 | + const defaultDocument = { |
| 15 | + addEventListener: function addEventListener(name, cb) { |
| 16 | + this[name] = cb; |
| 17 | + } |
| 18 | + }; |
| 19 | + |
| 20 | + return Object.assign({}, defaultDocument, params); |
| 21 | +} |
| 22 | + |
| 23 | +describe('mapStoreToDocument', () => { |
| 24 | + beforeEach(() => { |
| 25 | + sandbox.stub(store, 'getState'); |
| 26 | + sandbox.stub(store, 'dispatch'); |
| 27 | + }); |
| 28 | + |
| 29 | + afterEach(() => { |
| 30 | + sandbox.restore(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('triggers the set fullscreen action with false when the fullscreenchange event is triggered and fullscreen: true', () => { |
| 34 | + store.getState.returns({ |
| 35 | + playback: { |
| 36 | + fullscreen: false |
| 37 | + } |
| 38 | + }); |
| 39 | + const doc = createDocument(); |
| 40 | + const unsubscribe = mapStoreToDocument(store, doc); |
| 41 | + |
| 42 | + doc.webkitfullscreenchange(); |
| 43 | + |
| 44 | + assert(store.dispatch.calledWith({ |
| 45 | + type: SET_FULLSCREEN, |
| 46 | + fullscreen: true |
| 47 | + })); |
| 48 | + |
| 49 | + unsubscribe(); |
| 50 | + }); |
| 51 | + |
| 52 | + it('triggers the set fullscreen action with true when the fullscreenchange event is triggered and fullscreen: false', () => { |
| 53 | + store.getState.returns({ |
| 54 | + playback: { |
| 55 | + fullscreen: true |
| 56 | + } |
| 57 | + }); |
| 58 | + const doc = createDocument(); |
| 59 | + const unsubscribe = mapStoreToDocument(store, doc); |
| 60 | + |
| 61 | + doc.webkitfullscreenchange(); |
| 62 | + |
| 63 | + assert(store.dispatch.calledWith({ |
| 64 | + type: SET_FULLSCREEN, |
| 65 | + fullscreen: false |
| 66 | + })); |
| 67 | + |
| 68 | + unsubscribe(); |
| 69 | + }); |
| 70 | +}); |
0 commit comments