All files / nexshop-web-contents/spec/component/contents/floating-view floating-view-spec.js

100% Statements 34/34
100% Branches 0/0
100% Functions 12/12
100% Lines 34/34
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 671x 1x 1x 1x 1x   1x     1x       1x 8x   8x     1x 1x     1x 1x   1x     1x 1x   1x     1x 1x     1x       1x 4x 4x 4x     1x 1x     1x 1x 1x     1x 1x     1x 1x      
import React from 'react';
import {expect} from 'chai';
import sinon from "sinon";
import {shallow} from "enzyme";
import FloatingView from "../../../../src/component/contents/floating-view/floating-view";
 
describe('Floating View Spec', () => {
    let wrapper;
    let spyOnClose;
    const files = [
        {name: 'Image.jpg', type: 'image/jpeg'},
    ];
 
    beforeEach(() => {
        spyOnClose = sinon.spy();
 
        wrapper = shallow(<FloatingView files={files} onClose={spyOnClose}/>)
    });
 
    it('shows header text as "Uploading 1 item" when files length is one', () => {
       expect(wrapper.find('.floating-header__text').text()).to.equal('Uploading 1 item');
    });
 
    it('shows header text as "Uploading 2 items" when files length is two', () => {
        wrapper.setProps({files: [...files, {name: 'file.ext', type: 'ext/etc'}]});
 
        expect(wrapper.find('.floating-header__text').text()).to.equal('Uploading 2 items');
    });
 
    it('calls onClose when close icon is clicked', () => {
        wrapper.find('.floating-close').simulate('click');
 
        expect(spyOnClose.called).to.be.true;
    });
 
    it('renders upload file items', () => {
        expect(wrapper.find('.floating-body').children().length).to.equal(1);
    });
 
    describe('floating file', () => {
        let progressItem;
        let doneItem;
 
        beforeEach(() => {
            wrapper.setProps({files: [...files, {name: 'Video.mp4', type: 'video/mp4', status: 'done'}]});
            progressItem = wrapper.find('.floating-file').at(0);
            doneItem = wrapper.find('.floating-file').at(1);
        });
 
        it('has file name as text', () => {
            expect(progressItem.find('.floating-file__name').text()).to.equal('Image.jpg');
        });
 
        it('has icon by type', () => {
            expect(progressItem.find('.floating-file__icon-image').length).to.equal(1);
            expect(doneItem.find('.floating-file__icon-video').length).to.equal(1);
        });
 
        it('has progress icon when file status is progress', () => {
            expect(progressItem.find('.floating-file__progress').length).to.equal(1);
        });
 
        it('has done icon when file status is done', () => {
            expect(doneItem.find('.floating-file__done').length).to.equal(1);
        });
    });
});