@@ -126,15 +126,15 @@ describe('add-a-new-rate', () => {
126
126
127
127
await user . type ( screen . getByLabelText ( 'Description' ) , 'regular rate test' ) ;
128
128
129
- // select first option for metric
129
+ // select CPU metric explicitly by name
130
130
await user . click ( screen . getByLabelText ( 'Select metric' ) ) ;
131
131
options = await screen . findAllByRole ( 'option' ) ;
132
- await user . click ( options [ 0 ] ) ;
132
+ await user . click ( options . find ( o => / " v a l u e " : " c p u " / i . test ( o . textContent ) ) ) ;
133
133
134
- // select first option for measurement
134
+ // select measurement by name (avoid brittle index)
135
135
await user . click ( screen . getByLabelText ( 'Select measurement' ) ) ;
136
136
options = await screen . findAllByRole ( 'option' ) ;
137
- await user . click ( options [ 3 ] ) ; // Previous select options are not being removed from page
137
+ await user . click ( options . find ( o => / " v a l u e " : " u s a g e " / i . test ( o . textContent ) ) ) ;
138
138
139
139
// make sure the default cost type is selected
140
140
expect ( screen . getByLabelText ( qr . infraradio ) ) . toHaveProperty ( 'checked' , true ) ;
@@ -144,7 +144,7 @@ describe('add-a-new-rate', () => {
144
144
145
145
await user . click ( screen . getByLabelText ( 'Select measurement' ) ) ;
146
146
options = await screen . findAllByRole ( 'option' ) ;
147
- await user . click ( options [ 1 ] ) ;
147
+ await user . click ( options . find ( o => / " v a l u e " : " r e q u e s t " / i . test ( o . textContent ) ) ) ;
148
148
149
149
expect ( screen . getByLabelText ( qr . supplradio ) ) . toHaveProperty ( 'checked' , true ) ;
150
150
@@ -153,13 +153,13 @@ describe('add-a-new-rate', () => {
153
153
154
154
await user . click ( screen . getByLabelText ( 'Select metric' ) ) ;
155
155
options = await screen . findAllByRole ( 'option' ) ;
156
- await user . click ( options [ 1 ] ) ;
156
+ await user . click ( options . find ( o => / " v a l u e " : " m e m o r y " / i . test ( o . textContent ) ) ) ;
157
157
158
158
expect ( screen . getByText ( regExp ( messages . costModelsRequiredField ) ) ) . not . toBeNull ( ) ;
159
159
160
160
await user . click ( screen . getByLabelText ( 'Select measurement' ) ) ;
161
161
options = await screen . findAllByRole ( 'option' ) ;
162
- await user . click ( options [ 3 ] ) ; // Previous select options are not being removed from page
162
+ await user . click ( options . find ( o => / " v a l u e " : " u s a g e " / i . test ( o . textContent ) ) ) ;
163
163
164
164
expect ( screen . getByLabelText ( qr . supplradio ) ) . toHaveProperty ( 'checked' , true ) ;
165
165
await user . click ( screen . getByLabelText ( qr . infraradio ) ) ;
@@ -183,7 +183,7 @@ describe('add-a-new-rate', () => {
183
183
184
184
// making sure button is enabled
185
185
const createButton = screen . getByRole ( 'button' , { name : regExp ( messages . createRate ) } ) ;
186
- expect ( createButton ) . not . toBeDisabled ;
186
+ expect ( createButton ) . not . toBeDisabled ( ) ;
187
187
await user . click ( createButton ) ;
188
188
expect ( submit ) . toHaveBeenCalled ( ) ;
189
189
} , 10000 ) ;
@@ -200,11 +200,11 @@ describe('add-a-new-rate', () => {
200
200
201
201
await user . click ( screen . getByLabelText ( 'Select metric' ) ) ;
202
202
options = await screen . findAllByRole ( 'option' ) ;
203
- await user . click ( options [ 0 ] ) ;
203
+ await user . click ( options . find ( o => / " v a l u e " : " c p u " / i . test ( o . textContent ) ) ) ;
204
204
205
205
await user . click ( screen . getByLabelText ( 'Select measurement' ) ) ;
206
206
options = await screen . findAllByRole ( 'option' ) ;
207
- await user . click ( options [ 3 ] ) ; // Previous select options are not being removed from page
207
+ await user . click ( options . find ( o => / " v a l u e " : " u s a g e " / i . test ( o . textContent ) ) ) ;
208
208
209
209
await user . click ( screen . getByLabelText ( regExp ( messages . costModelsEnterTagRate ) ) ) ;
210
210
@@ -246,7 +246,7 @@ describe('add-a-new-rate', () => {
246
246
247
247
await user . type ( tagRateInput , '0.23' ) ;
248
248
await user . type ( screen . getByPlaceholderText ( 'Enter a tag description' ) , 'default worker' ) ;
249
- expect ( createButton ) . not . toBeDisabled ;
249
+ expect ( createButton ) . not . toBeDisabled ( ) ;
250
250
251
251
// set tag to default
252
252
await user . click ( screen . getByLabelText ( 'Default' ) ) ;
@@ -271,11 +271,11 @@ describe('add-a-new-rate', () => {
271
271
272
272
await user . click ( screen . getByLabelText ( 'Select metric' ) ) ;
273
273
options = await screen . findAllByRole ( 'option' ) ;
274
- await user . click ( options [ 1 ] ) ;
274
+ await user . click ( options . find ( o => / " v a l u e " : " m e m o r y " / i . test ( o . textContent ) ) ) ;
275
275
276
276
await user . click ( screen . getByLabelText ( 'Select measurement' ) ) ;
277
277
options = await screen . findAllByRole ( 'option' ) ;
278
- await user . click ( options [ 4 ] ) ; // Previous select options are not being removed from page
278
+ await user . click ( options . find ( o => / " v a l u e " : " u s a g e " / i . test ( o . textContent ) ) ) ;
279
279
280
280
await user . click ( screen . getByLabelText ( regExp ( messages . costModelsEnterTagRate ) ) ) ;
281
281
@@ -293,13 +293,13 @@ describe('add-a-new-rate', () => {
293
293
294
294
await user . click ( screen . getByLabelText ( 'Select measurement' ) ) ;
295
295
options = await screen . findAllByRole ( 'option' ) ;
296
- await user . click ( options [ 1 ] ) ;
296
+ await user . click ( options . find ( o => / " v a l u e " : " r e q u e s t " / i . test ( o . textContent ) ) ) ;
297
297
298
298
expect ( screen . queryByText ( regExp ( messages . priceListDuplicate ) ) ) . toBeNull ( ) ;
299
299
300
300
await user . click ( screen . getByLabelText ( 'Select measurement' ) ) ;
301
301
options = await screen . findAllByRole ( 'option' ) ;
302
- await user . click ( options [ 4 ] ) ;
302
+ await user . click ( options . find ( o => / " v a l u e " : " u s a g e " / i . test ( o . textContent ) ) ) ;
303
303
304
304
expect ( screen . getByText ( regExp ( messages . priceListDuplicate ) ) ) . not . toBeNull ( ) ;
305
305
} ) ;
0 commit comments