| 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 | 1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
18x
18x
18x
18x
18x
18x
18x
18x
18x
18x
18x
18x
1x
18x
18x
18x
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
1x
1x
1x
2x
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 {playlistActions, contentItemModel} from "nexshop-web-store";
describe('New Playlist Spec', () => {
const CONTENT_ITEMS = Object.freeze([
contentItemModel.createContentItem({thumbnailUrls: {thumbnail: 'some nail'}}, 5),
contentItemModel.createContentItem('contentItem2', 30)]
);
const {discardPlaylist} = playlistActions;
const DEFAULT_DATA = Object.freeze({
playlist: {
name: 'playlist title',
contentItems: CONTENT_ITEMS,
resolution: {value: "QHD", text: "2560x1440", orientation: "vertical"},
},
update_playlist: {
name: 'playlist title',
contentItems: CONTENT_ITEMS,
resolution: {value: "QHD", text: "2560x1440", orientation: "vertical"},
id: "some id",
type: "video",
durationSeconds: 30,
transitionEffect: "none",
fitMode: "contain"
}
});
let wrapper;
let instance;
let mockStore;
let spyBlockNavigation;
let spyUnblockNavigation;
let spySavePlaylistAsync;
let spyUpdatePlaylistAsync;
let spyMoveToPreview;
let spyCreatePreview;
let mockHistory = {
push: () => {
}
};
beforeEach(() => {
spySavePlaylistAsync = sinon.spy();
spyUpdatePlaylistAsync = sinon.spy();
spyBlockNavigation = sinon.spy();
spyUnblockNavigation = sinon.spy();
spyMoveToPreview = sinon.spy();
spyCreatePreview = sinon.spy();
sinon.stub(Redux, "bindActionCreators").returns({
savePlaylistAsync: spySavePlaylistAsync,
updatePlaylistAsync: spyUpdatePlaylistAsync,
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', 'updatePlaylistAsync', '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,
updatePlaylistAsync: spyUpdatePlaylistAsync,
});
});
});
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', () => {
describe('playlist save', () => {
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);
});
});
describe('playlist update', () => {
beforeEach(() => {
wrapper.setProps({id: "some id"});
});
it('call updatePlaylistAsync when contents id is exist', () => {
instance.onSavePlaylist();
expect(spyUpdatePlaylistAsync.called).to.be.true;
});
it('call updatePlaylistAsync with args when contents id is exist', () => {
instance.onSavePlaylist();
let args = spyUpdatePlaylistAsync.getCall(0).args[0];
let playlist = DEFAULT_DATA.update_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);
expect(args.metaData.contentItems[0].id).to.be.equal(playlist.contentItems[0].id);
});
});
});
it('getRelatedContents', () => {
const expected = [ { id: '3' }, { id: '2' }, { id: '1' } ];
expect(instance.getRelatedContents([{contents: {id: '3'}},
{contents: {id: '2', relatedContents:[{id: '3'},{id: '1'}]}}])).to.deep.equal(expected);
});
}); |