-
Notifications
You must be signed in to change notification settings - Fork 13
feat: migrate switch to base ui #571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+65
−102
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
632a587
feat: migrate checkbox to base ui
rohanchkrabrty ac925a7
feat: update checkbox tests and docs
rohanchkrabrty 0232244
feat: migrate avatar to base ui
rohanchkrabrty e46d9cc
fix: avatar tests
rohanchkrabrty eccbe8f
feat: migrate radio
rohanchkrabrty 876a228
feat: migrate separator props
rohanchkrabrty 1d4b6d1
feat: migrate switch
rohanchkrabrty 8b8be78
Merge branch 'main' into base-switch
rohanchkrabrty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ describe('Switch', () => { | |
| describe('Sizes', () => { | ||
| const sizes = ['small', 'large'] as const; | ||
| sizes.forEach(size => { | ||
| it(`renders ${size} size by default`, () => { | ||
| it(`renders ${size} size`, () => { | ||
| render(<Switch size={size} />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveClass(styles[size]); | ||
|
|
@@ -60,14 +60,14 @@ describe('Switch', () => { | |
| render(<Switch />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveAttribute('aria-checked', 'false'); | ||
| expect(switchElement).toHaveAttribute('data-state', 'unchecked'); | ||
| expect(switchElement).toHaveAttribute('data-unchecked'); | ||
| }); | ||
|
|
||
| it('renders as checked when checked prop is true', () => { | ||
| render(<Switch checked={true} />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveAttribute('aria-checked', 'true'); | ||
| expect(switchElement).toHaveAttribute('data-state', 'checked'); | ||
| expect(switchElement).toHaveAttribute('data-checked'); | ||
| }); | ||
|
|
||
| it('renders with defaultChecked', () => { | ||
|
|
@@ -92,8 +92,7 @@ describe('Switch', () => { | |
| it('renders as disabled when disabled prop is true', () => { | ||
| render(<Switch disabled />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toBeDisabled(); | ||
| expect(switchElement).toHaveAttribute('data-disabled', 'true'); | ||
| expect(switchElement).toHaveAttribute('data-disabled'); | ||
| }); | ||
|
|
||
| it('does not toggle when disabled', () => { | ||
|
|
@@ -110,20 +109,19 @@ describe('Switch', () => { | |
| it('can be disabled while checked', () => { | ||
| render(<Switch disabled checked />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toBeDisabled(); | ||
| expect(switchElement).toHaveAttribute('data-disabled'); | ||
| expect(switchElement).toHaveAttribute('aria-checked', 'true'); | ||
| expect(switchElement).toHaveAttribute('data-disabled', 'true'); | ||
| }); | ||
|
|
||
| it('maintains disabled state with different sizes', () => { | ||
| const { rerender } = render(<Switch disabled size='small' />); | ||
| let switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toBeDisabled(); | ||
| expect(switchElement).toHaveAttribute('data-disabled'); | ||
| expect(switchElement).toHaveClass(styles.small); | ||
|
|
||
| rerender(<Switch disabled size='large' />); | ||
| switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toBeDisabled(); | ||
| expect(switchElement).toHaveAttribute('data-disabled'); | ||
| expect(switchElement).toHaveClass(styles.large); | ||
| }); | ||
| }); | ||
|
|
@@ -137,7 +135,7 @@ describe('Switch', () => { | |
| fireEvent.click(switchElement); | ||
|
|
||
| expect(handleChange).toHaveBeenCalledTimes(1); | ||
| expect(handleChange).toHaveBeenCalledWith(true); | ||
| expect(handleChange).toHaveBeenCalledWith(true, expect.anything()); | ||
| }); | ||
|
|
||
| it('toggles from checked to unchecked', () => { | ||
|
|
@@ -147,7 +145,7 @@ describe('Switch', () => { | |
| const switchElement = screen.getByRole('switch'); | ||
| fireEvent.click(switchElement); | ||
|
|
||
| expect(handleChange).toHaveBeenCalledWith(false); | ||
| expect(handleChange).toHaveBeenCalledWith(false, expect.anything()); | ||
| }); | ||
|
|
||
| it('supports focus events', () => { | ||
|
|
@@ -169,14 +167,10 @@ describe('Switch', () => { | |
| render(<Switch onCheckedChange={handleChange} />); | ||
|
|
||
| const switchElement = screen.getByRole('switch'); | ||
| await switchElement.focus(); | ||
| switchElement.focus(); | ||
| await user.keyboard('[Space]'); | ||
|
|
||
| expect(handleChange).toHaveBeenCalledWith(true); | ||
| await user.keyboard('[Enter]'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't work with enter?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i just tested switch on their handbook and it seems to be working. |
||
|
|
||
| expect(handleChange).toHaveBeenCalledWith(false); | ||
| expect(handleChange).toHaveBeenCalledTimes(2); | ||
| expect(handleChange).toHaveBeenCalledWith(true, expect.anything()); | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -221,14 +215,14 @@ describe('Switch', () => { | |
| it('supports required attribute', () => { | ||
| render(<Switch required />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveAttribute('aria-required', 'true'); | ||
| expect(switchElement).toHaveAttribute('data-required'); | ||
| }); | ||
|
|
||
| it('works with required and disabled', () => { | ||
| render(<Switch required disabled />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveAttribute('aria-required', 'true'); | ||
| expect(switchElement).toBeDisabled(); | ||
| expect(switchElement).toHaveAttribute('data-required'); | ||
| expect(switchElement).toHaveAttribute('data-disabled'); | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -273,43 +267,31 @@ describe('Switch', () => { | |
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveAttribute('aria-describedby', 'description'); | ||
| }); | ||
|
|
||
| it('supports aria-invalid', () => { | ||
| render(<Switch aria-invalid='true' />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveAttribute('aria-invalid', 'true'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('HTML Attributes', () => { | ||
| it('supports name attribute', () => { | ||
| render(<Switch name='notifications' />); | ||
| const hiddenInput = document.querySelector('input[name="notifications"]'); | ||
| expect(hiddenInput).toHaveAttribute('name', 'notifications'); | ||
| }); | ||
|
|
||
| describe('Data Attributes', () => { | ||
| it('supports data attributes', () => { | ||
| render(<Switch data-testid='custom-switch' data-theme='dark' />); | ||
| const switchElement = screen.getByTestId('custom-switch'); | ||
| expect(switchElement).toHaveAttribute('data-theme', 'dark'); | ||
| }); | ||
|
|
||
| it('has data-state attribute for unchecked state', () => { | ||
| it('has data-unchecked attribute for unchecked state', () => { | ||
| render(<Switch />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveAttribute('data-state', 'unchecked'); | ||
| expect(switchElement).toHaveAttribute('data-unchecked'); | ||
| }); | ||
|
|
||
| it('has data-state attribute for checked state', () => { | ||
| it('has data-checked attribute for checked state', () => { | ||
| render(<Switch checked />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveAttribute('data-state', 'checked'); | ||
| expect(switchElement).toHaveAttribute('data-checked'); | ||
| }); | ||
|
|
||
| it('has data-disabled attribute when disabled', () => { | ||
| render(<Switch disabled />); | ||
| const switchElement = screen.getByRole('switch'); | ||
| expect(switchElement).toHaveAttribute('data-disabled', 'true'); | ||
| expect(switchElement).toHaveAttribute('data-disabled'); | ||
| }); | ||
|
|
||
| it('does not have data-disabled when enabled', () => { | ||
|
|
||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.