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

100% Statements 151/151
100% Branches 0/0
100% Functions 51/51
100% Lines 151/151
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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 3591x 1x 1x 1x 1x 1x 1x   1x 1x         1x                 1x 1x   1x 27x   27x 27x   27x           27x     1x 27x     1x 1x 1x 2x                 1x 1x       1x       1x 1x       1x         1x 1x 2x           1x 1x       1x       1x 1x       1x             1x 1x 1x                 1x 3x 3x       3x     1x 1x 1x     1x 1x     1x 1x       1x 1x                           1x 2x 2x       2x     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      
import React from 'react';
import {expect} from 'chai';
import {shallow, mount} from "enzyme";
import sinon from 'sinon';
import {contentItemModel} from "nexshop-web-store";
import PlaylistPreviewDetailView from "../../../../src/component/preview/playlist/playlist-preview-detail-view";
import ScenePreviewDetailView from "../../../../src/component/preview/scene/scene-preview-detail-view";
 
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;
    const DEFAULT_RESOLUTION = {text: '16x9', orientation: 'horizontal'};
    const DEFAULT_PREVIEW_WINDOW_SIZE = {width: 2800, height: 1000};
 
    beforeEach(() => {
        sinon.stub(global, 'setTimeout');
 
        contentItem = contentItemModel.createContentItem(contents, 30, 'fade');
        previousContentItem = contentItemModel.createContentItem(previousContents, 30, 'none');
 
        wrapper = mount(<PlaylistPreviewDetailView contentItem={contentItem}
                                                   previousContentItem={previousContentItem}
                                                   resolution={DEFAULT_RESOLUTION}
                                                   previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}
        />);
 
        sinon.spy(wrapper.instance(), "animate");
    });
 
    afterEach(() => {
        global.setTimeout.restore();
    });
 
    describe('resolution', () => {
        describe('resolution ratio is 16/9', () => {
            beforeEach(() => {
                wrapper.setProps(
                    {
                        resolution: {
                            text: '2560x1440',
                            orientation: 'horizontal'
                        }
                });
            });
            
            it('when preview detail ratio bigger then resolution ratio than modify width', () => {
                const previewWindowSize = {
                    width: 2560,
                    height: 1200
                };
                expect(wrapper.instance().getPreviewBodyFrameSize(wrapper.instance().props.resolution, previewWindowSize))
                    .to.deep.equal({contentItemSize: {width: 2133, height: 1200}, mountDepth: {width: 213, height:0}});
            });
 
            it('when preview detail ratio smaller then resolution ratio modify than modify height', () => {
                const previewWindowSize ={
                        width: 1750,
                        height: 1440
                    };
                expect(wrapper.instance().getPreviewBodyFrameSize(wrapper.instance().props.resolution, previewWindowSize))
                    .to.deep.equal({contentItemSize: {width: 1750, height: 984}, mountDepth: {width: 0, height:228}});
            });
        });
 
        describe('resolution ratio is 9/16', () => {
            beforeEach(() => {
                wrapper.setProps({resolution: {
                    text: '16x9',
                    orientation: 'vertical'
                }})
            });
 
            it('when preview detail ratio smaller then resolution ratio than modify height', () => {
                const previewWindowSize = {
                        width: 750,
                        height: 2560
                    };
                expect(wrapper.instance().getPreviewBodyFrameSize(wrapper.instance().props.resolution, previewWindowSize))
                    .to.deep.equal({contentItemSize: {width: 750, height: 1333}, mountDepth: {width: 0, height:613}});
            });
 
            it('when preview detail ratio bigger then resolution ratio than modify width', () => {
                const previewWindowSize = {
                        width: 1440,
                        height: 2000
                    };
                expect(wrapper.instance().getPreviewBodyFrameSize(wrapper.instance().props.resolution, previewWindowSize))
                    .to.deep.equal({contentItemSize: {width: 1125, height: 2000}, mountDepth: {width: 157, height:0}});
            });
        });
        
    });
    
    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}
                                                       resolution={DEFAULT_RESOLUTION}
                                                       previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
            wrapper.setState({active: true});
        });
 
        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('scene type', () => {
        const sceneContent = Object.freeze({
            name: '',
            metaData: {
                panels: [],
                display: {
                    resolution: DEFAULT_RESOLUTION,
                    orientation: 'horizontal',
                }
            },
            relatedContents: undefined,
            type: 'scene'
        });
        let sceneContentItem;
 
        beforeEach(() => {
            sceneContentItem = contentItemModel.createContentItem(sceneContent, 30, 'none');
            wrapper = mount(<PlaylistPreviewDetailView contentItem={sceneContentItem}
                                                       previousContentItem={previousContentItem}
                                                       resolution={DEFAULT_RESOLUTION}
                                                       previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
            wrapper.setState({active: true});
        });
 
        it('has detail dom elements', () => {
            expect(wrapper.find(ScenePreviewDetailView).exists()).to.be.true;
        });
 
        it('scene, previewWindowSize and sceneLayoutSize props to ScenePreviewDetailView', () => {
            const scene = Object.freeze(({
                display: {
                    orientation: "horizontal",
                    resolution: {
                        orientation: "horizontal",
                        text: "16x9"
                    }
                },
                panels: []
            }));
            expect(wrapper.find(ScenePreviewDetailView).prop('scene')).to.deep.equal(scene);
            expect(wrapper.find(ScenePreviewDetailView).prop('previewWindowSize')).to.deep.equal({width: 2550, height: 1000});
            expect(wrapper.find(ScenePreviewDetailView).prop('sceneLayoutSize')).to.deep.equal({width: 960, height: 540});
        });
    });
 
    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}
                                                       resolution={DEFAULT_RESOLUTION}
                                                       previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
            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}
                                                         resolution={DEFAULT_RESOLUTION}
                                                         previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
            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}
                                                       resolution={DEFAULT_RESOLUTION}
                                                       previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
        });
        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('636px');
        });
        it('has detail dom elements', () => {
            contentItem = contentItemModel.createContentItem(contents, 30, 'slide');
            wrapper = shallow(<PlaylistPreviewDetailView contentItem={contentItem}
                                                         previousContentItem={previousContentItem}
                                                         resolution={DEFAULT_RESOLUTION}
                                                         previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
            expect(wrapper.find('.preview-detail-slide').length).to.equal(2);
        });
 
        it('has not previousContent', () => {
            wrapper = mount(<PlaylistPreviewDetailView contentItem={contentItem}
                                                       resolution={DEFAULT_RESOLUTION}
                                                       previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
            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}
                                                       resolution={DEFAULT_RESOLUTION}
                                                       previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
        });
        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}
                                                         resolution={DEFAULT_RESOLUTION}
                                                         previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
            expect(wrapper.find('.preview-detail-blind').length).to.equal(2);
        });
 
        it('has not previousContent', () => {
            wrapper = mount(<PlaylistPreviewDetailView contentItem={contentItem}
                                                       resolution={DEFAULT_RESOLUTION}
                                                       previewWindowSize={DEFAULT_PREVIEW_WINDOW_SIZE}/>);
            expect(wrapper.find('.preview-detail-blind').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()" and set state active to false when componentDidMount', () => {
            wrapper.instance().componentDidMount();
 
            expect(wrapper.instance().animate.called).to.be.true;
            expect(wrapper.state('active')).to.be.false;
        });
 
        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;
        });
    });
});