-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test(timeline): unit tests * test(timeline): add unit tests * test: timeline unit tests * test(timeline): skip failed test in temp
- Loading branch information
Showing
9 changed files
with
286 additions
and
21 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
src/timeline/__tests__/__snapshots__/vitest-timeline.test.jsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`TimelineItem Component > props.children works fine 1`] = ` | ||
<div> | ||
<li | ||
class="t-timeline-item t-timeline-item-left" | ||
> | ||
<div | ||
class="t-timeline-item__wrapper" | ||
> | ||
<div | ||
class="t-timeline-item__dot t-timeline-item__dot--primary" | ||
/> | ||
<div | ||
class="t-timeline-item__tail t-timeline-item__tail--theme-default" | ||
/> | ||
</div> | ||
<div | ||
class="t-timeline-item__content" | ||
> | ||
<span | ||
class="custom-node" | ||
> | ||
TNode | ||
</span> | ||
</div> | ||
</li> | ||
</div> | ||
`; | ||
|
||
exports[`TimelineItem Component > props.content works fine 1`] = ` | ||
<div> | ||
<li | ||
class="t-timeline-item t-timeline-item-left" | ||
> | ||
<div | ||
class="t-timeline-item__wrapper" | ||
> | ||
<div | ||
class="t-timeline-item__dot t-timeline-item__dot--primary" | ||
/> | ||
<div | ||
class="t-timeline-item__tail t-timeline-item__tail--theme-default" | ||
/> | ||
</div> | ||
<div | ||
class="t-timeline-item__content" | ||
> | ||
<span | ||
class="custom-node" | ||
> | ||
TNode | ||
</span> | ||
</div> | ||
</li> | ||
</div> | ||
`; | ||
|
||
exports[`TimelineItem Component > props.label works fine 1`] = ` | ||
<div> | ||
<li | ||
class="t-timeline-item t-timeline-item-left" | ||
> | ||
<div | ||
class="t-timeline-item__label t-timeline-item__label--alternate" | ||
> | ||
<span | ||
class="custom-node" | ||
> | ||
TNode | ||
</span> | ||
</div> | ||
<div | ||
class="t-timeline-item__wrapper" | ||
> | ||
<div | ||
class="t-timeline-item__dot t-timeline-item__dot--primary" | ||
/> | ||
<div | ||
class="t-timeline-item__tail t-timeline-item__tail--theme-default" | ||
/> | ||
</div> | ||
<div | ||
class="t-timeline-item__content" | ||
/> | ||
</li> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import { render } from '@test/utils'; | ||
import { Timeline } from '../../timeline'; | ||
|
||
export function getTimelineDefaultMount(Timeline, props, events) { | ||
return render( | ||
<Timeline {...props} {...events}> | ||
<Timeline.Item label="2022-01-01">Event1</Timeline.Item> | ||
<Timeline.Item label="2022-02-01">Event2</Timeline.Item> | ||
<Timeline.Item label="2022-03-01">Event3</Timeline.Item> | ||
<Timeline.Item label="2022-04-01" dotColor="yellowgreen">Event4</Timeline.Item> | ||
</Timeline> | ||
); | ||
} | ||
|
||
// labelAlign 优先级比较 | ||
export function getTimelineItemMount(TimelineItem, props) { | ||
return render( | ||
<Timeline labelAlign='right'> | ||
<TimelineItem {...props} label="2022-01-01">Event1</TimelineItem> | ||
<TimelineItem label="2022-02-01">Event2</TimelineItem> | ||
<TimelineItem label="2022-03-01">Event3</TimelineItem> | ||
<TimelineItem label="2022-04-01">Event4</TimelineItem> | ||
</Timeline> | ||
); | ||
} | ||
|
||
export default getTimelineDefaultMount |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/** | ||
* 该文件由脚本自动生成,如需修改请联系 PMC | ||
* This file generated by scripts of tdesign-api. `npm run api:docs Timeline React(PC) vitest,finalProject` | ||
* If you need to modify this file, contact PMC first please. | ||
*/ | ||
import React from 'react'; | ||
import { fireEvent, vi, render } from '@test/utils'; | ||
import { Timeline, TimelineItem } from '..'; | ||
import { getTimelineDefaultMount, getTimelineItemMount } from './mount'; | ||
|
||
describe('Timeline Component', () => { | ||
const labelAlignClassNameMap = { | ||
left: 't-timeline-left', | ||
alternate: 't-timeline-alternate', | ||
right: 't-timeline-right', | ||
}; | ||
Object.entries(labelAlignClassNameMap).forEach(([enumValue, expectedClassName]) => { | ||
it(`props.labelAlign is equal to ${enumValue}`, () => { | ||
let propValue = { true: true, false: false }[enumValue]; | ||
propValue = propValue === undefined ? enumValue : propValue; | ||
const { container } = getTimelineDefaultMount(Timeline, { labelAlign: propValue }); | ||
expect(container.firstChild).toHaveClass(expectedClassName); | ||
}); | ||
}); | ||
|
||
it('props.labelAlign: layout=horizontal labelAlign=top works fine', () => { | ||
const { container } = getTimelineDefaultMount(Timeline, { layout: 'horizontal', labelAlign: 'top' }); | ||
const domWrapper = container.querySelector('.t-timeline'); | ||
expect(domWrapper).toHaveClass('t-timeline-top'); | ||
}); | ||
it('props.labelAlign: layout=horizontal labelAlign=bottom works fine', () => { | ||
const { container } = getTimelineDefaultMount(Timeline, { layout: 'horizontal', labelAlign: 'bottom' }); | ||
const domWrapper = container.querySelector('.t-timeline'); | ||
expect(domWrapper).toHaveClass('t-timeline-bottom'); | ||
}); | ||
|
||
['horizontal', 'vertical'].forEach((item) => { | ||
it(`props.layout is equal to ${item}`, () => { | ||
const { container } = getTimelineDefaultMount(Timeline, { layout: item }); | ||
expect(container.firstChild).toHaveClass(`t-timeline-${item}`); | ||
}); | ||
}); | ||
|
||
['alternate', 'same'].forEach((item) => { | ||
it(`props.mode is equal to ${item}`, () => { | ||
const { container } = render(<Timeline mode={item}></Timeline>); | ||
expect(container.firstChild).toHaveClass(`t-timeline-label--${item}`); | ||
}); | ||
}); | ||
|
||
it('props.reverse is equal true', () => { | ||
const { container } = getTimelineDefaultMount(Timeline, { reverse: true }); | ||
expect(container.querySelector('.t-timeline-item__content').textContent).toBe('Event4'); | ||
}); | ||
|
||
it('props.theme is equal dot', () => { | ||
const { container } = getTimelineDefaultMount(Timeline, { theme: 'dot' }); | ||
expect(container.querySelectorAll('.t-timeline-item__tail--theme-dot').length).toBe(4); | ||
}); | ||
}); | ||
|
||
describe('TimelineItem Component', () => { | ||
it('props.children works fine', () => { | ||
const { container } = render( | ||
<TimelineItem> | ||
<span className="custom-node">TNode</span> | ||
</TimelineItem>, | ||
); | ||
expect(container.querySelector('.custom-node')).toBeTruthy(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('props.content works fine', () => { | ||
const { container } = render(<TimelineItem content={<span className="custom-node">TNode</span>}></TimelineItem>); | ||
expect(container.querySelector('.custom-node')).toBeTruthy(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('props.dot works fine', () => { | ||
const { container } = render(<TimelineItem dot={<span className="custom-node">TNode</span>}></TimelineItem>); | ||
expect(container.querySelector('.custom-node')).toBeTruthy(); | ||
}); | ||
|
||
const dotColorClassNameMap = { | ||
primary: 't-timeline-item__dot--primary', | ||
warning: 't-timeline-item__dot--warning', | ||
error: 't-timeline-item__dot--error', | ||
default: 't-timeline-item__dot--default', | ||
}; | ||
Object.entries(dotColorClassNameMap).forEach(([enumValue, expectedClassName]) => { | ||
it(`props.dotColor is equal to ${enumValue}`, () => { | ||
let propValue = { true: true, false: false }[enumValue]; | ||
propValue = propValue === undefined ? enumValue : propValue; | ||
const wrapper = render(<TimelineItem dotColor={propValue}></TimelineItem>); | ||
const container = wrapper.container.querySelector('.t-timeline-item__dot'); | ||
expect(container).toHaveClass(expectedClassName); | ||
}); | ||
}); | ||
|
||
it(`props.dotColor is equal to yellowgreen`, () => { | ||
const { container } = render(<TimelineItem dotColor="yellowgreen"></TimelineItem>); | ||
const domWrapper = container.querySelector('.t-timeline-item__dot'); | ||
expect(domWrapper.style.borderColor).toBe('yellowgreen'); | ||
}); | ||
|
||
it('props.label works fine', () => { | ||
const { container } = render(<TimelineItem label={<span className="custom-node">TNode</span>}></TimelineItem>); | ||
expect(container.querySelector('.custom-node')).toBeTruthy(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it.skip('props.labelAlign is equal left', () => { | ||
const { container } = getTimelineItemMount(TimelineItem, { labelAlign: 'left' }); | ||
expect(container.querySelectorAll('.t-timeline-item:first-child .t-timeline-item-left').length).toBe(1); | ||
}); | ||
|
||
it('props.loading: TimelineItem contains element `.t-timeline-item__dot .t-loading`', () => { | ||
// loading default value is | ||
const { container } = render(<TimelineItem></TimelineItem>); | ||
expect(container.querySelector('.t-timeline-item__dot .t-loading')).toBeFalsy(); | ||
// loading = false | ||
const { container: container1 } = render(<TimelineItem loading={false}></TimelineItem>); | ||
expect(container1.querySelector('.t-timeline-item__dot .t-loading')).toBeFalsy(); | ||
// loading = true | ||
const { container: container2 } = render(<TimelineItem loading={true}></TimelineItem>); | ||
expect(container2.querySelector('.t-timeline-item__dot .t-loading')).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import _Timeline from './Timeline'; | ||
import _TimelineItem from './TimelineItem'; | ||
|
||
import './style/index.js'; | ||
|
||
export type { TimelineProps } from './Timeline'; | ||
|
||
export const Timeline = _Timeline; | ||
export const TimelineItem = _TimelineItem; | ||
|
||
export default Timeline; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
:: BASE_DOC :: | ||
|
||
## API | ||
### Timeline Props | ||
|
||
name | type | default | description | required | ||
-- | -- | -- | -- | -- | ||
className | String | - | 类名 | N | ||
style | Object | - | 样式,Typescript:`React.CSSProperties` | N | ||
labelAlign | String | left | label info placement。options:left/right/alternate/top/bottom | N | ||
layout | String | vertical | time line layout。options:horizontal/vertical | N | ||
mode | String | alternate | The position relationship between the label and the content text, 'alternate' is displayed on both sides of the axis, and 'same' is displayed on the same side。options:alternate/same | N | ||
reverse | Boolean | false | \- | N | ||
theme | String | default | options:default/dot | N | ||
|
||
### TimelineItem Props | ||
|
||
name | type | default | description | required | ||
-- | -- | -- | -- | -- | ||
className | String | - | 类名 | N | ||
style | Object | - | 样式,Typescript:`React.CSSProperties` | N | ||
children | TNode | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N | ||
content | TNode | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N | ||
dot | TElement | - | Typescript:`TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N | ||
dotColor | String | primary | Typescript:`string` | N | ||
label | TNode | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N | ||
labelAlign | String | - | options:left/right/top/bottom | N | ||
loading | Boolean | - | Whether it is in the loading state | N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters