All files / nexshop-web-contents/spec/component/popup/context-menu context-menu-spec.js

100% Statements 38/38
100% Branches 0/0
100% Functions 12/12
100% Lines 38/38
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 731x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x     1x 1x 2x         1x 2x     1x 1x 1x     1x 1x   1x       1x 1x 3x               1x 3x 3x 3x     1x 1x   1x     1x 1x   1x     1x 1x   1x        
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;
        });
    });
 
});