-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve(design): Set required to true for Form.Item with Switch to hi…
…de optional mark
- Loading branch information
1 parent
9c3461d
commit 33e2bf4
Showing
3 changed files
with
371 additions
and
1 deletion.
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
296 changes: 296 additions & 0 deletions
296
packages/design/src/form/__tests__/__snapshots__/switch.test.tsx.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,296 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Form.Item with Switch > dynamic Switch 1`] = ` | ||
<form | ||
class="ant-form ant-form-horizontal" | ||
> | ||
<div | ||
class="ant-form-item" | ||
> | ||
<div | ||
class="ant-row ant-form-item-row" | ||
> | ||
<div | ||
class="ant-col ant-form-item-label" | ||
> | ||
<label | ||
class="ant-form-item-required ant-form-item-required-mark-optional" | ||
for="switch" | ||
title="Switch" | ||
> | ||
Switch | ||
</label> | ||
</div> | ||
<div | ||
class="ant-col ant-form-item-control" | ||
> | ||
<div | ||
class="ant-form-item-control-input" | ||
> | ||
<div | ||
class="ant-form-item-control-input-content" | ||
> | ||
<button | ||
aria-checked="false" | ||
aria-required="true" | ||
class="ant-switch" | ||
id="switch" | ||
role="switch" | ||
type="button" | ||
> | ||
<div | ||
class="ant-switch-handle" | ||
/> | ||
<span | ||
class="ant-switch-inner" | ||
> | ||
<span | ||
class="ant-switch-inner-checked" | ||
/> | ||
<span | ||
class="ant-switch-inner-unchecked" | ||
/> | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
`; | ||
|
||
exports[`Form.Item with Switch > nested Switch 1`] = ` | ||
<form | ||
class="ant-form ant-form-horizontal" | ||
> | ||
<div | ||
class="ant-form-item" | ||
> | ||
<div | ||
class="ant-row ant-form-item-row" | ||
> | ||
<div | ||
class="ant-col ant-form-item-label" | ||
> | ||
<label | ||
class="ant-form-item-required-mark-optional" | ||
for="switch" | ||
title="Switch" | ||
> | ||
Switch | ||
<span | ||
class="ant-form-item-optional" | ||
title="" | ||
> | ||
(optional) | ||
</span> | ||
</label> | ||
</div> | ||
<div | ||
class="ant-col ant-form-item-control" | ||
> | ||
<div | ||
class="ant-form-item-control-input" | ||
> | ||
<div | ||
class="ant-form-item-control-input-content" | ||
> | ||
<span | ||
id="switch" | ||
> | ||
<button | ||
aria-checked="false" | ||
class="ant-switch" | ||
role="switch" | ||
type="button" | ||
> | ||
<div | ||
class="ant-switch-handle" | ||
/> | ||
<span | ||
class="ant-switch-inner" | ||
> | ||
<span | ||
class="ant-switch-inner-checked" | ||
/> | ||
<span | ||
class="ant-switch-inner-unchecked" | ||
/> | ||
</span> | ||
</button> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
`; | ||
|
||
exports[`Form.Item with Switch > normal Switch 1`] = ` | ||
<form | ||
class="ant-form ant-form-horizontal" | ||
> | ||
<div | ||
class="ant-form-item" | ||
> | ||
<div | ||
class="ant-row ant-form-item-row" | ||
> | ||
<div | ||
class="ant-col ant-form-item-label" | ||
> | ||
<label | ||
class="ant-form-item-required ant-form-item-required-mark-optional" | ||
for="switch" | ||
title="Switch" | ||
> | ||
Switch | ||
</label> | ||
</div> | ||
<div | ||
class="ant-col ant-form-item-control" | ||
> | ||
<div | ||
class="ant-form-item-control-input" | ||
> | ||
<div | ||
class="ant-form-item-control-input-content" | ||
> | ||
<button | ||
aria-checked="false" | ||
aria-required="true" | ||
class="ant-switch" | ||
id="switch" | ||
role="switch" | ||
type="button" | ||
> | ||
<div | ||
class="ant-switch-handle" | ||
/> | ||
<span | ||
class="ant-switch-inner" | ||
> | ||
<span | ||
class="ant-switch-inner-checked" | ||
/> | ||
<span | ||
class="ant-switch-inner-unchecked" | ||
/> | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
`; | ||
|
||
exports[`Form.Item with Switch > renderProps Switch 1`] = ` | ||
<form | ||
class="ant-form ant-form-horizontal" | ||
> | ||
<div | ||
class="ant-form-item" | ||
> | ||
<div | ||
class="ant-row ant-form-item-row" | ||
> | ||
<div | ||
class="ant-col ant-form-item-label" | ||
> | ||
<label | ||
class="ant-form-item-required-mark-optional" | ||
for="switch" | ||
title="Switch" | ||
> | ||
Switch | ||
<span | ||
class="ant-form-item-optional" | ||
title="" | ||
> | ||
(optional) | ||
</span> | ||
</label> | ||
</div> | ||
<div | ||
class="ant-col ant-form-item-control" | ||
> | ||
<div | ||
class="ant-form-item-control-input" | ||
> | ||
<div | ||
class="ant-form-item-control-input-content" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
`; | ||
|
||
exports[`Form.Item with Switch > sub Switch 1`] = ` | ||
<form | ||
class="ant-form ant-form-horizontal" | ||
> | ||
<div | ||
class="ant-form-item" | ||
> | ||
<div | ||
class="ant-row ant-form-item-row" | ||
> | ||
<div | ||
class="ant-col ant-form-item-label" | ||
> | ||
<label | ||
class="ant-form-item-required-mark-optional" | ||
for="switch" | ||
title="Switch" | ||
> | ||
Switch | ||
<span | ||
class="ant-form-item-optional" | ||
title="" | ||
> | ||
(optional) | ||
</span> | ||
</label> | ||
</div> | ||
<div | ||
class="ant-col ant-form-item-control" | ||
> | ||
<div | ||
class="ant-form-item-control-input" | ||
> | ||
<div | ||
class="ant-form-item-control-input-content" | ||
> | ||
<button | ||
aria-checked="false" | ||
class="ant-switch" | ||
role="switch" | ||
type="button" | ||
> | ||
<div | ||
class="ant-switch-handle" | ||
/> | ||
<span | ||
class="ant-switch-inner" | ||
> | ||
<span | ||
class="ant-switch-inner-checked" | ||
/> | ||
<span | ||
class="ant-switch-inner-unchecked" | ||
/> | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
`; |
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,67 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { ConfigProvider, Form, Switch } from '@oceanbase/design'; | ||
import type { FormItemProps } from '@oceanbase/design'; | ||
|
||
const FormItemTest: React.FC<FormItemProps> = ({ children }) => ( | ||
<Form> | ||
<Form.Item label="Switch" name="switch"> | ||
{children} | ||
</Form.Item> | ||
</Form> | ||
); | ||
|
||
describe('Form.Item with Switch', () => { | ||
it('normal Switch', () => { | ||
const { container, asFragment } = render( | ||
<FormItemTest> | ||
<Switch /> | ||
</FormItemTest> | ||
); | ||
expect(container.querySelector('.ant-form-item-optional')).toBeFalsy(); | ||
expect(asFragment().firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('dynamic Switch', () => { | ||
const { container, asFragment } = render( | ||
<FormItemTest>{true ? <Switch /> : null}</FormItemTest> | ||
); | ||
expect(container.querySelector('.ant-form-item-optional')).toBeFalsy(); | ||
expect(asFragment().firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('nested Switch', () => { | ||
const { container, asFragment } = render( | ||
<FormItemTest> | ||
<span> | ||
<Switch /> | ||
</span> | ||
</FormItemTest> | ||
); | ||
expect(container.querySelector('.ant-form-item-optional')).toBeTruthy(); | ||
expect(asFragment().firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('renderProps Switch', () => { | ||
const { container, asFragment } = render( | ||
<FormItemTest> | ||
{() => { | ||
return true ? <Switch /> : null; | ||
}} | ||
</FormItemTest> | ||
); | ||
expect(container.querySelector('.ant-form-item-optional')).toBeTruthy(); | ||
expect(asFragment().firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it('sub component Switch', () => { | ||
const SwitchComponent = () => <Switch />; | ||
const { container, asFragment } = render( | ||
<FormItemTest> | ||
<SwitchComponent /> | ||
</FormItemTest> | ||
); | ||
expect(container.querySelector('.ant-form-item-optional')).toBeTruthy(); | ||
expect(asFragment().firstChild).toMatchSnapshot(); | ||
Check failure on line 65 in packages/design/src/form/__tests__/switch.test.tsx GitHub Actions / test (16.x, ubuntu-latest)src/form/__tests__/switch.test.tsx > Form.Item with Switch > sub component Switch
|
||
}); | ||
}); |