| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 | import React from 'react';import { mount } from 'enzyme';import sinon from 'sinon';import { stepsClasses } from '@douyinfe/semi-foundation/steps/constants';import Steps from '../index';import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';const Step = Steps.Step;describe('Steps', () => {    it('current works', () => {        const element = (            <Steps current={0}>                <Step>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const wrapper = mount(element);        expect(            wrapper                .find('Step')                .at(0)                .props().status        ).toEqual('process');    });    it('parent status works', () => {        const wait = (            <Steps status="wait" current={0}>                <Step>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const waitWrapper = mount(wait);        expect(            waitWrapper.props().status        ).toEqual('wait');        waitWrapper.unmount();        const error = (            <Steps status="error" current={0}>                <Step>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const errorWrapper = mount(error);        expect(            errorWrapper.props().status        ).toEqual('error');        errorWrapper.unmount();        const finish = (            <Steps status="finish" current={0}>                <Step>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const finishWrapper = mount(finish);        expect(            finishWrapper.props().status        ).toEqual('finish');        finishWrapper.unmount();        const process = (            <Steps status="process" current={0}>                <Step>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const processWrapper = mount(process);        expect(            processWrapper.props().status        ).toEqual('process');        processWrapper.unmount();        const warning = (            <Steps status="warning" current={0}>                <Step>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const warningWrapper = mount(warning);        expect(            warningWrapper.props().status        ).toEqual('warning');        warningWrapper.unmount();    });    it('child status works', () => {        const wait = (            <Steps current={0}>                <Step status="wait">Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const waitWrapper = mount(wait);        expect(            waitWrapper                .find('Step')                .at(0)                .props().status        ).toEqual('wait');        waitWrapper.unmount();        const error = (            <Steps current={0}>                <Step status="error">Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const errorWrapper = mount(error);        expect(            errorWrapper                .find('Step')                .at(0)                .props().status        ).toEqual('error');        errorWrapper.unmount();        const finish = (            <Steps current={0}>                <Step status="finish">Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const finishWrapper = mount(finish);        expect(            finishWrapper                .find('Step')                .at(0)                .props().status        ).toEqual('finish');        finishWrapper.unmount();        const process = (            <Steps current={0}>                <Step status="process">Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const processWrapper = mount(process);        expect(            processWrapper                .find('Step')                .at(0)                .props().status        ).toEqual('process');        processWrapper.unmount();        const warning = (            <Steps current={0}>                <Step status="warning">Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const warningWrapper = mount(warning);        expect(            warningWrapper                .find('Step')                .at(0)                .props().status        ).toEqual('warning');        warningWrapper.unmount();    });    it('initial works', () => {        const element = (            <Steps status="warning" initial={1} current={1}>                <Step>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const wrapper = mount(element);        expect(            wrapper                .find('Step')                .at(0)                .props().status        ).toEqual('warning');    });    it('FillStep onClick works', () => {        const spyOnClick = sinon.fake();        const element = (            <Steps status="warning" initial={1} current={1}>                <Step onClick={spyOnClick}>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const wrapper = mount(element);        const fiestStepContainer = wrapper.find('Step').at(0).find(`.${stepsClasses.ITEM}`);        fiestStepContainer.simulate('click');        expect(spyOnClick.calledOnce).toEqual(true);    });    it('BasicStep onClick works', () => {        const spyOnClick = sinon.fake();        const element = (            <Steps type='basic' status="warning" initial={1} current={1}>                <Step onClick={spyOnClick}>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const wrapper = mount(element);        const fiestStepContainer = wrapper.find('Step').at(0).find(`.${stepsClasses.ITEM}`);        fiestStepContainer.simulate('click');        expect(spyOnClick.calledOnce).toEqual(true);    });    it('NavStep onClick works', () => {        const spyOnClick = sinon.fake();        const element = (            <Steps type='nav' status="warning" initial={1} current={1}>                <Step onClick={spyOnClick}>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const wrapper = mount(element);        const fiestStepContainer = wrapper.find('Step').at(0).find(`.${stepsClasses.ITEM}`);        fiestStepContainer.simulate('click');        expect(spyOnClick.calledOnce).toEqual(true);    });    it('Steps onChange works', () => {        const spyOnChange = sinon.fake();        const element = (            <Steps status="warning" initial={1} onChange={spyOnChange} current={1}>                <Step>Step.1</Step>                <Step>Step.1</Step>                <Step>Step.1</Step>            </Steps>        );        const wrapper = mount(element);        const fiestStepContainer = wrapper.find('Step').at(1).find(`.${stepsClasses.ITEM}`);        fiestStepContainer.simulate('click');        expect(spyOnChange.calledOnce).toEqual(false);        const fiestStepContainer2 = wrapper.find('Step').at(0).find(`.${stepsClasses.ITEM}`);        fiestStepContainer2.simulate('click');        expect(spyOnChange.calledOnce).toEqual(true);    });    it('Steps type', () => {        const nav = (            <Steps type="nav" current={1}>                <Step title="Finished" />                <Step title="In Progress" />                <Step title="Waiting" />            </Steps>        );        const navWrapper = mount(nav);        expect(navWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-nav`)).toEqual(true);        navWrapper.unmount();        const basic = (            <Steps type="basic" current={1}>                <Step title="Finished" />                <Step title="In Progress" />                <Step title="Waiting" />            </Steps>        );        const basicWrapper = mount(basic);        expect(basicWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-basic`)).toEqual(true);        basicWrapper.unmount();        const fill = (            <Steps type="fill" current={1}>                <Step title="Finished" />                <Step title="In Progress" />                <Step title="Waiting" />            </Steps>        );        const fillWrapper = mount(fill);        expect(fillWrapper.exists(`.${BASE_CLASS_PREFIX}-steps`)).toEqual(true);        fillWrapper.unmount();    });    it('Steps with custom className & style', () => {        const wrapper = mount(            <Steps className='test' style={{ color: 'red' }}>                <Step title="Finished" />                <Step title="In Progress" />                <Step title="Waiting" />            </Steps>        );        expect(wrapper.exists('.test')).toEqual(true);        expect(wrapper.find(`.${BASE_CLASS_PREFIX}-steps.test`)).toHaveStyle('color', 'red');    });    it('Step with custom className & style', () => {        const wrapper = mount(            <Steps >                <Step className='test' style={{ color: 'blue' }} title="Finished" />                <Step title="In Progress" />                <Step title="Waiting" />            </Steps>        );        const firstStep = wrapper.find('Step').at(0);        expect(firstStep.exists('.test')).toEqual(true);        expect(firstStep).toHaveStyle('color', 'blue');    });    it('Steps with size', () => {        const wrapper = mount(            <Steps type="basic" size='small'>                <Step className='test' style={{ color: 'red' }} title="Finished" />                <Step title="In Progress" />                <Step title="Waiting" />            </Steps>        );        expect(wrapper.exists(`.${BASE_CLASS_PREFIX}-steps-small`)).toEqual(true);    });    it('Steps with hasLine', () => {        const hasLineWrapper = mount(            <Steps type="basic" hasLine={true} current={1}>                <Step title="Finished" description="This is a description" />                <Step title="In Progress" description="This is a description" />                <Step title="Waiting" description="This is a description" />            </Steps>        );        expect(hasLineWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-hasline`)).toEqual(true);        hasLineWrapper.unmount();        const noLineWrapper = mount(            <Steps type="basic" hasLine={false} current={1}>                <Step title="Finished" description="This is a description" />                <Step title="In Progress" description="This is a description" />                <Step title="Waiting" description="This is a description" />            </Steps>        );        expect(noLineWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-hasline`)).toEqual(false);        noLineWrapper.unmount();    });    it('Steps with direction', () => {        const verticalWrapper = mount(            <Steps direction="vertical" type="basic" current={1}>                <Steps.Step title="Finished" description="This is a description" />                <Steps.Step title="In Progress" description="This is a description" />                <Steps.Step title="Waiting" description="This is a description" />            </Steps>        );        expect(verticalWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-vertical`)).toEqual(true);        verticalWrapper.unmount();        const horizontalWrapper = mount(            <Steps direction="horizontal" type="basic" current={1}>                <Steps.Step title="Finished" description="This is a description" />                <Steps.Step title="In Progress" description="This is a description" />                <Steps.Step title="Waiting" description="This is a description" />            </Steps>        );        expect(horizontalWrapper.exists(`.${BASE_CLASS_PREFIX}-steps-horizontal`)).toEqual(true);        horizontalWrapper.unmount();    });});
 |