-
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.
feat(switch): adds
brand
variant to switch component
Adds a `brand` variant for use on the brand background components such as the AppBar. Improves disabled colors to match button. fix #221
- Loading branch information
1 parent
658085c
commit 58a7cf4
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