@@ -4,6 +4,7 @@ import { stub, spy } from 'sinon';
4
4
import { act , createRenderer , fireEvent , screen } from '@mui/internal-test-utils' ;
5
5
import Rating , { ratingClasses as classes } from '@mui/material/Rating' ;
6
6
import { createTheme , ThemeProvider } from '@mui/material/styles' ;
7
+ import userEvent from '@testing-library/user-event' ;
7
8
import describeConformance from '../../test/describeConformance' ;
8
9
9
10
describe ( '<Rating />' , ( ) => {
@@ -121,6 +122,25 @@ describe('<Rating />', () => {
121
122
expect ( checked . value ) . to . equal ( '2' ) ;
122
123
} ) ;
123
124
125
+ it ( 'should select the rating with user clicks using user-event' , async ( ) => {
126
+ if ( ! / j s d o m / . test ( window . navigator . userAgent ) ) {
127
+ this . skip ( ) ;
128
+ }
129
+
130
+ const user = userEvent . setup ( ) ;
131
+ const handleChange = spy ( ) ;
132
+
133
+ const { container } = render ( < Rating name = "rating-test" onChange = { handleChange } /> ) ;
134
+
135
+ await user . click ( screen . getByLabelText ( '3 Stars' ) ) ;
136
+
137
+ expect ( handleChange . callCount ) . to . equal ( 1 ) ;
138
+ expect ( handleChange . args [ 0 ] [ 1 ] ) . to . deep . equal ( 3 ) ;
139
+
140
+ const checked = container . querySelector ( 'input[name="rating-test"]:checked' ) ;
141
+ expect ( checked . value ) . to . equal ( '3' ) ;
142
+ } ) ;
143
+
124
144
it ( 'should change the value to null' , ( ) => {
125
145
const handleChange = spy ( ) ;
126
146
render ( < Rating name = "rating-test" onChange = { handleChange } value = { 2 } /> ) ;
0 commit comments