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

100% Statements 78/78
100% Branches 0/0
100% Functions 22/22
100% Lines 78/78
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 1721x 1x 1x 1x 1x   1x       1x 1x   1x 16x                                                             16x       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 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   1x     1x 1x 1x   1x   1x     1x 1x 1x   1x   1x        
import React from 'react';
import {expect} from 'chai';
import {shallow} from 'enzyme';
import PanelGroup from "react-panelgroup";
import ScenePreviewDetailView from "../../../../src/component/preview/scene/scene-preview-detail-view";
 
describe('Scene Preview Detail View Spec', () => {
    let wrapper;
    let mockScene;
 
    const PREVIEW_WINDOW_SIZE = {width: 1920, height: 1080};
    const SCENE_LAYOUT_SIZE = {width: 960, height: 540};
 
    beforeEach(() => {
        mockScene = {
            panels: [
                {
                    id: 'g1',
                    domAttribute: {size: 960, minSize: 5, resize: 'dynamic'},
                    type: 'group',
                    direction: 'row',
                    panels: [
                        {
                            id: 'p1',
                            domAttribute: {size: 480, minSize: 5, resize: 'dynamic', pixelWidth: 480, pixelHeight: 540},
                            type: 'panel',
                            contentItems: [{
                                type: 'image',
                                contentUrl: 'some url'
                            }]
                        },
                        {
                            id: 'p2',
                            domAttribute: {size: 480, minSize: 5, resize: 'dynamic', pixelWidth: 480, pixelHeight: 540},
                            type: 'panel',
                            contentItems: [{
                                type: 'video',
                                contentUrl: 'some url'
                            }]
                        }
                    ]
                },
            ]
        };
 
        wrapper = shallow(<ScenePreviewDetailView scene={mockScene} previewWindowSize={PREVIEW_WINDOW_SIZE}
                                                  sceneLayoutSize={SCENE_LAYOUT_SIZE}/>);
    });
 
    describe('render', () => {
        it('has 2 panel groups', () => {
            expect(wrapper.find(PanelGroup)).to.lengthOf(2);
        });
 
        it('has 2 panel', () => {
            expect(wrapper.find('.layout-panel__body')).to.lengthOf(2);
        });
 
        it('has 1 image', () => {
            expect(wrapper.find('.layout-panel__body__status--image')).to.lengthOf(1);
        });
 
        it('has 1 video', () => {
            expect(wrapper.find('.layout-panel__body__status--video')).to.lengthOf(1);
        });
 
        it('preview scene be double up', () => {
            expect(wrapper.find(PanelGroup).at(0).html()).to.contains('style="width:1920px;');
        });
 
        it('video element has double up panel width and height', () => {
            expect(wrapper.find('video').html()).to.contains('width:960px');
            expect(wrapper.find('video').html()).to.contains('height:1080px');
        });
    });
 
    describe('find size ratio', () => {
        describe('find base side', () => {
            it('base height side when wide monitor(16:8) & horizontal scene(16:9)', () => {
                const sceneRatio = 16 / 9;
                const windowRatio = 16 / 8;
 
                const baseSide = wrapper.instance().getPreviewBaseSide(sceneRatio, windowRatio);
 
                expect(baseSide).to.be.equal('height');
            });
 
            it('base width side when wide monitor(16:10) & horizontal scene(16:9)', () => {
                const sceneRatio = 16 / 9;
                const windowRatio = 16 / 10;
 
                const baseSide = wrapper.instance().getPreviewBaseSide(sceneRatio, windowRatio);
 
                expect(baseSide).to.be.equal('width');
            });
 
            it('base height side when wide monitor(16:8) & vertical scene(9:16)', () => {
                const sceneRatio = 9 / 16;
                const windowRatio = 16 / 8;
 
                const baseSide = wrapper.instance().getPreviewBaseSide(sceneRatio, windowRatio);
 
                expect(baseSide).to.be.equal('height');
            });
 
            it('base width side when narrow monitor(8:16) & horizontal scene(16:9)', () => {
                const sceneRatio = 16 / 9;
                const windowRatio = 8 / 16;
 
                const baseSide = wrapper.instance().getPreviewBaseSide(sceneRatio, windowRatio);
 
                expect(baseSide).to.be.equal('width');
            });
 
            it('base width side when narrow monitor(8:16) & vertical scene(9:16)', () => {
                const sceneRatio = 9 / 16;
                const windowRatio = 8 / 16;
 
                const baseSide = wrapper.instance().getPreviewBaseSide(sceneRatio, windowRatio);
 
                expect(baseSide).to.be.equal('width');
            });
 
            it('base height side when narrow monitor(10:16) & vertical scene(9:16)', () => {
                const sceneRatio = 9 / 16;
                const windowRatio = 10 / 16;
 
                const baseSide = wrapper.instance().getPreviewBaseSide(sceneRatio, windowRatio);
 
                expect(baseSide).to.be.equal('height');
            });
        });
 
        describe('find ratio', () => {
            it('ratio is 2 when monitor(1920:1080) & scene(960:540)', () => {
                const sceneSize = {width: 960, height: 540};
                const windowSize = {width: 1920, height: 1080};
 
                const ratio = wrapper.instance().getPreviewRatio(sceneSize, windowSize);
 
                expect(ratio).to.be.equal(2);
            });
 
            it('ratio is 0.5 when monitor(480:270) & scene(16:9)', () => {
                const sceneSize = {width: 960, height: 540};
                const windowSize = {width: 480, height: 270};
 
                const ratio = wrapper.instance().getPreviewRatio(sceneSize, windowSize);
 
                expect(ratio).to.be.equal(0.5);
            });
 
            it('ratio is 1 when monitor(1980:540) & scene(960:540)', () => {
                const sceneSize = {width: 960, height: 540};
                const windowSize = {width: 1980, height: 540};
 
                const ratio = wrapper.instance().getPreviewRatio(sceneSize, windowSize);
 
                expect(ratio).to.be.equal(1);
            });
 
            it('ratio is 0.5 when monitor(1280:480) & scene(540:960)', () => {
                const sceneSize = {width: 540, height: 960};
                const windowSize = {width: 1280, height: 480};
 
                const ratio = wrapper.instance().getPreviewRatio(sceneSize, windowSize);
 
                expect(ratio).to.be.equal(0.5);
            });
        });
    });
});