-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: unit test(data-picker、skeleton、static-data-picker、static-data-r…
…ange-picker、static-time-picker) (#2022) * test: unit test * feat(input-button): support loading prop (#2023) * feat(input-button): support loading prop * test(input-button): add case Co-authored-by: maxin <maxin@growingio.com> * chore(deps): bump moment from 2.29.1 to 2.29.2 Bumps [moment](https://github.com/moment/moment) from 2.29.1 to 2.29.2. - [Release notes](https://github.com/moment/moment/releases) - [Changelog](https://github.com/moment/moment/blob/develop/CHANGELOG.md) - [Commits](moment/moment@2.29.1...2.29.2) --- updated-dependencies: - dependency-name: moment dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps-dev): bump typescript from 4.5.3 to 4.6.4 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.5.3 to 4.6.4. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](microsoft/TypeScript@v4.5.3...v4.6.4) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump crowdin/github-action from 1.4.7 to 1.4.8 Bumps [crowdin/github-action](https://github.com/crowdin/github-action) from 1.4.7 to 1.4.8. - [Release notes](https://github.com/crowdin/github-action/releases) - [Commits](crowdin/github-action@1.4.7...1.4.8) --- updated-dependencies: - dependency-name: crowdin/github-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump rc-util from 5.18.1 to 5.21.4 Bumps [rc-util](https://github.com/react-component/util) from 5.18.1 to 5.21.4. - [Release notes](https://github.com/react-component/util/releases) - [Changelog](https://github.com/react-component/util/blob/master/HISTORY.md) - [Commits](react-component/util@v5.18.1...v5.21.4) --- updated-dependencies: - dependency-name: rc-util dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump react-dnd-html5-backend from 14.1.0 to 16.0.1 Bumps [react-dnd-html5-backend](https://github.com/react-dnd/react-dnd) from 14.1.0 to 16.0.1. - [Release notes](https://github.com/react-dnd/react-dnd/releases) - [Changelog](https://github.com/react-dnd/react-dnd/blob/main/CHANGELOG.md) - [Commits](https://github.com/react-dnd/react-dnd/commits) --- updated-dependencies: - dependency-name: react-dnd-html5-backend dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * test(form): add test cases (#2019) * test(checkbox): add test case * test(result): add test cases * refactor(result): remove test file unused references * test(switch): add test cases * test(form): add test cases * ci(sonar): ignore case * ci(sonar): config ignore rule * docs(steps): add steps storybook (#2013) Co-authored-by: vermilionAnd <zhujiahong@growingio> * docs(toggle): add toggle storybook (#2009) Co-authored-by: vermilionAnd <zhujiahong@growingio> Co-authored-by: maxin <48519459+nnmax@users.noreply.github.com> Co-authored-by: maxin <maxin@growingio.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: gavin <haozhigang@outlook.com> Co-authored-by: vermilionAnd <61216850+zhuzilv@users.noreply.github.com> Co-authored-by: vermilionAnd <zhujiahong@growingio>
- Loading branch information
1 parent
7b8d1e3
commit fdbbf67
Showing
8 changed files
with
286 additions
and
11 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { format } from 'date-fns'; | ||
import Button from '../../button'; | ||
import DatePicker from '../DatePicker'; | ||
|
||
describe('Testing DatePicker ', () => { | ||
it('render without params', () => { | ||
const { container } = render(<DatePicker />); | ||
expect(container.querySelector('input[type="button"]')).toBeTruthy(); | ||
}); | ||
|
||
it('render has trigger params', () => { | ||
const { container } = render( | ||
<DatePicker | ||
trigger={<Button type="secondary">{format(new Date(), '您的所选时间为 yyyy-MM-dd HH:mm:ss')}</Button>} | ||
/> | ||
); | ||
expect(container.querySelectorAll('您的所选时间为')).toBeTruthy(); | ||
}); | ||
|
||
it('render has format', () => { | ||
const { container } = render(<DatePicker format="yyyy/MM/dd hh:mm" />); | ||
expect(container.querySelector('input[type="button"]')).toBeTruthy(); | ||
}); | ||
|
||
it('render has dataTestId', () => { | ||
const { container } = render(<DatePicker dataTestId="test" />); | ||
expect(container.querySelector('input[data-testId="test"]')).toBeTruthy(); | ||
expect(container.querySelector('input[data-testId="dataPicker"]')).toBeFalsy(); | ||
}); | ||
|
||
it('operation', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
render(<DatePicker format="yyyy/MM/dd hh:mm" onVisibleChange={() => {}} onSelect={() => {}} />); | ||
|
||
fireEvent.click(screen.getByRole('button')); | ||
|
||
expect(screen.getByText('12')).toBeTruthy(); | ||
|
||
fireEvent.click(screen.getByText('12')); | ||
|
||
expect(screen.getByTestId('dataPicker').title).toMatch('/12'); | ||
}); | ||
|
||
it('operation without params', () => { | ||
render(<DatePicker format="yyyy/MM/dd hh:mm" />); | ||
|
||
fireEvent.click(screen.getByRole('button')); | ||
|
||
expect(screen.getByText('12')).toBeTruthy(); | ||
|
||
fireEvent.click(screen.getByText('12')); | ||
|
||
expect(screen.getByTestId('dataPicker').title).toMatch('/12'); | ||
}); | ||
}); |
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,53 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import SkeletonImage from '../Image'; | ||
import Skeleton from '../Skeleton'; | ||
|
||
describe('Testing Skeleton ', () => { | ||
it('without params', () => { | ||
render(<Skeleton />); | ||
expect(screen.getByTestId('skeleton')).toBeTruthy(); | ||
}); | ||
|
||
it('has params', () => { | ||
const { container } = render( | ||
<Skeleton loading delay={500} paragraph={{ row: 4, width: '100%' }} active={false} avatar={{ size: 'small' }} /> | ||
); | ||
expect(container.getElementsByClassName('gio-skeleton-paragraph')[0].getElementsByTagName('p').length).toBe(4); | ||
}); | ||
|
||
it('has title paragraph', () => { | ||
const { container } = render(<Skeleton paragraph={{ row: 4, width: '100%' }} title />); | ||
expect(container.getElementsByClassName('gio-skeleton-title').length).toBe(1); | ||
expect(container.getElementsByClassName('gio-skeleton-paragraph')[0].getElementsByTagName('p').length).toBe(4); | ||
}); | ||
|
||
it('has only title', () => { | ||
const { container } = render(<Skeleton title />); | ||
expect(container.getElementsByClassName('gio-skeleton-title').length).toBe(1); | ||
}); | ||
|
||
it('rowWidth is array', () => { | ||
const { container } = render(<Skeleton paragraph={{ row: 3, width: [200, 300, '100%'] }} />); | ||
expect(container.getElementsByClassName('gio-skeleton-paragraph')[0].getElementsByTagName('p').length).toBe(3); | ||
expect(container.getElementsByClassName('gio-skeleton-paragraph')[0].getElementsByTagName('p')[0].style.width).toBe( | ||
'200px' | ||
); | ||
}); | ||
|
||
it('loading is false', () => { | ||
render(<Skeleton loading={false}>内容</Skeleton>); | ||
expect(screen.getByText('内容')).toBeTruthy(); | ||
}); | ||
|
||
it('SkeletonImage', () => { | ||
const { container } = render(<SkeletonImage delay={500} width={200} color="#000000" />); | ||
expect(container.getElementsByClassName('gio-skeleton-image').length).toBe(1); | ||
}); | ||
|
||
it('SkeletonImage loading false', () => { | ||
const { container } = render(<SkeletonImage loading={false}>内容</SkeletonImage>); | ||
expect(container.getElementsByClassName('gio-skeleton-image').length).toBe(0); | ||
expect(screen.getByText('内容')).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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import StaticDatePicker from '../StaticDatePicker'; | ||
|
||
describe('Testing StaticDatePicker ', () => { | ||
it('without params', () => { | ||
render(<StaticDatePicker />); | ||
expect(screen.getByText('12')).toBeTruthy(); | ||
}); | ||
|
||
it('disabledDate is function', () => { | ||
render(<StaticDatePicker disabledDate={(current: Date) => current.getTime() > new Date().getTime()} />); | ||
expect(screen.getByText('12')).toBeTruthy(); | ||
}); | ||
|
||
it('onPanelChange has onPanelChange', () => { | ||
const { container } = render( | ||
<StaticDatePicker | ||
disabledDate={(current: Date) => current.getTime() > new Date().getTime()} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
onPanelChange={() => {}} | ||
/> | ||
); | ||
|
||
fireEvent.click(container.querySelector('button[class="gio-picker-header-super-prev-btn"]')); | ||
|
||
expect(screen.getByText('12')).toBeTruthy(); | ||
|
||
fireEvent.click(container.querySelector('button[class="gio-picker-header-prev-btn"]')); | ||
|
||
expect(screen.getByText('12')).toBeTruthy(); | ||
|
||
fireEvent.click(screen.getByText('12')); | ||
|
||
expect(screen.getByText('12')).toBeTruthy(); | ||
}); | ||
|
||
it('onPanelChange not onPanelChange', () => { | ||
const { container } = render( | ||
<StaticDatePicker disabledDate={(current: Date) => current.getTime() > new Date().getTime()} /> | ||
); | ||
|
||
fireEvent.click(container.querySelector('button[class="gio-picker-header-super-prev-btn"]')); | ||
|
||
expect(screen.getByText('12')).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { startOfToday, subMonths } from 'date-fns'; | ||
import StaticDateRangePicker from '../StaticDateRangePicker'; | ||
|
||
describe('Testing StaticDatePicker ', () => { | ||
it('without params', () => { | ||
const { container } = render(<StaticDateRangePicker />); | ||
expect(container.querySelector('div[class="gio-date-range-picker"]')).toBeTruthy(); | ||
}); | ||
|
||
it('onPanelChange has onPanelChange', () => { | ||
const { container } = render( | ||
<StaticDateRangePicker | ||
disabledDate={(current: Date) => current.getTime() > new Date().getTime()} | ||
defaultViewDates={[subMonths(startOfToday(), 1), startOfToday()]} | ||
/> | ||
); | ||
|
||
fireEvent.click( | ||
container.querySelector('.gio-date-range-picker__left button[class="gio-picker-header-super-prev-btn"]') | ||
); | ||
|
||
expect(container.querySelector('div[class="gio-picker-cell-inner"]')).toBeTruthy(); | ||
|
||
fireEvent.click( | ||
container.querySelector('.gio-date-range-picker__right button[class="gio-picker-header-super-next-btn"]') | ||
); | ||
|
||
expect(container.querySelector('div[class="gio-picker-cell-inner"]')).toBeTruthy(); | ||
}); | ||
|
||
it('left right', () => { | ||
const { container } = render( | ||
<StaticDateRangePicker defaultValue={[new Date('2022-03-01'), new Date('2022-04-01')]} /> | ||
); | ||
|
||
fireEvent.click(container.querySelector('td[title="2022-04-02"] .gio-picker-cell-inner')); | ||
|
||
fireEvent.click(container.querySelector('td[title="2022-04-11"] .gio-picker-cell-inner')); | ||
|
||
expect(container.querySelector('div[class="gio-picker-cell-inner"]')).toBeTruthy(); | ||
}); | ||
|
||
it('has function', () => { | ||
const { container } = render( | ||
<StaticDateRangePicker | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
onDateMouseEnter={() => {}} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
onDateMouseLeave={() => {}} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
onSelect={() => {}} | ||
defaultValue={[new Date('2022-03-01'), new Date('2022-04-01')]} | ||
/> | ||
); | ||
|
||
fireEvent.click(container.querySelector('td[title="2022-04-02"] .gio-picker-cell-inner')); | ||
|
||
fireEvent.mouseEnter(container.querySelector('td[title="2022-04-10"] .gio-picker-cell-inner')); | ||
|
||
fireEvent.mouseLeave(container.querySelector('td[title="2022-04-10"] .gio-picker-cell-inner')); | ||
|
||
fireEvent.click(container.querySelector('td[title="2022-04-11"] .gio-picker-cell-inner')); | ||
|
||
expect(container.querySelector('div[class="gio-picker-cell-inner"]')).toBeTruthy(); | ||
}); | ||
|
||
it('not function', () => { | ||
const { container } = render( | ||
<StaticDateRangePicker defaultValue={[new Date('2022-03-01'), new Date('2022-04-01')]} /> | ||
); | ||
|
||
fireEvent.mouseEnter(container.querySelector('td[title="2022-04-10"] .gio-picker-cell-inner')); | ||
|
||
fireEvent.mouseLeave(container.querySelector('td[title="2022-04-10"] .gio-picker-cell-inner')); | ||
|
||
expect(container.querySelector('div[class="gio-picker-cell-inner"]')).toBeTruthy(); | ||
}); | ||
|
||
it('has defaultViewDates', () => { | ||
const { container } = render( | ||
<StaticDateRangePicker defaultValue={[new Date('2022-03-01'), new Date('2022-04-01')]} /> | ||
); | ||
|
||
fireEvent.mouseEnter(container.querySelector('td[title="2022-04-10"] .gio-picker-cell-inner')); | ||
|
||
fireEvent.mouseLeave(container.querySelector('td[title="2022-04-10"] .gio-picker-cell-inner')); | ||
|
||
expect(container.querySelector('div[class="gio-picker-cell-inner"]')).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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import StaticTimePicker from '../StaticTimePicker'; | ||
|
||
describe('Testing StaticTimePicker ', () => { | ||
it('without params', () => { | ||
render(<StaticTimePicker />); | ||
expect(screen.getByText('59')).toBeTruthy(); | ||
}); | ||
|
||
it('showSecond', () => { | ||
render(<StaticTimePicker showSecond />); | ||
expect(screen.getAllByText('59').length).toBe(2); | ||
}); | ||
}); |
fdbbf67
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
gio-design – ./
gio-design-git-master-growingio.vercel.app
gio-design-growingio.vercel.app
gio-design.vercel.app