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);
});
}); |