2018-04-20 11:23:37 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import TimeLine from '..';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2018-04-20 11:23:37 +08:00
|
|
|
|
|
|
|
const { Item } = TimeLine;
|
|
|
|
|
2020-02-26 17:21:44 +08:00
|
|
|
const wrapperFactory = (timeLineProps = {}, labelItems) =>
|
2018-12-07 16:17:45 +08:00
|
|
|
mount(
|
|
|
|
<TimeLine type="editable-card" {...timeLineProps}>
|
|
|
|
<Item key="1">foo</Item>
|
|
|
|
<Item key="2">bar</Item>
|
|
|
|
<Item key="3">baz</Item>
|
2020-02-26 17:21:44 +08:00
|
|
|
{labelItems}
|
2018-12-07 16:17:45 +08:00
|
|
|
</TimeLine>,
|
|
|
|
);
|
2018-04-20 11:23:37 +08:00
|
|
|
|
|
|
|
describe('TimeLine', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(TimeLine);
|
|
|
|
mountTest(TimeLine.Item);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(TimeLine);
|
|
|
|
rtlTest(TimeLine.Item);
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2018-04-20 11:23:37 +08:00
|
|
|
describe('renders items without passing any props correctly', () => {
|
|
|
|
const wrapper = wrapperFactory();
|
|
|
|
|
|
|
|
it('has 3 timeline item', () => {
|
|
|
|
expect(wrapper.find('li.ant-timeline-item')).toHaveLength(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has only 1 timeline item is marked as the last item', () => {
|
|
|
|
expect(wrapper.find('li.ant-timeline-item-last')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('its last item is marked as the last item', () => {
|
2020-10-21 10:35:06 +08:00
|
|
|
expect(wrapper.find('li.ant-timeline-item').last().hasClass('ant-timeline-item-last')).toBe(
|
|
|
|
true,
|
|
|
|
);
|
2018-04-20 11:23:37 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('renders pending item', () => {
|
|
|
|
const pending = <div>pending...</div>;
|
|
|
|
const pendingDot = <i>dot</i>;
|
|
|
|
|
|
|
|
it('has one extra timeline item', () => {
|
|
|
|
const wrapper = wrapperFactory({ pending });
|
|
|
|
expect(wrapper.find('li.ant-timeline-item')).toHaveLength(4);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has extra pending timeline item', () => {
|
|
|
|
const wrapper = wrapperFactory({ pending });
|
|
|
|
expect(wrapper.find('li.ant-timeline-item-pending')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
it("renders the pending timeline item as long as it receive a truthy prop value to 'pending'", () => {
|
2018-04-20 11:23:37 +08:00
|
|
|
const wrapper = wrapperFactory({ pending: true });
|
|
|
|
expect(wrapper.find('li.ant-timeline-item-pending')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('its last item is marked as the pending item', () => {
|
|
|
|
const wrapper = wrapperFactory({ pending });
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
2020-10-21 10:35:06 +08:00
|
|
|
wrapper.find('li.ant-timeline-item').last().hasClass('ant-timeline-item-pending'),
|
2018-12-07 16:17:45 +08:00
|
|
|
).toBe(true);
|
2018-04-20 11:23:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('its second to last item is marked as the last item', () => {
|
|
|
|
const wrapper = wrapperFactory({ pending });
|
|
|
|
const items = wrapper.find('li.ant-timeline-item');
|
|
|
|
expect(items.at(items.length - 2).hasClass('ant-timeline-item-last')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has the correct pending node', () => {
|
|
|
|
const wrapper = wrapperFactory({ pending });
|
|
|
|
expect(wrapper.find('li.ant-timeline-item-pending').contains(pending)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('has the correct pending dot node', () => {
|
|
|
|
const wrapper = wrapperFactory({ pending, pendingDot });
|
|
|
|
expect(wrapper.find('li.ant-timeline-item-pending').contains(pendingDot)).toBe(true);
|
|
|
|
});
|
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
it("has no pending dot if without passing a truthy 'pending' prop", () => {
|
2018-04-20 11:23:37 +08:00
|
|
|
const wrapper = wrapperFactory({ pendingDot });
|
|
|
|
expect(wrapper.find('li.ant-timeline-item-pending').contains(pendingDot)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('the item rendering sequence is controlled by reverse', () => {
|
|
|
|
it('items is in order when prop reverse is false', () => {
|
|
|
|
const wrapper = wrapperFactory({ reverse: false });
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(wrapper.find('.ant-timeline-item-content').map(w => w.text())).toEqual([
|
|
|
|
'foo',
|
|
|
|
'bar',
|
|
|
|
'baz',
|
|
|
|
]);
|
2018-04-20 11:23:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('items is reversed when prop reverse is true', () => {
|
|
|
|
const wrapper = wrapperFactory({ reverse: true });
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(wrapper.find('.ant-timeline-item-content').map(w => w.text())).toEqual([
|
|
|
|
'baz',
|
|
|
|
'bar',
|
|
|
|
'foo',
|
|
|
|
]);
|
2018-04-20 11:23:37 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('renders items reversely and with pending item', () => {
|
|
|
|
const pending = <div>pending...</div>;
|
|
|
|
|
|
|
|
it('its last item is marked as the last item', () => {
|
|
|
|
const wrapper = wrapperFactory({ pending, reverse: true });
|
2020-10-21 10:35:06 +08:00
|
|
|
expect(wrapper.find('li.ant-timeline-item').last().hasClass('ant-timeline-item-last')).toBe(
|
|
|
|
true,
|
|
|
|
);
|
2018-04-20 11:23:37 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('its first item is marked as the pending item', () => {
|
|
|
|
const wrapper = wrapperFactory({ pending, reverse: true });
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
2020-10-21 10:35:06 +08:00
|
|
|
wrapper.find('li.ant-timeline-item').first().hasClass('ant-timeline-item-pending'),
|
2018-12-07 16:17:45 +08:00
|
|
|
).toBe(true);
|
2018-04-20 11:23:37 +08:00
|
|
|
});
|
|
|
|
});
|
2020-02-26 17:21:44 +08:00
|
|
|
|
|
|
|
it('renders Timeline item with label correctly', () => {
|
|
|
|
const label = '2020-01-01';
|
|
|
|
const wrapper = wrapperFactory(
|
|
|
|
{},
|
|
|
|
<Item key="1" label={label}>
|
|
|
|
foo
|
|
|
|
</Item>,
|
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-timeline-label')).toHaveLength(1);
|
|
|
|
expect(wrapper.find('.ant-timeline-item-label').text()).toBe(label);
|
|
|
|
});
|
2018-04-20 11:23:37 +08:00
|
|
|
});
|