| 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 | 1x
1x
1x
1x
1x
1x
1x
1x
11x
11x
11x
11x
11x
11x
11x
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
1x
1x
2x
2x
2x
2x
1x
1x
1x
1x
1x
1x
| import React from 'react';
import sinon from 'sinon';
import configureStore from 'redux-mock-store';
import {expect} from 'chai';
import {shallow} from "enzyme";
import MoveTo from "../../../../src/component/dialog/move-to/move-to";
describe('Move To Spec', () => {
let wrapper;
let spyOnClose;
let spyCloseDialog;
let spyFetchFoldersUnderFoldersAsync;
let dialogInstance;
let dialogWrapper;
let mockStore;
beforeEach(() => {
spyOnClose = sinon.spy();
spyCloseDialog = sinon.spy();
spyFetchFoldersUnderFoldersAsync = sinon.spy();
mockStore = configureStore()({
dialog: 'move-to',
contents: {
breadcrumb: [],
foldersUnderBreadcrumb: [],
},
});
dialogWrapper = shallow(<MoveTo store={mockStore}/>).dive();
wrapper = shallow(<MoveTo.WrappedDialogComponent onClose={spyOnClose}
actions={{
closeDialog: spyCloseDialog,
fetchFoldersUnderFoldersAsync: spyFetchFoldersUnderFoldersAsync,
}}
breadcrumb={[{id: 1}]}
foldersUnderBreadcrumb={[{id: 1}]}
/>);
dialogInstance = dialogWrapper.instance();
});
describe('Mapping Props', () => {
it('has visibility true when redux state dialog is "move-to"', () => {
expect(dialogInstance.props.visibility).to.true;
});
it('shows counts of will move items as a title', () => {
expect(wrapper.find('.move-to-header').text()).to.equal("Move to selected 1 contents");
});
it('shows New folder as a content', () => {
expect(wrapper.find('.move-to-body-new').text()).to.equal("+ New Folder");
});
it('click on CANCEL triggers onCancel prop', () => {
wrapper.find('.move-to-footer__cancel').simulate('click');
expect(spyCloseDialog.called).to.be.true;
});
});
describe('componentWillMount', () => {
it('call fetchFoldersUnderFoldersAsync', () => {
expect(spyFetchFoldersUnderFoldersAsync.called).to.true;
});
});
describe('componentWillReceiveProps', () => {
describe('prop value is filled', () => {
const props = {
foldersUnderBreadcrumb: [{id: 1, name: 'some folder'}, {
id: 'childrenId',
collapsed: true,
hasChildFolder: 'Y',
parentId: 1
}],
breadcrumb: [{id: 1, name: 'some folder'}],
};
it('call setState', () => {
sinon.spy(wrapper.instance(), 'setState');
wrapper.instance().componentWillReceiveProps(props);
expect(wrapper.instance().setState.called).to.true;
});
});
describe('prop value is null', () => {
const props = {
foldersUnderBreadcrumb: [],
breadcrumb: [],
};
it('call listToTree, but folders in state is null', () => {
wrapper.instance().componentWillReceiveProps(props);
expect(wrapper.instance().state.folders).to.null;
});
});
});
describe('onClickCancel', () => {
it('call closeDialog', () => {
wrapper.instance().onClickCancel();
expect(spyCloseDialog.called).to.true;
});
});
describe('onFolderItemClicked', () => {
let prevFolders;
beforeEach(() => {
prevFolders = {
id: 'parentId', collapsed: false, hasChildFolder: 'Y',
children: [{
id: 'childrenId',
collapsed: true,
hasChildFolder: 'Y',
children: [{id: 'sonId', collapsed: false, children: []}]
}],
};
wrapper.setState({
folders: prevFolders
});
});
it('call onFolderItemArrowClicked with isClosable changed', () => {
const spyOnFolderItemArrowClicked = sinon.spy(wrapper.instance(), 'onFolderItemArrowClicked');
expect(wrapper.instance().state.folders.children[0].collapsed).to.be.true;
wrapper.instance().onFolderItemClicked('childrenId');
expect(wrapper.instance().state.selectedFolderId).to.equal('childrenId');
expect(spyOnFolderItemArrowClicked.calledWith('childrenId', false)).to.true;
expect(wrapper.instance().state.folders.children[0].collapsed).to.be.false;
wrapper.instance().onFolderItemArrowClicked('childrenId', true);
expect(wrapper.instance().state.folders.children[0].collapsed).to.be.true;
expect(wrapper.instance().state.folders).to.deep.equal(prevFolders);
});
});
describe('click event', () => {
let spyOnFolderItemClicked;
let spyOnFolderItemArrowClicked;
let prevFolders;
beforeEach(() => {
spyOnFolderItemClicked = sinon.spy(wrapper.instance(), 'onFolderItemClicked');
spyOnFolderItemArrowClicked = sinon.spy(wrapper.instance(), 'onFolderItemArrowClicked');
prevFolders = {
id: 'parentId', collapsed: false, hasChildFolder: 'Y',
children: [{
id: 'childrenId',
collapsed: true,
hasChildFolder: 'Y',
children: [{id: 'sonId', collapsed: false, children: []}]
}],
};
wrapper.setState({
folders: prevFolders
});
});
it('calls onFolderItemClicked action when click folder item', () => {
wrapper.find('.move-to-folder-item-row').at(0).simulate('click');
expect(spyOnFolderItemClicked.called).to.true;
});
it('calls onFolderItemArrowClicked action when click folder item arrow', () => {
wrapper.find('.move-to-folder-item-arrow--opened').at(0).simulate('click');
expect(spyOnFolderItemArrowClicked.called).to.true;
});
});
}); |