| 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 | 1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
15x
15x
15x
15x
15x
15x
15x
15x
15x
15x
15x
1x
15x
15x
15x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
2x
2x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
| import React from 'react';
import {expect} from 'chai';
import {shallow} from 'enzyme';
import configureStore from 'redux-mock-store';
import * as Redux from "redux";
import sinon from "sinon";
import {actions as AlertActions, DiscardRefresh} from "nexshop-web-alert";
import Playlist from "../../../src/component/playlist/playlist";
import PlayListTitleView from "../../../src/component/playlist/playlist-title-view";
import ContentsMini from "../../../src/component/playlist/contents-mini/contents-mini";
import PlaylistEditor from "../../../src/component/playlist/playlist-editor/playlist-editor";
import {discardPlaylist} from "../../../src/action/playlist";
import {createContentItem} from "../../../src/model-factory/content-item";
describe('New Playlist Spec', () => {
const CONTENT_ITEMS = Object.freeze([
createContentItem({thumbnailUrls: {thumbnail: 'some nail'}}, 5),
createContentItem('contentItem2', 30)]
);
const DEFAULT_DATA = Object.freeze({
playlist: {
name: 'playlist title',
contentItems: CONTENT_ITEMS,
resolution: {value: "QHD", text: "2560x1440", orientation: "vertical"},
}
});
let wrapper;
let instance;
let mockStore;
let spyBlockNavigation;
let spyUnblockNavigation;
let spySavePlaylistAsync;
let spyMoveToPreview;
let spyCreatePreview;
let mockHistory = {
push: () => {
}
};
beforeEach(() => {
spySavePlaylistAsync = sinon.spy();
spyBlockNavigation = sinon.spy();
spyUnblockNavigation = sinon.spy();
spyMoveToPreview = sinon.spy();
spyCreatePreview = sinon.spy();
sinon.stub(Redux, "bindActionCreators").returns({
savePlaylistAsync: spySavePlaylistAsync,
blockNavigation: spyBlockNavigation,
unblockNavigation: spyUnblockNavigation,
createPreview: spyCreatePreview,
});
sinon.stub(mockHistory, 'push').returns(sinon.spy());
sinon.stub(global, 'setTimeout');
mockStore = configureStore()(DEFAULT_DATA);
wrapper = shallow(<Playlist moveToPreview={spyMoveToPreview} store={mockStore} history={mockHistory}/>).dive();
instance = wrapper.instance();
});
afterEach(() => {
Redux.bindActionCreators.restore();
mockHistory.push.restore();
global.setTimeout.restore();
});
describe('Mapping props and actions', () => {
it('has props.name', () => {
expect(wrapper.instance().props.name).to.equal('playlist title');
});
it('has props.contentItems', () => {
expect(wrapper.instance().props.contentItems).to.deep.equal(DEFAULT_DATA.playlist.contentItems);
});
it('binds actionCreator with blockNavigation and unblockNavigation', () => {
let actions = Redux.bindActionCreators.lastCall.args[0];
const actionsKeys = Object.keys(actions);
expect(actionsKeys).to.deep.equal(['savePlaylistAsync', 'createPreview', 'blockNavigation', 'unblockNavigation']);
expect(actions.blockNavigation).to.equal(AlertActions.blockNavigation);
expect(actions.unblockNavigation).to.equal(AlertActions.unblockNavigation);
});
it('has action blockNavigation and unblockNavigation', () => {
expect(wrapper.instance().props.actions).to.deep.equal({
blockNavigation: spyBlockNavigation,
createPreview: spyCreatePreview,
unblockNavigation: spyUnblockNavigation,
savePlaylistAsync: spySavePlaylistAsync,
});
});
});
describe('rendering', () => {
it('has title and editor component with "playlist-title", "playlist-editor" and "contents-mini"', () => {
expect(wrapper.find(PlayListTitleView).length).to.equals(1);
expect(wrapper.find(PlaylistEditor).length).to.equals(1);
expect(wrapper.find(ContentsMini).length).to.equals(1);
expect(wrapper.find(DiscardRefresh).length).to.equals(1);
});
it('passes title and onPreviewClick to PlayListTitleView as props', () => {
expect(wrapper.find(PlayListTitleView).prop('name')).to.equal('playlist title');
expect(wrapper.find(PlayListTitleView).prop('onPreviewClick')).to.equal(wrapper.instance().moveToPreview);
});
});
it('calls blockNavigation action when componentDidMount is called', () => {
wrapper.instance().componentDidMount();
expect(spyBlockNavigation.calledWith('Your work has not been saved.', discardPlaylist())).to.be.true;
});
it('calls unblockNavigation action when componentWillUnmount is called', () => {
wrapper.instance().componentWillUnmount();
expect(spyUnblockNavigation.called).to.be.true;
});
it('calls unblockNavigation, createPreview action when moveToPreview is called', () => {
wrapper.instance().moveToPreview();
expect(spyUnblockNavigation.called).to.be.true;
expect(spyCreatePreview.calledWith(DEFAULT_DATA.playlist.name, DEFAULT_DATA.playlist.contentItems, 0)).to.be.true;
});
describe('calls history.push with "/contents/main"', () => {
it('when title is undefined', () => {
wrapper.setProps({title: '', resolution: {}});
wrapper.instance().componentWillMount();
expect(mockHistory.push.calledWith('/contents/main'));
});
it('when title is undefined', () => {
wrapper.setProps({title: 'some title', resolution: undefined});
wrapper.instance().componentWillMount();
expect(mockHistory.push.calledWith('/contents/main'));
});
});
describe('onPreviewClick', () => {
let setTimeoutArgument;
beforeEach(() => {
wrapper.instance().moveToPreview();
setTimeoutArgument = global.setTimeout.lastCall.args[0];
});
it('calls unblockNavigation', () => {
expect(spyUnblockNavigation.called).to.be.true;
});
it('sets history.push', () => {
setTimeoutArgument();
expect(mockHistory.push.calledWith('/contents/playlist-preview')).to.be.true;
});
});
describe('onSavePlayList', () => {
it('call savePlaylistAsync', () => {
instance.onSavePlaylist();
expect(spySavePlaylistAsync.called).to.be.true;
});
it('call savePlayListAsync with args', () => {
instance.onSavePlaylist();
let args = spySavePlaylistAsync.getCall(0).args[0];
let playlist = DEFAULT_DATA.playlist;
const [width, height] = playlist.resolution.text.split('x');
expect(args.name).to.be.equal(playlist.name);
expect(args.metaData.display.resolution.width).to.be.equal(width);
expect(args.metaData.display.resolution.height).to.be.equal(height);
expect(args.thumbnailUrls.thumbnail).to.be.equal(playlist.contentItems[0].contents.thumbnailUrls.thumbnail);
});
});
}); |