| 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342 | 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
42x
42x
42x
1x
26x
26x
26x
1x
26x
26x
26x
26x
26x
26x
26x
26x
26x
26x
26x
26x
26x
1x
1x
6x
6x
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
4x
4x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
2x
1x
1x
1x
1x
1x
1x
2x
1x
1x
1x
1x
1x
1x
1x
1x
3x
3x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
3x
1x
1x
1x
1x
1x
1x
1x
1x
3x
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
| import React from 'react';
import {expect} from 'chai';
import {shallow} from "enzyme";
import sinon from "sinon";
import * as Redux from 'redux';
import configureStore from 'redux-mock-store';
import {actions as dialogActions} from "nexshop-web-dialog";
import {contentsActions, playlistActions, sceneActions} from "nexshop-web-store";
import {actions as popupActions} from "nexshop-web-popup";
import ContentsMain from '../../src/component/contents-main';
import ContentsMainView from '../../src/component/contents-main-view';
import {openFloatingView} from '../../src/action/floating-view';
const {selectUploadFiles, uploadFilesAsync, createNewFolderAsync, fetchExistContentNameAsync, replaceContentNameValidity} = contentsActions;
const {createPlaylist} = playlistActions;
const {createScene} = sceneActions;
const {openPopup, closePopup, closeAllPopup} = popupActions;
describe('ContentsMain Spec', () => {
let wrapper;
let instance;
let mockStore;
const spyOpenPopup = sinon.spy();
const spyOpenDialog = sinon.spy();
const spyClosePopup = sinon.spy();
const spySelectUploadFiles = sinon.spy();
const spyOpenFloatingView = sinon.spy();
const spyUploadFilesAsync = sinon.spy();
const spyCloseDialog = sinon.spy();
const spyCreatePlaylist = sinon.spy();
const spyCreateScene = sinon.spy();
const spyHistoryPush = sinon.spy();
const spyCreateNewFolderAsync = sinon.spy();
const spyCloseAllPopup = sinon.spy();
const spyFetchExistContentNameAsync = sinon.spy();
const spyReplaceContentNameValidity = sinon.spy();
const mockActions = {
openPopup: spyOpenPopup,
closePopup: spyClosePopup,
openDialog: spyOpenDialog,
closeDialog: spyCloseDialog,
selectUploadFiles: spySelectUploadFiles,
openFloatingView: spyOpenFloatingView,
uploadFilesAsync: spyUploadFilesAsync,
createPlaylist: spyCreatePlaylist,
createScene: spyCreateScene,
createNewFolderAsync: spyCreateNewFolderAsync,
closeAllPopup: spyCloseAllPopup,
fetchExistContentNameAsync: spyFetchExistContentNameAsync,
replaceContentNameValidity: spyReplaceContentNameValidity,
};
const mockHistory = {
push: spyHistoryPush
};
const {openDialog, closeDialog} = dialogActions;
const mockStoreContents = {
contentNameExisted: 'NONE',
breadcrumb: [{name: 'Contents', id: 'rootId'}]
};
function getWrapperAndInstance(mockStore) {
wrapper = shallow(<ContentsMain store={mockStore} history={mockHistory}/>).dive();
instance = wrapper.instance();
return {wrapper, instance};
}
beforeEach(() => {
mockStore = configureStore()({
dialog: 'create-scene',
popup: {},
contents: {
contentNameExisted: 'NONE',
breadcrumb: [{name: 'Contents', id: 'rootId'}]
}
});
sinon.stub(Redux, "bindActionCreators").withArgs({
openDialog,
closeDialog,
openPopup,
closePopup,
selectUploadFiles,
uploadFilesAsync,
openFloatingView,
createPlaylist,
createScene,
createNewFolderAsync,
closeAllPopup,
fetchExistContentNameAsync,
replaceContentNameValidity,
}, sinon.match.func).returns(mockActions);
({instance, wrapper} = getWrapperAndInstance(mockStore));
});
afterEach(() => {
Redux.bindActionCreators.restore();
spyOpenPopup.reset();
spyOpenDialog.reset();
spyClosePopup.reset();
spySelectUploadFiles.reset();
spyOpenFloatingView.reset();
spyUploadFilesAsync.reset();
spyCloseDialog.reset();
spyCreatePlaylist.reset();
spyCreateNewFolderAsync.reset();
spyCloseAllPopup.reset();
spyFetchExistContentNameAsync.reset();
spyReplaceContentNameValidity.reset();
});
describe('Mapping props', () => {
beforeEach(() => {
mockStore = configureStore()({dialog: '', popup: {}, contents: mockStoreContents});
({instance, wrapper} = getWrapperAndInstance(mockStore));
});
it('has addMenuVisibility according to "add-menu" popup state', () => {
expect(instance.props.addMenuVisibility).to.be.not.true;
mockStore = configureStore()({dialog: '', popup: {'add-menu': {visibility: true}}, contents: mockStoreContents});
({instance} = getWrapperAndInstance(mockStore));
expect(instance.props.addMenuVisibility).to.be.true;
});
it('has createPlaylistDialogVisibility according to "create-playlist" dialog state', () => {
expect(instance.props.createPlaylistDialogVisibility).to.be.false;
mockStore = configureStore()({dialog: 'create-playlist', popup: {}, contents: mockStoreContents});
({instance} = getWrapperAndInstance(mockStore));
expect(instance.props.createPlaylistDialogVisibility).to.be.true;
});
it('has createSceneDialogVisibility according to "create-scene" dialog state', () => {
expect(instance.props.createSceneDialogVisibility).to.be.false;
mockStore = configureStore()({dialog: 'create-scene', popup: {}, contents: mockStoreContents});
({instance} = getWrapperAndInstance(mockStore));
expect(instance.props.createSceneDialogVisibility).to.be.true;
});
it('has maps bound actions', () => {
expect(instance.props.actions).to.deep.equal(mockActions);
});
describe('addMenuVisibility ', () => {
it('addMenuVisibility is not true when popup do not have "add-menu" or visibility is false', () => {
expect(wrapper.instance().props.addMenuVisibility).to.be.not.true;
mockStore = configureStore()({dialog: '', popup: {'add-menu': {visibility: false}}, contents: mockStoreContents});
({instance, wrapper} = getWrapperAndInstance(mockStore));
expect(wrapper.instance().props.addMenuVisibility).to.be.not.true;
});
it('addMenuVisibility is true when popup do have "add-menu" and visibility is true', () => {
mockStore = configureStore()({dialog: '', popup: {'add-menu': {visibility: true}}, contents: mockStoreContents});
({instance, wrapper} = getWrapperAndInstance(mockStore));
expect(wrapper.instance().props.addMenuVisibility).to.be.true;
});
});
});
describe('uploadFiles', () => {
const files = ['fi', 'le', 's'];
beforeEach(() => {
({instance} = getWrapperAndInstance(mockStore));
instance.uploadFiles(files);
});
it('throws selectUploadFiles action', () => {
expect(spySelectUploadFiles.calledWith(files)).to.be.true;
});
it('throws uploadFileAsync after selectUploadFiles', () => {
expect(spyUploadFilesAsync.calledAfter(spySelectUploadFiles)).to.be.true;
});
it('throws openFloatingView after uploadFileAsync', () => {
expect(spyOpenFloatingView.calledAfter(spyUploadFilesAsync)).to.be.true;
});
it('throws closePopup', () => {
expect(spyClosePopup.called).to.be.true;
});
});
describe('openDialogAndClosePopup', () => {
beforeEach(() => {
instance.openDialogAndClosePopup('some dialog')
});
it('calls openDialog with passed dialog name', () => {
expect(spyOpenDialog.calledWith('some dialog')).to.be.true;
});
it('closes AddMenu', () => {
expect(spyClosePopup.called).to.be.true;
});
});
describe('clicking menu item', () => {
beforeEach(() => {
sinon.stub(instance, 'openDialogAndClosePopup');
});
it('calls openDialogAndClosePopup with "create-playlist"', () => {
instance.onCreatePlaylistMenuClicked();
expect(instance.openDialogAndClosePopup.calledWith('create-playlist')).to.be.true;
});
it('calls openDialogAndClosePopup with "create-scene"', () => {
instance.onCreateSceneMenuClicked();
expect(instance.openDialogAndClosePopup.calledWith('create-scene')).to.be.true;
});
});
describe('onAddButtonClicked', () => {
let spyStopPropagation;
beforeEach(() => {
spyStopPropagation = sinon.spy();
instance.onAddButtonClicked({stopPropagation: spyStopPropagation});
});
it('calls openPopup action with "add-menu"', () => {
expect(spyOpenPopup.calledWith('add-menu')).to.be.true;
});
it('close all popup when "add-menu" popup is already shown', () => {
mockStore = configureStore()({dialog: '', popup: {name: 'add-menu'}, contents: mockStoreContents});
({instance, wrapper} = getWrapperAndInstance(mockStore));
instance.onAddButtonClicked({stopPropagation: spyStopPropagation});
expect(spyCloseAllPopup.called).to.be.true;
});
it('stops event propagation', () => {
expect(spyStopPropagation.called).to.be.true;
});
});
describe('onPlaylistCreated', () => {
beforeEach(() => {
wrapper.instance().onPlaylistCreated("title", "resolution");
});
it('calls createPlaylist action with title, resolution', () => {
expect(spyCreatePlaylist.calledWith('title', 'resolution')).to.be.true;
});
it('calls closeDialog action', () => {
expect(spyCloseDialog.called).to.be.true;
});
it('pushes new history /contents/create-playlist', () => {
expect(spyHistoryPush.calledWith('/contents/create-playlist')).to.be.true;
});
});
describe('onSceneCreated', () => {
beforeEach(() => {
wrapper.instance().onSceneCreated("title", {text: '16x9', orientation: 'vertical'});
});
it('calls spyCreateScene action with title, resolution', () => {
expect(spyCreateScene.calledWith('title', {width: '16', height: '9'}, 'vertical')).to.be.true;
});
it('calls closeDialog action', () => {
expect(spyCloseDialog.called).to.be.true;
});
it('pushes new history /contents/scene', () => {
expect(spyHistoryPush.calledWith('/contents/scene')).to.be.true;
});
});
describe('closeDialog', () => {
it('throws closeDialog action', () => {
wrapper.instance().closeDialog();
expect(spyCloseDialog.called).to.be.true;
});
});
describe('onCreateNewFolderClicked', () => {
it('call add new folder action', () => {
wrapper.instance().onCreateNewFolderClicked();
expect(spyCreateNewFolderAsync.called).to.be.true;
});
});
describe('rendering', () => {
it('passes props to ContentsMainView', () => {
const contentsMainViewWrapper = wrapper.find(ContentsMainView);
expect(contentsMainViewWrapper.prop('onCreateSceneMenuClicked')).to.equal(instance.onCreateSceneMenuClicked);
expect(contentsMainViewWrapper.prop('onSceneCreated')).to.equal(instance.onSceneCreated);
expect(contentsMainViewWrapper.prop('onCreatePlaylistMenuClicked')).to.equal(instance.onCreatePlaylistMenuClicked);
expect(contentsMainViewWrapper.prop('onCreateNewFolderClicked')).to.equal(instance.onCreateNewFolderClicked);
expect(contentsMainViewWrapper.prop('onPlaylistCreated')).to.equal(instance.onPlaylistCreated);
expect(contentsMainViewWrapper.prop('onAddButtonClicked')).to.equal(instance.onAddButtonClicked);
expect(contentsMainViewWrapper.prop('addMenuVisibility')).to.equal(instance.props.addMenuVisibility);
expect(contentsMainViewWrapper.prop('onSelectFiles')).to.equal(instance.uploadFiles);
expect(contentsMainViewWrapper.prop('closeAddMenu')).to.equal(spyClosePopup);
expect(contentsMainViewWrapper.prop('createPlaylistDialogVisibility')).to.be.false;
expect(contentsMainViewWrapper.prop('createSceneDialogVisibility')).to.be.true;
expect(contentsMainViewWrapper.prop('closeDialog')).to.equal(instance.closeDialog);
expect(contentsMainViewWrapper.prop('fetchExistContentNameAsync')).to.equal(spyFetchExistContentNameAsync);
expect(contentsMainViewWrapper.prop('breadcrumb')).to.deep.equal(mockStoreContents.breadcrumb);
expect(contentsMainViewWrapper.prop('contentNameExisted')).to.equal(mockStoreContents.contentNameExisted);
expect(contentsMainViewWrapper.prop('replaceContentNameValidity')).to.equal(spyReplaceContentNameValidity);
});
});
}); |