import React from 'react';
import {expect} from 'chai';
import {shallow} from 'enzyme';
import sinon from 'sinon';
import ContentsMainView from '../../src/component/contents-main-view';
import AddMenu from '../../src/component/popup/add-menu/add-menu';
import CreateThat from '../../src/component/dialog/create-that/create-that';
import ConfirmDeleteContentsItem from '../../src/component/dialog/confirm-delete-contents-item/confirm-delete-contents-item';
import MoveTo from '../../src/component/dialog/move-to/move-to';
describe('ContentsMain View Spec', () => {
const spyOnAddButtonClicked = sinon.spy();
const spyOnCreatePlaylistMenuClicked = sinon.spy();
const spyOnPlaylistCreated = sinon.spy();
const spyOnCreateSceneMenuClicked = sinon.spy();
const spyOnUploadFilesSelected = sinon.spy();
const spyCloseAddMenu = sinon.spy();
const spyCloseDialog = sinon.spy();
const spyOnCreateNewFolderClicked = sinon.spy();
const breadcrumb = [{name: 'name1', id: 'id1'}, {name: 'name1', id: 'id1'}];
const spyReplaceContentNameValidity = sinon.spy();
const spyFetchExistContentNameAsync = sinon.spy();
const contentNameExisted = 'NONE';
let wrapper;
beforeEach(() => {
wrapper = shallow(
<ContentsMainView
addMenuVisibility={true}
onAddButtonClicked={spyOnAddButtonClicked}
onCreatePlaylistMenuClicked={spyOnCreatePlaylistMenuClicked}
onCreateSceneMenuClicked={spyOnCreateSceneMenuClicked}
onSelectFiles={spyOnUploadFilesSelected}
closeAddMenu={spyCloseAddMenu}
closeDialog={spyCloseDialog}
onCreateNewFolderClicked={spyOnCreateNewFolderClicked}
fetchExistContentNameAsync={spyFetchExistContentNameAsync}
breadcrumb={breadcrumb}
replaceContentNameValidity={spyReplaceContentNameValidity}
contentNameExisted={contentNameExisted}
/>
);
});
afterEach(() => {
spyOnAddButtonClicked.reset();
spyOnCreatePlaylistMenuClicked.reset();
spyOnPlaylistCreated.reset();
spyOnCreateSceneMenuClicked.reset();
spyCloseAddMenu.reset();
spyCloseDialog.reset();
spyOnCreateNewFolderClicked.reset();
spyReplaceContentNameValidity.reset();
});
it('calls onAddButtonClicked', () => {
wrapper.find('.add-button').simulate('click');
expect(spyOnAddButtonClicked.called).to.be.true;
});
it('has add-button-rotate class when addMenuVisibility prop is true', () => {
expect(wrapper.find('.add-button').hasClass('add-button--rotate')).to.be.true;
});
it('does not have add-buttor-rotate class when addmenuVisibility prop is false', () => {
wrapper.setProps({addMenuVisibility: false});
expect(wrapper.find('.add-button').hasClass('add-button--rotate')).to.be.false;
});
describe('AddMenu', () => {
it('passes props', () => {
expect(wrapper.find(AddMenu).prop('onClose')).to.equal(wrapper.instance().closeAddMenu);
expect(wrapper.find(AddMenu).prop('onCreatePlaylistClicked')).to.equal(spyOnCreatePlaylistMenuClicked);
expect(wrapper.find(AddMenu).prop('onCreateSceneClicked')).to.equal(spyOnCreateSceneMenuClicked);
expect(wrapper.find(AddMenu).prop('onUploadFilesSelected')).to.equal(spyOnUploadFilesSelected);
expect(wrapper.find(AddMenu).prop('onCreateNewFolderClicked')).to.equal(spyOnCreateNewFolderClicked);
});
it('call closeAddMenu when AddMenu close button clicked', () => {
wrapper.instance().closeAddMenu();
expect(spyCloseAddMenu.called).to.true;
});
});
describe('Create That', () => {
let spyOnPlaylistCreated;
let spyOnSceneCreated;
let createPlaylist;
let createScene;
let spyCloseDialog;
beforeEach(() => {
spyOnPlaylistCreated = sinon.spy();
spyOnSceneCreated = sinon.spy();
spyCloseDialog = sinon.spy();
wrapper.setProps({
createPlaylistDialogVisibility: true,
createSceneDialogVisibility: false,
onPlaylistCreated: spyOnPlaylistCreated,
onSceneCreated: spyOnSceneCreated,
closeDialog: spyCloseDialog,
breadcrumb,
replaceContentNameValidity: spyReplaceContentNameValidity
});
createPlaylist = wrapper.find(CreateThat).at(0);
createScene = wrapper.find(CreateThat).at(1);
});
it('has 2 different dialogs', () => {
expect(wrapper.find(CreateThat).length).to.equal(2);
});
it('has one for playlist and another for scene', () => {
expect(createPlaylist.prop('whatThatIs')).to.equal('Playlist');
expect(createScene.prop('whatThatIs')).to.equal('Scene');
});
it('has visibility for each dialogs', () => {
expect(createPlaylist.prop('visibility')).to.be.true;
expect(createScene.prop('visibility')).to.be.false;
});
it('has onCreate handler for each dialogs', () => {
expect(createPlaylist.prop('onCreated')).to.equal(spyOnPlaylistCreated);
expect(createScene.prop('onCreated')).to.equal(spyOnSceneCreated);
});
it('has onCancel, onClose as closeDialog prop for each dialogs', () => {
expect(createPlaylist.prop('onCancel')).to.equal(spyCloseDialog);
expect(createScene.prop('onCancel')).to.equal(spyCloseDialog);
expect(createPlaylist.prop('onClose')).to.equal(spyCloseDialog);
expect(createScene.prop('onClose')).to.equal(spyCloseDialog);
});
it('has breadcrumb, replaceContentNameValidity props for each dialogs', () => {
expect(createPlaylist.prop('breadcrumb')).to.equal(breadcrumb);
expect(createScene.prop('breadcrumb')).to.equal(breadcrumb);
expect(createPlaylist.prop('replaceContentNameValidity')).to.equal(spyReplaceContentNameValidity);
expect(createScene.prop('replaceContentNameValidity')).to.equal(spyReplaceContentNameValidity);
});
it('has ConfirmDeleteContentsItem', () => {
expect(wrapper.find(ConfirmDeleteContentsItem).exists()).to.true;
});
it('has MoveTo', () => {
expect(wrapper.find(MoveTo).exists()).to.true;
});
});
}); |