-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from commitd/stuarthendren/issue221
feat(switch): adds `brand` variant to switch component
- Loading branch information
Showing
3 changed files
with
97 additions
and
50 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 |
---|---|---|
@@ -1,13 +1,30 @@ | ||
import React from 'react' | ||
import { renderLight, renderDark } from 'test-utils' | ||
import { Default } from './Switch.stories' | ||
import { renderLight, renderDark, userEvent, screen } from 'test-utils' | ||
import { Default as Switch, States } from './Switch.stories' | ||
|
||
it('renders light without error', () => { | ||
const { asFragment } = renderLight(<Default />) | ||
expect(asFragment()).toBeDefined() | ||
const onClickSpy = jest.fn() | ||
renderLight(<Switch onClick={onClickSpy} />) | ||
const buttonElement = screen.getByRole('switch') | ||
buttonElement.click() | ||
expect(onClickSpy).toHaveBeenCalled() | ||
}) | ||
|
||
it('renders and can be accessed with keyboard', () => { | ||
const onClickSpy = jest.fn() | ||
renderLight(<Switch onClick={onClickSpy} />) | ||
userEvent.tab() | ||
userEvent.keyboard('{enter}') | ||
expect(onClickSpy).toHaveBeenCalled() | ||
}) | ||
|
||
it('renders disabled without role', async () => { | ||
renderDark(<Switch disabled />) | ||
const buttons = await screen.findAllByRole('switch') | ||
buttons.forEach((b) => expect(b).toHaveAttribute('disabled')) | ||
}) | ||
|
||
it('renders dark without error', () => { | ||
const { asFragment } = renderDark(<Default />) | ||
it('renders all variants without error', () => { | ||
const { asFragment } = renderDark(<States />) | ||
expect(asFragment()).toBeDefined() | ||
}) |
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