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

100% Statements 116/116
100% Branches 0/0
100% Functions 38/38
100% Lines 116/116
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 2311x 1x 1x 1x 1x 1x   1x 1x         1x                   1x 21x   21x 21x   21x     21x     1x 21x     1x 1x 1x                 1x 3x 3x       1x 1x 1x     1x 1x     1x 1x       1x 1x 1x     1x 1x   1x 1x     1x 1x       1x 1x       1x 1x 1x       1x 1x 1x 1x   1x         1x 1x 3x 3x     1x 1x   1x 1x   1x 1x 1x 1x   1x 1x 1x   1x     1x 1x 1x         1x 1x 3x 3x     1x 1x   1x   1x 1x   1x 1x   1x     1x 1x 1x         1x     1x 3x   3x   3x 3x     1x 3x     1x 1x     1x 1x     1x 1x 1x 1x         1x 1x 3x     1x 3x   1x 1x   1x   1x   1x     1x 1x   1x   1x     1x 1x   1x      
import React from 'react';
import {expect} from 'chai';
import {shallow, mount} from "enzyme";
import sinon from 'sinon';
import PlaylistPreviewDetailView from "../../../src/component/preview/playlist/playlist-preview-detail-view";
import {contentItemModel} from "nexshop-web-store";
 
describe('Playlist Preview Detail Spec.js', () => {
    const contents = Object.freeze({
        metaData: {
            contentUrl: "http://nexshop-api-gateway-manualtest.ap-northeast-2.elasticbeanstalk.com/api/v1/files/5c7017ebc6614557bfcdb596c7393ac4"
        }
    });
    const previousContents = Object.freeze({
        metaData: {
            contentUrl: "http://nexshop-api-gateway-manualtest.ap-northeast-2.elasticbeanstalk.com/api/v1/files/beebb59d23994f6482b24bd4004a0b7b"
        }
    });
 
    let wrapper;
    let contentItem;
    let previousContentItem;
 
    beforeEach(() => {
        sinon.stub(global, 'setTimeout');
 
        contentItem = contentItemModel.createContentItem(contents, 30, 'fade');
        previousContentItem = contentItemModel.createContentItem(previousContents, 30, 'none');
 
        wrapper = mount(<PlaylistPreviewDetailView contentItem={contentItem}
                                                   previousContentItem={previousContentItem}/>);
 
        sinon.spy(wrapper.instance(), "animate");
    });
 
    afterEach(() => {
        global.setTimeout.restore();
    });
 
    describe('video type', () => {
        const CONTENT_URL = "http://nexshop-api-gateway-manualtest.ap-northeast-2.elasticbeanstalk.com/api/v1/files/831d3ea793654233966117af7d95604d";
        const videoContents = Object.freeze({
            type: "video",
            metaData: {
                contentUrl: CONTENT_URL,
                mimeType: "video/mp4",
            }
        });
        let videoContentItem;
 
        beforeEach(() => {
            videoContentItem = contentItemModel.createContentItem(videoContents, 30, 'none');
            wrapper = mount(<PlaylistPreviewDetailView contentItem={videoContentItem}
                                                       previousContentItem={previousContentItem}/>);
        });
 
        it('has detail dom elements', () => {
            expect(wrapper.find('.preview-detail--video').exists()).to.be.true;
            expect(wrapper.find('video').exists()).to.be.true;
        });
 
        it('has src attribute with thumbnail url', () => {
            expect(wrapper.find('video').prop('src')).to.equal(CONTENT_URL);
        });
        
        it('has type attribute with mimeType', () => {
             expect(wrapper.find('video').prop('type')).to.equal("video/mp4");
        });
    });
 
    describe('none -> fade', () => {
        it('have detail dom elements', () => {
            expect(wrapper.find('.preview-detail-fade').length).to.equal(2);
        });
 
        it('has css style with opacity, transition', () => {
            expect(wrapper.find('.preview-detail-fade').at(0).node.style.opacity).to.equal('0');
 
            wrapper.setState({active: true});
            expect(wrapper.find('.preview-detail-fade').at(0).node.style.opacity).to.equal('1');
        });
 
        it('has contentUrl', () => {
            expect(wrapper.find('.preview-detail-fade').at(0).node.style.backgroundImage)
                .to.equal(`url(${contents.metaData.contentUrl})`);
        });
 
        it('has previousContentUrl', () => {
            expect(wrapper.find('.preview-detail-fade').at(1).node.style.backgroundImage)
                .to.equal(`url(${previousContents.metaData.contentUrl})`);
        });
 
        it('has not previousContent', () => {
            wrapper = mount(<PlaylistPreviewDetailView contentItem={contentItem}/>);
            expect(wrapper.find('.preview-detail-fade').at(1).node.style.backgroundImage).to.equal("url()");
        });
    });
 
    describe('No effect', () => {
        it('has detail dom elements', () => {
            contentItem = contentItemModel.createContentItem(contents, 30, 'none');
            wrapper = shallow(<PlaylistPreviewDetailView contentItem={contentItem}
                                                         previousContentItem={previousContentItem}/>);
            expect(wrapper.find('.preview-detail').length).to.equal(1);
        });
 
    });
 
    describe('Slide', () => {
        beforeEach(() => {
            contentItem = contentItemModel.createContentItem(contents, 30, 'slide');
            wrapper = mount(<PlaylistPreviewDetailView contentItem={contentItem}
                                                       previousContentItem={previousContentItem}/>);
        });
        it('has css style with height, transition', () => {
            wrapper.setState({active: false});
 
            expect(wrapper.find('.preview-detail-slide').at(0).node.style.transition).to.equal('');
            expect(wrapper.find('.preview-detail-slide').at(1).node.style.transition).to.equal('');
 
            wrapper.setState({active: true});
            expect(wrapper.find('.preview-detail-slide').at(0).node.style.transition).to.equal('left 1s');
            expect(wrapper.find('.preview-detail-slide').at(1).node.style.transition).to.equal('left 1s');
            expect(wrapper.find('.preview-detail-slide').at(0).node.style.left).to.equal('250px');
        });
        it('has detail dom elements', () => {
            contentItem = contentItemModel.createContentItem(contents, 30, 'slide');
            wrapper = shallow(<PlaylistPreviewDetailView contentItem={contentItem}
                                                         previousContentItem={previousContentItem}/>);
            expect(wrapper.find('.preview-detail-slide').length).to.equal(2);
        });
 
        it('has not previousContent', () => {
            wrapper = mount(<PlaylistPreviewDetailView contentItem={contentItem}/>);
            expect(wrapper.find('.preview-detail-slide').at(1).node.style.backgroundImage).to.equal("url()");
        });
    });
 
 
    describe('Blind', () => {
        beforeEach(() => {
            contentItem = contentItemModel.createContentItem(contents, 30, 'blind');
            wrapper = mount(<PlaylistPreviewDetailView contentItem={contentItem}
                                                       previousContentItem={previousContentItem}/>);
        });
        it('has css style with height, transition', () => {
            wrapper.setState({active: false});
 
            expect(wrapper.find('.preview-detail-blind').at(0).node.style.transition).to.equal('');
 
            wrapper.setState({active: true});
            expect(wrapper.find('.preview-detail-blind').at(0).node.style.transition).to.equal('top 1s');
        });
        it('has detail dom elements', () => {
            wrapper = shallow(<PlaylistPreviewDetailView contentItem={contentItem}
                                                         previousContentItem={previousContentItem}/>);
            expect(wrapper.find('.preview-detail-blind').length).to.equal(2);
        });
 
        it('has not previousContent', () => {
            wrapper = mount(<PlaylistPreviewDetailView contentItem={contentItem}/>);
            expect(wrapper.find('.preview-detail-blind__image').at(0).node.style.backgroundImage).to.equal("url()");
        });
 
    });
 
    describe('animate method', () => {
        let timeout;
 
        beforeEach(() => {
            wrapper.instance().animate();
 
            expect(wrapper.state('active')).to.be.false;
 
            timeout = global.setTimeout.lastCall.args[0];
            timeout();
        });
 
        afterEach(() => {
            wrapper.instance().animate.restore();
        });
 
        it('sets timeout for change active state', () => {
            expect(global.setTimeout.calledWith(sinon.match.func)).to.be.true;
        });
 
        it('changes active state with true', () => {
            expect(wrapper.state('active')).to.be.true;
        });
 
        it('not changes active state with true', () => {
            wrapper.setState({active: true});
            timeout();
            expect(wrapper.state('active')).to.be.true;
        });
 
    });
 
    describe('lifecycle method', () => {
        beforeEach(() => {
            sinon.stub(global, 'clearTimeout');
        });
 
        afterEach(() => {
            global.clearTimeout.restore();
        });
        it('call "animate()" when componentDidMount & componentDidUpdate', () => {
            wrapper.instance().componentDidMount();
 
            expect(wrapper.instance().animate.called).to.be.true;
 
            wrapper.instance().componentDidUpdate();
 
            expect(wrapper.instance().animate.calledTwice).to.be.true;
        });
 
        it('componentWillReceiveProps sets active state with false', () => {
            wrapper.setState({active: true});
 
            wrapper.instance().componentWillReceiveProps();
 
            expect(wrapper.state('active')).to.be.false;
        });
 
        it('call timeout', () => {
            wrapper.instance().componentWillUnmount();
 
            expect(global.clearTimeout.called).to.be.true;
        });
    });
});