@@ -58,8 +58,15 @@ const clickButton = ( name ) => {
58
58
fireEvent . click ( getButton ( name ) ) ;
59
59
} ;
60
60
61
+ const getSliderInput = ( ) => {
62
+ return screen . getByRole ( 'slider' , { name : 'Border width' } ) ;
63
+ } ;
64
+
65
+ const getWidthInput = ( ) => {
66
+ return screen . getByRole ( 'spinbutton' , { name : 'Border width' } ) ;
67
+ } ;
61
68
const setWidthInput = ( value ) => {
62
- const widthInput = screen . getByRole ( 'spinbutton' ) ;
69
+ const widthInput = getWidthInput ( ) ;
63
70
widthInput . focus ( ) ;
64
71
fireEvent . change ( widthInput , { target : { value } } ) ;
65
72
} ;
@@ -73,9 +80,13 @@ describe( 'BorderControl', () => {
73
80
74
81
const label = screen . getByText ( props . label ) ;
75
82
const colorButton = screen . getByLabelText ( toggleLabelRegex ) ;
76
- const widthInput = screen . getByRole ( 'spinbutton' ) ;
77
- const unitSelect = screen . getByRole ( 'combobox' ) ;
78
- const slider = screen . queryByRole ( 'slider' ) ;
83
+ const widthInput = getWidthInput ( ) ;
84
+ const unitSelect = screen . getByRole ( 'combobox' , {
85
+ name : 'Select unit' ,
86
+ } ) ;
87
+ const slider = screen . queryByRole ( 'slider' , {
88
+ name : 'Border width' ,
89
+ } ) ;
79
90
80
91
expect ( label ) . toBeInTheDocument ( ) ;
81
92
expect ( colorButton ) . toBeInTheDocument ( ) ;
@@ -100,13 +111,13 @@ describe( 'BorderControl', () => {
100
111
it ( 'should render with slider' , ( ) => {
101
112
renderBorderControl ( { withSlider : true } ) ;
102
113
103
- const slider = screen . getByRole ( 'slider' ) ;
114
+ const slider = getSliderInput ( ) ;
104
115
expect ( slider ) . toBeInTheDocument ( ) ;
105
116
} ) ;
106
117
107
118
it ( 'should render placeholder in UnitControl' , ( ) => {
108
119
renderBorderControl ( { placeholder : 'Mixed' } ) ;
109
- const widthInput = screen . getByRole ( 'spinbutton' ) ;
120
+ const widthInput = getWidthInput ( ) ;
110
121
111
122
expect ( widthInput ) . toHaveAttribute ( 'placeholder' , 'Mixed' ) ;
112
123
} ) ;
@@ -262,7 +273,7 @@ describe( 'BorderControl', () => {
262
273
it ( 'should update width with slider value' , ( ) => {
263
274
const { rerender } = renderBorderControl ( { withSlider : true } ) ;
264
275
265
- const slider = screen . getByRole ( 'slider' ) ;
276
+ const slider = getSliderInput ( ) ;
266
277
fireEvent . change ( slider , { target : { value : '5' } } ) ;
267
278
268
279
expect ( props . onChange ) . toHaveBeenNthCalledWith ( 1 , {
@@ -271,7 +282,7 @@ describe( 'BorderControl', () => {
271
282
} ) ;
272
283
273
284
rerenderBorderControl ( rerender , { withSlider : true } ) ;
274
- const widthInput = screen . getByRole ( 'spinbutton' ) ;
285
+ const widthInput = getWidthInput ( ) ;
275
286
276
287
expect ( widthInput . value ) . toEqual ( '5' ) ;
277
288
} ) ;
0 commit comments