@@ -199,32 +199,17 @@ const grouped_icon_options = [
199199] ;
200200
201201describe ( "Select component tests" , ( ) => {
202- test ( "Renders with correct label" , ( ) => {
202+ test ( "When clicking the label, the focus goes to the select " , ( ) => {
203203 const { getByText, getByRole } = render (
204204 < DxcSelect label = "test-select-label" helperText = "test-select-helper-text" placeholder = "Example text" />
205205 ) ;
206206 const select = getByRole ( "combobox" ) ;
207207 const label = getByText ( "test-select-label" ) ;
208208
209- expect ( label ) . toBeTruthy ( ) ;
210209 userEvent . click ( label ) ;
211210 expect ( document . activeElement ) . toEqual ( select ) ;
212211 } ) ;
213- test ( "Renders with correct helper text and placeholder" , ( ) => {
214- const { getByText } = render (
215- < DxcSelect label = "test-select-label" helperText = "test-select-helper-text" placeholder = "Example text" />
216- ) ;
217-
218- expect ( getByText ( "test-select-helper-text" ) ) . toBeTruthy ( ) ;
219- expect ( getByText ( "Example text" ) ) . toBeTruthy ( ) ;
220- } ) ;
221- test ( "Renders with correct optional label" , ( ) => {
222- const { getByText } = render ( < DxcSelect label = "test-select-label" optional /> ) ;
223-
224- expect ( getByText ( "test-select-label" ) ) . toBeTruthy ( ) ;
225- expect ( getByText ( "(Optional)" ) ) . toBeTruthy ( ) ;
226- } ) ;
227- test ( "Renders with error message and correct aria attributes" , ( ) => {
212+ test ( "Renders with correct aria attributes when is in error state" , ( ) => {
228213 const { getByText, getByRole } = render ( < DxcSelect label = "Error label" error = "Error message." /> ) ;
229214 const select = getByRole ( "combobox" ) ;
230215 const errorMessage = getByText ( "Error message." ) ;
@@ -293,26 +278,45 @@ describe("Select component tests", () => {
293278 expect ( getByText ( "Option 02, Option 03, Option 04, Option 06" ) ) . toBeTruthy ( ) ;
294279 expect ( submitInput . value ) . toBe ( "4,2,6,3" ) ;
295280 } ) ;
296- test ( "Disabled select - Clear all options action must be shown but not clickable " , ( ) => {
297- const { getByRole, getByText , queryByRole } = render (
298- < DxcSelect label = "test-select-label" value = { [ "1" , "2" ] } options = { single_options } disabled searchable multiple />
281+ test ( "Disabled select - Cannot gain focus or open the listbox via click " , ( ) => {
282+ const { getByRole, queryByRole } = render (
283+ < DxcSelect label = "test-select-label" value = { [ "1" , "2" ] } options = { single_options } disabled />
299284 ) ;
300285 const select = getByRole ( "combobox" ) ;
301286
302287 expect ( select . getAttribute ( "aria-disabled" ) ) . toBe ( "true" ) ;
303288 userEvent . click ( select ) ;
304289 expect ( queryByRole ( "listbox" ) ) . toBeFalsy ( ) ;
290+ expect ( document . activeElement === select ) . toBeFalsy ( ) ;
291+ } ) ;
292+ test ( "Disabled select - Clear all options action must be shown but not clickable" , ( ) => {
293+ const { getByRole, getByText } = render (
294+ < DxcSelect label = "test-select-label" value = { [ "1" , "2" ] } options = { single_options } disabled searchable multiple />
295+ ) ;
296+
305297 userEvent . click ( getByRole ( "button" ) ) ;
306298 expect ( getByText ( "Option 01, Option 02" ) ) . toBeTruthy ( ) ;
307299 } ) ;
308- test ( "Focused select does not open the listbox" , ( ) => {
300+ test ( "Disabled select - Does not call onBlur event" , ( ) => {
301+ const onBlur = jest . fn ( ) ;
302+ const { getByRole } = render (
303+ < DxcSelect label = "test-select-label" options = { single_options } disabled onBlur = { onBlur } />
304+ ) ;
305+ const select = getByRole ( "combobox" ) ;
306+
307+ userEvent . click ( select ) ;
308+ fireEvent . keyDown ( getByRole ( "combobox" ) , { key : "Tab" , code : "Tab" , keyCode : 9 , charCode : 9 } ) ;
309+ expect ( onBlur ) . not . toHaveBeenCalled ( ) ;
310+ } ) ;
311+ test ( "Disabled select - When the component gains the focus, the listbox does not open" , ( ) => {
309312 const { getByRole, queryByRole } = render (
310313 < DxcSelect label = "test-select-label" value = { [ "1" , "2" ] } options = { single_options } disabled searchable multiple />
311314 ) ;
312315 const select = getByRole ( "combobox" ) ;
313316
314317 fireEvent . focus ( select ) ;
315318 expect ( queryByRole ( "listbox" ) ) . toBeFalsy ( ) ;
319+ expect ( document . activeElement === select ) . toBeFalsy ( ) ;
316320 } ) ;
317321 test ( "Controlled - Single selection - Not optional constraint" , ( ) => {
318322 const onChange = jest . fn ( ) ;
0 commit comments