All files / nexshop-web-contents/spec/component/dialog/create-that create-that-spec.js

100% Statements 58/58
100% Branches 0/0
100% Functions 16/16
100% Lines 58/58
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 1181x 1x 1x 1x 1x 1x   1x           1x 11x 11x 11x   11x                 1x 1x     1x 1x 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   1x     1x 1x 1x 1x 1x   1x   1x     1x 1x   1x   1x   1x    
import React from 'react';
import sinon from 'sinon';
import {expect} from 'chai';
import {mount, shallow} from "enzyme";
import CreateThat from "../../../../src/component/dialog/create-that/create-that";
import ResolutionDropDown from "../../../../src/component/resolution-drop-down/resolution-drop-down";
 
describe('CreateThat Spec', () => {
    let wrapper;
    let spyOnClose;
    let spyReplaceContentNameValidity;
    let spyFetchExistContentNameAsync;
 
    beforeEach(() => {
        spyOnClose = sinon.spy();
        spyReplaceContentNameValidity = sinon.spy();
        spyFetchExistContentNameAsync = sinon.spy();
 
        wrapper = shallow(<CreateThat.WrappedDialogComponent whatThatIs="Scene" onClose={spyOnClose}
                                                             visibility={true}
                                                             breadcrumb={[{name: 'Contents', id: 'rootId'}]}
                                                             replaceContentNameValidity={spyReplaceContentNameValidity}
                                                             contentNameExisted="NONE"
                                                             fetchExistContentNameAsync={spyFetchExistContentNameAsync}
        />);
    });
 
    it('shows that + Name as a title', () => {
        expect(wrapper.find('.create-that-body__title').text()).to.equal("Scene Name");
    });
 
    describe('title input focus and blur test', () => {
        beforeEach(() => {
            wrapper = mount(<CreateThat.WrappedDialogComponent whatThatIs="Scene" onClose={spyOnClose} visibility={true}
                                                               breadcrumb={[{name: 'Contents', id: 'rootId'}]}
                                                               replaceContentNameValidity={spyReplaceContentNameValidity}
                                                               contentNameExisted="NONE"
                                                               fetchExistContentNameAsync={spyFetchExistContentNameAsync}
            />);
        });
        it('focuses on title Input', () => {
            const focusedElement = document.activeElement;
 
            expect(wrapper.find('.create-that-body__input').matchesElement(focusedElement)).to.be.true;
        });
 
        it('call fetchExistContentNameAsync when after input name and focus out', () => {
            wrapper.instance().titleInput.value = 'some scene name';
            wrapper.find('.create-that-body__input').simulate('blur');
 
            expect(spyFetchExistContentNameAsync.calledWith('rootId', 'Scene', 'some scene name')).to.true;
        });
 
        it('show error message when name is invalid', () => {
            wrapper.instance().titleInput.value = 'some name';
            wrapper.setProps({contentNameExisted: 'EXIST'});
 
            expect(wrapper.find('.create-that-body__error-message').at(0).text()).to.not.empty;
        });
    });
 
    describe('ResolutionDropDown', () => {
        it('passes changeResolution as onChange prop', () => {
            expect(wrapper.find(ResolutionDropDown).prop('onChange')).to.equal(wrapper.instance().changeResolution);
        });
    });
 
    it('passes changeTitle as onChange of input', () => {
        expect(wrapper.find('.create-that-body__input').prop('onChange')).to.equal(wrapper.instance().changeTitle);
    });
 
    it('changeTitle changes title state', () => {
        wrapper.instance().changeTitle({target: {value: 'new title'}});
 
        expect(wrapper.state('title')).to.equal('new title');
    });
 
    it('changeResolution changes resolution state', () => {
        wrapper.instance().changeResolution({value: 'value', text: 'text'});
 
        expect(wrapper.state('resolution')).to.deep.equal({value: 'value', text: 'text'});
    });
 
    it('activates when title, resolution has value', () => {
        wrapper.setState({title: 'some title'});
 
        expect(wrapper.find('.create-that-footer__create--inactive').exists()).to.be.true;
 
        wrapper.setState({resolution: {value: 'value', text: 'text'}});
 
        expect(wrapper.find('.create-that-footer__create--inactive').exists()).to.be.true;
 
        wrapper.setProps({contentNameExisted: 'NOT_EXIST'});
 
        expect(wrapper.find('.create-that-footer__create').exists()).to.be.true;
    });
 
    it('click on CREATE triggers onCreated prop with title, resolution', () => {
        const spyOnCreated = sinon.spy();
        wrapper.setProps({onCreated: spyOnCreated});
        wrapper.setState({title: 'some title', resolution: 'some resolution'});
        wrapper.setProps({contentNameExisted: 'NOT_EXIST'});
 
        wrapper.find('.create-that-footer__create').simulate('click');
 
        expect(spyOnCreated.calledWith('some title', 'some resolution')).to.be.true;
    });
 
    it('click on CANCEL triggers onCancel prop', () => {
        const spyOnCancel = sinon.spy();
 
        wrapper.setProps({onCancel: spyOnCancel});
 
        wrapper.find('.create-that-footer__cancel').simulate('click');
 
        expect(spyOnCancel.called).to.be.true;
    });
});