import React from 'react';
import {expect} from 'chai';
import {shallow} from "enzyme";
import sinon from 'sinon';
import ContextMenu from '../../../../src/component/popup/context-menu/context-menu';
describe('Context Menu Spec', () => {
const popupPosition = {x: 100, y: 200};
const spyOnRenameClick = sinon.spy();
const spyOnClose = sinon.spy();
const spyOnMoveToClick = sinon.spy();
const spyOnCopyToClick = sinon.spy();
let wrapper;
describe('on folder when type is undefined', () => {
beforeEach(() => {
wrapper = shallow(<ContextMenu onClose={spyOnClose} popupPosition={popupPosition}
onRenameClick={spyOnRenameClick}
/>).dive();
});
afterEach(() => {
spyOnRenameClick.reset();
});
it('set style left and top by props position', () => {
expect(wrapper.find('.context-menu-wrapper').at(0).getNode().props.style.left).to.equal(popupPosition.x);
expect(wrapper.find('.context-menu-wrapper').at(0).getNode().props.style.top).to.equal(popupPosition.y);
});
it('bind onRenameClick at context-menu-text onClick', () => {
wrapper.find('.context-menu-text').simulate('click');
expect(spyOnRenameClick.called).to.true;
});
});
describe('on contents item', () => {
beforeEach(() => {
wrapper = shallow(<ContextMenu close={spyOnClose} popupPosition={popupPosition}
onRenameClick={spyOnRenameClick}
onMoveToClick={spyOnMoveToClick}
onCopyToClick={spyOnCopyToClick}
type='playlist'
/>).dive();
});
afterEach(() => {
spyOnRenameClick.reset();
spyOnMoveToClick.reset();
spyOnCopyToClick.reset();
});
it('bind onMoveToClick at context-menu-text onClick', () => {
wrapper.find('.context-menu-text').at(0).simulate('click');
expect(spyOnMoveToClick.called).to.true;
});
it('bind onCopyClick at context-menu-text onClick', () => {
wrapper.find('.context-menu-text').at(1).simulate('click');
expect(spyOnCopyToClick.called).to.true;
});
it('bind onRenameClick at context-menu-text onClick', () => {
wrapper.find('.context-menu-text').at(2).simulate('click');
expect(spyOnRenameClick.called).to.true;
});
});
}); |