UNPKG

nexshop-web-contents

Version:

Nexshop Web Contents Project

149 lines (124 loc) 6.23 kB
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; }); }); });