-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLAY-784] Converting Toggle kit to Typescript (#2510)
**What does this PR do?** Converting Toggle kit to Typescript. [Runway Ticket](https://nitro.powerhrg.com/runway/backlog_items/PLAY-784) **How to test?** 1. Go to Toggle kit on Playbook docs 2. Ensure all the examples still work #### Checklist: - [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [x] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [x] **TESTS** I have added test coverage to my code. --------- Co-authored-by: Nida Ghuman <[email protected]>
- Loading branch information
1 parent
434c25f
commit d130ce0
Showing
2 changed files
with
87 additions
and
22 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,67 @@ | ||
import React from 'react' | ||
import { render, screen } from '../utilities/test-utils' | ||
|
||
import Toggle from './_toggle' | ||
|
||
const testId = 'toggle' | ||
const className = 'custom-class-name' | ||
|
||
const ToggleDefault = (props) => ( | ||
<> | ||
<Toggle | ||
aria={{ label: testId }} | ||
className={className} | ||
data={{ testid: testId }} | ||
id={testId} | ||
{...props} | ||
/> | ||
</> | ||
) | ||
|
||
test('should pass data prop', () => { | ||
render(<ToggleDefault />) | ||
const kit = screen.getByTestId(testId) | ||
expect(kit).toBeInTheDocument() | ||
}) | ||
|
||
test('should pass className prop', () => { | ||
render(<ToggleDefault />) | ||
const kit = screen.getByTestId(testId) | ||
expect(kit).toHaveClass(className) | ||
}) | ||
|
||
test('should pass aria prop', () => { | ||
render(<ToggleDefault />) | ||
const kit = screen.getByTestId(testId) | ||
expect(kit).toHaveAttribute('aria-label', testId) | ||
}) | ||
|
||
test('should pass id prop', () => { | ||
render(<ToggleDefault />) | ||
const kit = screen.getByTestId(testId) | ||
expect(kit).toHaveProperty('id', testId) | ||
}) | ||
|
||
test('should not be checked by default', () => { | ||
render(<ToggleDefault />) | ||
const kit = screen.getByTestId(testId) | ||
expect(kit).toHaveClass('pb_toggle_kit_sm_off') | ||
}) | ||
|
||
test('should pass checked prop', () => { | ||
render(<ToggleDefault checked />) | ||
const kit = screen.getByTestId(testId) | ||
expect(kit).toHaveClass('pb_toggle_kit_sm_on') | ||
}) | ||
|
||
test('should have sm size by default', () => { | ||
render(<ToggleDefault />) | ||
const kit = screen.getByTestId(testId) | ||
expect(kit).toHaveClass('pb_toggle_kit_sm_off') | ||
}) | ||
|
||
test('should pass size prop', () => { | ||
render(<ToggleDefault size='md' />) | ||
const kit = screen.getByTestId(testId) | ||
expect(kit).toHaveClass('pb_toggle_kit_md_off') | ||
}) |