nexshop-web-contents
Version:
Nexshop Web Contents Project
87 lines (70 loc) • 3.28 kB
JavaScript
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 ConfirmUpdateContentsItem from '../../../../src/component/dialog/confirm-update-contents-item/confirm-update-contents-item';
describe('Confirm Update 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(),
};
sinon.stub(Redux, "bindActionCreators").returns({
openDialog: mockActions.openDialog,
closeDialog: mockActions.closeDialog,
});
mockStore = configureStore()({
dialog: 'update-contents-item',
});
dialogWrapper = shallow(<ConfirmUpdateContentsItem store={mockStore} name={"name"}/>).dive();
wrapper = shallow(<ConfirmUpdateContentsItem.WrappedDialogComponent actions={mockActions} name={"name"}/>);
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 "update-contents-item"', () => {
expect(dialogInstance.props.visibility).to.true;
});
it('has update message', () => {
expect(wrapper.find('.confirm-update-contents-item-body').at(0).text())
.to.equal("CONTENT name is in used.");
expect(wrapper.find('.confirm-update-contents-item-body').at(1).text())
.to.equal(" Would you like to modify?");
});
it('has caption', () => {
expect(wrapper.find('.confirm-update-contents-item-caption').text()).to.equal('Every scene, playlist, schedule with this file will be affected.');
});
it('binds actionCreator with openDialog, closeDialog', () => {
let actions = Redux.bindActionCreators.lastCall.args[0];
const actionsKeys = Object.keys(actions);
expect(actionsKeys).to.deep.equal(['openDialog', 'closeDialog']);
expect(actions.openDialog).to.equal(openDialog);
expect(actions.closeDialog).to.equal(closeDialog);
});
it('has actions openDialog, closeDialog, updateContentsItem', () => {
expect(dialogInstance.props.actions).to.deep.equal({
openDialog: mockActions.openDialog,
closeDialog: mockActions.closeDialog
});
});
});
});
describe('click event', () => {
it('calls closeDialog action when click Cancel button', () => {
wrapper.find('.confirm-update-contents-item-footer__cancel').simulate('click');
expect(mockActions.closeDialog.calledWith('update-contents-item')).to.be.true;
});
});
});