| 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 | 1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
12x
12x
12x
12x
12x
12x
1x
12x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
1x
3x
3x
3x
3x
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 sinon from 'sinon';
import * as Redux from "redux";
import {actions as dialogActions} from "nexshop-web-dialog";
import ConfirmDeleteContentsItem from '../../../../src/component/dialog/confirm-delete-contents-item/confirm-delete-contents-item';
import {contentsActions} from "nexshop-web-store";
const {deleteContentsItem} = contentsActions;
describe('Confirm Delete Contents Item Spec', () => {
let dialogWrapper;
let wrapper;
let mockStore;
let mockActions;
let dialogInstance;
const {openDialog, closeDialog} = dialogActions;
beforeEach(() => {
mockActions = {
openDialog: sinon.spy(),
closeDialog: sinon.spy(),
deleteContentsItem: sinon.spy(),
};
sinon.stub(Redux, "bindActionCreators").returns({
openDialog: mockActions.openDialog,
closeDialog: mockActions.closeDialog,
deleteContentsItem: mockActions.deleteContentsItem,
});
mockStore = configureStore()({
dialog: 'delete-contents-item',
contents: {
deleteIndex: 0,
used: 'NONE'
}
});
dialogWrapper = shallow(<ConfirmDeleteContentsItem store={mockStore}/>).dive();
wrapper = shallow(<ConfirmDeleteContentsItem.WrappedDialogComponent actions={mockActions}
deleteIndex={0}
used={'NONE'}/>);
dialogInstance = dialogWrapper.instance();
});
afterEach(() => {
Redux.bindActionCreators.restore();
});
describe('Mapping Props', () => {
describe('not used contents item case', () => {
it('has visibility true when redux state dialog is "delete-contents-item"', () => {
expect(dialogInstance.props.visibility).to.true;
});
it('has deleteIndex', () => {
expect(dialogInstance.props.deleteIndex).to.equal(0);
});
it('has used', () => {
expect(dialogInstance.props.used).to.equal('NONE')
});
it('has delete message', () => {
expect(wrapper.find('.confirm-delete-contents-item-body').text())
.to.equal('Would you like to delete?')
});
it('has delete button', () => {
expect(wrapper.find('.confirm-delete-contents-item-footer__delete').text()).to.equal('DELETE');
});
it('binds actionCreator with openDialog, closeDialog, deleteContentsItem', () => {
let actions = Redux.bindActionCreators.lastCall.args[0];
const actionsKeys = Object.keys(actions);
expect(actionsKeys).to.deep.equal(['openDialog', 'closeDialog', 'deleteContentsItem']);
expect(actions.openDialog).to.equal(openDialog);
expect(actions.closeDialog).to.equal(closeDialog);
expect(actions.deleteContentsItem).to.equal(deleteContentsItem);
});
it('has actions openDialog, closeDialog, deleteContentsItem', () => {
expect(dialogInstance.props.actions).to.deep.equal({
openDialog: mockActions.openDialog,
closeDialog: mockActions.closeDialog,
deleteContentsItem: mockActions.deleteContentsItem,
});
});
});
describe('used contents item case', () => {
beforeEach(() => {
mockStore = configureStore()({
dialog: 'delete-contents-item',
contents: {
deleteIndex: 0,
willDeleteContent: {
name: 'NOT terminate contents item'
},
used: 'USED'
}
});
dialogWrapper = shallow(<ConfirmDeleteContentsItem store={mockStore}/>).dive();
wrapper = shallow(<ConfirmDeleteContentsItem.WrappedDialogComponent actions={mockActions}
deleteIndex={0}
willDeleteContent={
{name:'NOT terminate contents item'}
}
used={'USED'}
/>);
dialogInstance = dialogWrapper.instance();
});
it('has used', () => {
expect(dialogInstance.props.used).to.equal('USED')
});
it('has delete message', () => {
expect(wrapper.find('.confirm-delete-contents-item-body').at(0).text()).to.equal('CONTENT NOT terminate contents item is in used.');
expect(wrapper.find('.confirm-delete-contents-item-body').at(1).text()).to.equal(' Would you like to delete?')
});
it('has caption', () => {
expect(wrapper.find('caption').text()).to.equal('Every scene, playlist, schedule with this file will be affected.');
});
});
});
describe('click event', () => {
it('calls closeDialog action when click Cancel button', () => {
wrapper.find('.confirm-delete-contents-item-footer__cancel').simulate('click');
expect(mockActions.closeDialog.called).to.be.true;
});
it('calls deleteContentsItem and closeDialog action when click Delete button', () => {
wrapper.find('.confirm-delete-contents-item-footer__delete').simulate('click');
expect(mockActions.deleteContentsItem.calledWith(0)).to.be.true;
expect(mockActions.closeDialog.called).to.be.true;
});
});
}); |