@@ -75,9 +75,7 @@ describe('<Select> integration', () => {
7575 const { getAllByRole, getByRole, queryByRole } = render ( < SelectAndDialog /> ) ;
7676
7777 const trigger = getByRole ( 'button' ) ;
78- // basically this is a combined query getByRole('button', { name: 'Ten' })
79- // but we arent' there yet
80- expect ( trigger ) . to . have . text ( 'Ten' ) ;
78+ expect ( trigger ) . to . have . accessibleName ( 'Ten' ) ;
8179 // Let's open the select component
8280 // in the browser user click also focuses
8381 fireEvent . mouseDown ( trigger ) ;
@@ -96,17 +94,31 @@ describe('<Select> integration', () => {
9694 } ) ;
9795
9896 describe ( 'with label' , ( ) => {
97+ it ( 'requires `id` and `labelId` for a proper accessible name' , ( ) => {
98+ const { getByRole } = render (
99+ < FormControl >
100+ < InputLabel id = "label" > Age</ InputLabel >
101+ < Select id = "input" labelId = "label" value = "10" >
102+ < MenuItem value = "" > none</ MenuItem >
103+ < MenuItem value = "10" > Ten</ MenuItem >
104+ </ Select >
105+ </ FormControl > ,
106+ ) ;
107+
108+ expect ( getByRole ( 'button' ) ) . to . have . accessibleName ( 'Age Ten' ) ;
109+ } ) ;
110+
99111 // we're somewhat abusing "focus" here. What we're actually interested in is
100112 // displaying it as "active". WAI-ARIA authoring practices do not consider the
101113 // the trigger part of the widget while a native <select /> will outline the trigger
102114 // as well
103115 it ( 'is displayed as focused while open' , ( ) => {
104- const { container , getByRole } = render (
116+ const { getByTestId , getByRole } = render (
105117 < FormControl >
106- < InputLabel classes = { { focused : 'focused-label' } } htmlFor = "age-simple ">
118+ < InputLabel classes = { { focused : 'focused-label' } } data-testid = "label ">
107119 Age
108120 </ InputLabel >
109- < Select inputProps = { { id : 'age' } } value = "" >
121+ < Select value = "" >
110122 < MenuItem value = "" > none</ MenuItem >
111123 < MenuItem value = { 10 } > Ten</ MenuItem >
112124 </ Select >
@@ -117,7 +129,7 @@ describe('<Select> integration', () => {
117129 trigger . focus ( ) ;
118130 fireEvent . keyDown ( document . activeElement , { key : 'Enter' } ) ;
119131
120- expect ( container . querySelector ( '[for="age-simple"] ') ) . to . have . class ( 'focused-label' ) ;
132+ expect ( getByTestId ( 'label ') ) . to . have . class ( 'focused-label' ) ;
121133 } ) ;
122134
123135 it ( 'does not stays in an active state if an open action did not actually open' , ( ) => {
0 commit comments