All files / nexshop-web-contents/spec/component/preview playlist-preview-spec.js

100% Statements 55/55
100% Branches 0/0
94.12% Functions 16/17
100% Lines 55/55
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 1141x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x         1x             1x         1x 9x   9x 9x 9x   9x         9x               9x     1x 9x 9x     1x 1x 1x     1x 1x     1x 1x 1x 1x   1x     1x 1x             1x 1x 1x 1x     1x 1x 1x 1x     1x 1x       1x 1x 2x     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 {previewActions, contentItemModel} from "nexshop-web-store";
import PlaylistPreview from '../../../src/component/preview/playlist/playlist-preview';
import PlaylistPreviewListView from "../../../src/component/preview/playlist/playlist-preview-list-view";
import PlaylistPreviewHeaderView from "../../../src/component/preview/playlist/playlist-preview-header-view";
import PlaylistPreviewDetailView from "../../../src/component/preview/playlist/playlist-preview-detail-view";
 
describe('Playlist Preview Spec', () => {
    const contentItems = [
        contentItemModel.createContentItem({contentUrl: 'some url'}),
        contentItemModel.createContentItem({contentUrl: 'contentUrl2'})
    ];
 
    const {selectPreviewItem} = previewActions;
 
    let wrapper;
    let mockStore;
    let spySelectPreviewItem;
    let spyDeletePreviewPreviousIndex;
 
    let mockHistory = {
        goBack: () => {
        }
    };
 
    beforeEach(() => {
        sinon.stub(mockHistory, 'goBack');
 
        mockStore = configureStore()({preview: {name: 'X-Men Begins', contentItems}});
        spySelectPreviewItem = sinon.spy();
        spyDeletePreviewPreviousIndex = sinon.spy();
 
        sinon.stub(Redux, "bindActionCreators").returns({
            selectPreviewItem: spySelectPreviewItem,
            deletePreviewPreviousIndex: spyDeletePreviewPreviousIndex,
        });
 
        mockStore = configureStore()({
            preview: {
                name: 'X-Men Begins',
                contentItems: contentItems,
                selectedPreviewItemIndex: 1,
            },
        });
 
        wrapper = shallow(<PlaylistPreview store={mockStore} history={mockHistory}/>).dive();
    });
 
    afterEach(() => {
        mockHistory.goBack.restore();
        Redux.bindActionCreators.restore();
    });
 
    describe('Mapping props', () => {
        it('has playlist name', () => {
            expect(wrapper.instance().props.name).to.equal('X-Men Begins');
        });
 
        it('has selectedPreviewItemIndex', () => {
            expect(wrapper.instance().props.selectedPreviewItemIndex).to.equal(1);
        });
 
        it('bindActionCreators', () => {
            let actions = Redux.bindActionCreators.lastCall.args[0];
            const actionsKeys = Object.keys(actions);
            expect(actionsKeys).to.deep.equal(['selectPreviewItem','deletePreviewPreviousIndex']);
 
            expect(actions.selectPreviewItem).to.equal(selectPreviewItem);
        });
 
        it('has action selectPreviewItem', () => {
            expect(wrapper.instance().props.actions).to.deep.equal({
                selectPreviewItem: spySelectPreviewItem,
                deletePreviewPreviousIndex: spyDeletePreviewPreviousIndex,
            });
        });
    });
 
    describe('passes props', () => {
        it('passes name and onClickClose props to PlaylistPreviewHeaderView', () => {
            expect(wrapper.find(PlaylistPreviewHeaderView).prop('name')).to.equal('X-Men Begins');
            expect(wrapper.find(PlaylistPreviewHeaderView).prop('onClickClose')).to.equal(wrapper.instance().onClickClose);
        });
 
        it('passes playlist, selectedPreviewItemIndex and onSelectPreviewItem props to PlaylistPreviewListView', () => {
            expect(wrapper.find(PlaylistPreviewListView).prop('contentItems')).to.equal(contentItems);
            expect(wrapper.find(PlaylistPreviewListView).prop('selectedPreviewItemIndex')).to.equal(1);
            expect(wrapper.find(PlaylistPreviewListView).prop('onSelectPreviewItem')).to.equal(spySelectPreviewItem);
        });
 
        it('passes contentUrl props to PlaylistPreviewDetailView', () => {
            expect(wrapper.find(PlaylistPreviewDetailView).prop('contentItem').contents.contentUrl).to.equal(contentItems[1].contents.contentUrl);
        });
    });
 
    describe('onClickClose', () => {
        beforeEach(() => {
            wrapper.instance().onClickClose();
        });
 
        it('calls history.goBack', () => {
            expect(mockHistory.goBack.called).to.be.true;
        });
 
        it('dispatches selectPreviewItem with zero', () => {
            expect(spySelectPreviewItem.calledWith(0)).to.be.true;
        });
    });
});