File tree Expand file tree Collapse file tree
packages/ra-ui-materialui/src/button Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import * as React from 'react' ;
2+ import { render , screen } from '@testing-library/react' ;
3+ import expect from 'expect' ;
4+
5+ import { Basic } from './ToggleThemeButton.stories' ;
6+
7+ describe ( 'ToggleThemeButton' , ( ) => {
8+ it ( 'should display a button' , ( ) => {
9+ render ( < Basic /> ) ;
10+ screen . getByLabelText ( 'Toggle Theme' ) ;
11+ } ) ;
12+ it ( 'should allow to change the theme between light and dark' , ( ) => {
13+ const { container } = render ( < Basic /> ) ;
14+ const root = container . querySelector < HTMLDivElement > (
15+ '.MuiScopedCssBaseline-root'
16+ ) ;
17+ if ( ! root ) {
18+ throw new Error ( 'No root element found' ) ;
19+ }
20+ expect ( getComputedStyle ( root ) . colorScheme ) . toBe ( 'light' ) ;
21+ screen . getByLabelText ( 'Toggle Theme' ) . click ( ) ;
22+ expect ( getComputedStyle ( root ) . colorScheme ) . toBe ( 'dark' ) ;
23+ screen . getByLabelText ( 'Toggle Theme' ) . click ( ) ;
24+ expect ( getComputedStyle ( root ) . colorScheme ) . toBe ( 'light' ) ;
25+ } ) ;
26+ } ) ;
You can’t perform that action at this time.
0 commit comments