Skip to content

Commit de12c40

Browse files
committed
Mapping the store to the document
1 parent ce94a6a commit de12c40

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

app/store/mapStoreToDocument.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
import { setFullscreen } from '../actions/setFullscreen';
4+
5+
function setupDispatch(store, doc) {
6+
const state = store.getState();
7+
8+
doc.addEventListener('webkitfullscreenchange', () => {
9+
store.dispatch(setFullscreen(!state.playback.fullscreen));
10+
});
11+
}
12+
13+
export default (store, doc) => {
14+
setupDispatch(store, doc);
15+
16+
return store.subscribe(() => {});
17+
};

test/store/mapStoreToDocument.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)