All files / nexshop-web-contents/spec/component/resolution-drop-down resolution-menu-spec.js

100% Statements 36/36
100% Branches 0/0
100% Functions 11/11
100% Lines 35/35
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 691x 1x 1x 1x 1x 1x   1x         4x   1x           1x   1x 6x 6x 6x       1x 1x     1x 1x   1x     1x 1x 1x     1x       1x 3x 3x     1x 1x 1x     1x 1x 1x     1x 1x 1x      
import React from 'react';
import {expect} from 'chai';
import sinon from 'sinon';
import ResolutionMenu from "../../../src/component/resolution-drop-down/resolution-menu";
import {shallow} from "enzyme";
import ResolutionItem from "../../../src/component/resolution-drop-down/resolution-item";
 
describe('ResolutionMenu Spec', () => {
    let wrapper;
    let spyOnItemSelected;
    let spyOnBlur;
 
    const createResolutionItem = (value, text) => ({value, text});
 
    const resolutionItems = [
        createResolutionItem('value1', 'text1'),
        createResolutionItem('value2', 'text2'),
        createResolutionItem('value3', 'text3'),
    ];
 
    const selectedItem = {...createResolutionItem('value1', 'text1'), orientation: 'some orientation'};
 
    beforeEach(() => {
        spyOnItemSelected = sinon.spy();
        spyOnBlur = sinon.spy();
        wrapper = shallow(<ResolutionMenu items={resolutionItems} onItemSelected={spyOnItemSelected}
                                          selectedItem={selectedItem} onBlur={spyOnBlur}/>);
    });
 
    it('draws number of items', () => {
        expect(wrapper.find(ResolutionItem).length).to.equal(3);
    });
 
    it('adds onBlur', () => {
        wrapper.find('.resolution-menu').simulate('blur');
 
        expect(spyOnBlur.called).to.be.true;                   
    });
 
    it('could not show selectedOrientation when selectedItem is not exist', () => {
        wrapper.setProps({selectedItem: undefined});
        expect(wrapper.find(ResolutionItem).at(0).prop('selectedOrientation')).to.equal('');
    });
 
    describe('ResolutionItem props', () => {
        let first;
        let last;
 
        beforeEach(() => {
            first = wrapper.find(ResolutionItem).at(0);
            last = wrapper.find(ResolutionItem).at(resolutionItems.length - 1);
        });
 
        it('has item', () => {
            expect(first.prop('item')).to.equal(resolutionItems[0]);
            expect(last.prop('item')).to.equal(resolutionItems[2]);
        });
 
        it('has onItemSelected as onSelected prop', () => {
            expect(first.prop('onSelected')).to.equal(spyOnItemSelected);
            expect(last.prop('onSelected')).to.equal(spyOnItemSelected);
        });
 
        it('has selected orientation as prop', () => {
            expect(first.prop('selectedOrientation')).to.equal('some orientation');
            expect(last.prop('selectedOrientation')).to.equal('');
        });
    });
});