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

100% Statements 33/33
100% Branches 0/0
100% Functions 11/11
100% Lines 33/33
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 601x 1x 1x 1x 1x   1x     1x 5x     1x 1x     1x 1x     1x 1x 2x   2x   2x     1x 1x 1x       1x 1x 2x   2x 2x   2x     1x 1x 1x       1x 1x   1x   1x    
import React from 'react';
import {expect} from 'chai';
import sinon from 'sinon';
import ResolutionItem from "../../../src/component/resolution-drop-down/resolution-item";
import {shallow} from "enzyme";
 
describe('ResolutionItem Spec', () => {
    let wrapper;
 
    beforeEach(() => {
        wrapper = shallow(<ResolutionItem item={{value: 'value', text: 'text'}}/>)
    });
 
    it('shows resolution value', () => {
        expect(wrapper.find('.resolution-item__title').text()).to.equal('value');
    });
 
    it('shows resolution text', () => {
        expect(wrapper.find('.resolution-item__resolution').text()).to.equal('text');
    });
 
    describe('Selected Orientation', () => {
        const assertOrientationIsSelected = (orientation) => {
            expect(wrapper.find(`.resolution-item__${orientation}--selected`).length).to.equal(0);
 
            wrapper.setProps({selectedOrientation: orientation});
 
            expect(wrapper.find(`.resolution-item__${orientation}--selected`).length).to.equal(1);
        };
 
        it('changes orientation selected class depends on selectedOrientation', () => {
            assertOrientationIsSelected('horizontal');
            assertOrientationIsSelected('vertical');
        });
    });
 
    describe('Orientation is clicked', () => {
        const assertOnSelectedIsCalled = (orientation) => {
            const spyOnSelected = sinon.spy();
 
            wrapper.setProps({onSelected: spyOnSelected});
            wrapper.find(`.resolution-item__${orientation}`).simulate('click');
 
            expect(spyOnSelected.calledWith({value: 'value', text: 'text', orientation})).to.be.true;
        };
 
        it('calls onSelected props with orientation', () => {
            assertOnSelectedIsCalled('horizontal');
            assertOnSelectedIsCalled('vertical');
        });
    });
    
    it('includes divider when includeDivider is true', () => {
        expect(wrapper.find('.resolution-item__divider').length).to.equal(0);
 
        wrapper.setProps({includeDivider: true});
        
        expect(wrapper.find('.resolution-item__divider').length).to.equal(1);
    });
});