import React from 'react';
import {expect} from 'chai';
import {shallow} from "enzyme";
import configureStore from 'redux-mock-store';
import * as Redux from 'redux';
import sinon from "sinon";
import ContentsMini from "../../../../src/component/playlist/contents-mini/contents-mini";
import {playlistActions} from "nexshop-web-store";
const contents = [
{
id: 1,
name: 'first.file',
type: 'image',
thumbnailUrls: {
thumbnail: 'first.thumbnail.file',
},
},
{
id: 2,
name: 'second.file',
type: 'video',
thumbnailUrls: {
thumbnail: 'second.thumbnail.file'
}
},
{
id: 3,
name: 'third.file',
type: 'playlist',
thumbnailUrls: {
thumbnail: 'third.thumbnail.file'
}
},
];
describe('Contents Mini Spec', () => {
let wrapper;
let mockStore;
let spyStartDragContentsItem;
const {startDragContentsItem} = playlistActions;
beforeEach(() => {
mockStore = configureStore()({contents: {contents}});
spyStartDragContentsItem = sinon.spy();
sinon.stub(Redux, "bindActionCreators").returns({
startDragContentsItem: spyStartDragContentsItem,
});
wrapper = shallow(<ContentsMini store={mockStore}/>).dive();
});
afterEach(() => {
Redux.bindActionCreators.restore();
});
it('Map props', () => {
const filteredContents = [{
id: 1,
name: 'first.file',
type: 'image',
thumbnailUrls: {
thumbnail: 'first.thumbnail.file',
},
}, {
id: 2,
name: 'second.file',
type: 'video',
thumbnailUrls: {
thumbnail: 'second.thumbnail.file'
}
}];
expect(wrapper.instance().props.contents).to.deep.equal(filteredContents);
});
it('binds actionCreator with startDragContentsItem', () => {
let actions = Redux.bindActionCreators.lastCall.args[0];
const actionsKeys = Object.keys(actions);
expect(actionsKeys).to.deep.equal(['startDragContentsItem']);
expect(actions.startDragContentsItem).to.equal(startDragContentsItem);
});
it('has action startDragContentsItem', () => {
expect(wrapper.instance().props.actions).to.deep.equal({
startDragContentsItem: spyStartDragContentsItem,
});
});
}); |