@@ -11,7 +11,7 @@ test.describe('base tests', () => {
1111 } ) ;
1212
1313 test ( 'sanity startup' , async ( { page } ) => {
14- const currencyInput = await page . locator ( '#currency-input' ) ;
14+ const currencyInput = page . locator ( '#currency-input' ) ;
1515 await expect ( currencyInput ) . toHaveValue ( '$0.00 USD' ) ;
1616 } ) ;
1717
@@ -96,8 +96,8 @@ test.describe('component parameters', () => {
9696 await decimalInput . fill ( ',' ) ;
9797 await applyBtn . click ( ) ;
9898
99- await page . waitForTimeout ( 100 ) ;
10099 const currencyInput = page . locator ( '#currency-input' ) ;
100+ await expect ( currencyInput ) . toHaveValue ( '0,00' ) ;
101101 await currencyInput . focus ( ) ;
102102 await currencyInput . fill ( '' ) ;
103103 await currencyInput . type ( '12345' ) ;
@@ -120,8 +120,8 @@ test.describe('component parameters', () => {
120120 await precisionInput . fill ( '2' ) ;
121121 await applyBtn . click ( ) ;
122122
123- await page . waitForTimeout ( 100 ) ;
124123 const currencyInput = page . locator ( '#currency-input' ) ;
124+ await expect ( currencyInput ) . toHaveValue ( '0,00' ) ;
125125 await currencyInput . focus ( ) ;
126126 await currencyInput . fill ( '' ) ;
127127 await currencyInput . type ( '1234567' ) ;
@@ -145,8 +145,8 @@ test.describe('component parameters', () => {
145145 await precisionInput . fill ( '0' ) ;
146146 await applyBtn . click ( ) ;
147147
148- await page . waitForTimeout ( 100 ) ;
149148 const currencyInput = page . locator ( '#currency-input' ) ;
149+ await expect ( currencyInput ) . toHaveValue ( '0' ) ;
150150 await currencyInput . focus ( ) ;
151151 await currencyInput . fill ( '' ) ;
152152 await currencyInput . type ( '12345' ) ;
@@ -167,8 +167,8 @@ test.describe('component parameters', () => {
167167 await precisionInput . fill ( '3' ) ;
168168 await applyBtn . click ( ) ;
169169
170- await page . waitForTimeout ( 100 ) ;
171170 const currencyInput = page . locator ( '#currency-input' ) ;
171+ await expect ( currencyInput ) . toHaveValue ( '0.000' ) ;
172172 await currencyInput . focus ( ) ;
173173 await currencyInput . fill ( '' ) ;
174174 await currencyInput . type ( '12345' ) ;
@@ -194,26 +194,24 @@ test.describe('component parameters', () => {
194194 // Enable allowNegative via form control
195195 const allowNegativeCheckbox = page . locator ( '[name=allowNegative]' ) ;
196196 const applyBtn = page . locator ( '[name=apply]' ) ;
197+ const currencyInput = page . locator ( '#currency-input' ) ;
197198
198199 await allowNegativeCheckbox . check ( ) ;
199200 await applyBtn . click ( ) ;
200201
201- // Wait for the state to update and component to re-render
202- await page . waitForTimeout ( 200 ) ;
203-
204- const currencyInput = page . locator ( '#currency-input' ) ;
202+ await expect ( currencyInput ) . toHaveValue ( '$0.00 USD' ) ;
205203 await currencyInput . focus ( ) ;
206204 await currencyInput . selectText ( ) ;
207-
205+
208206 // First input a number (can't have negative zero)
209207 await currencyInput . pressSequentially ( '50' ) ;
210-
208+
211209 let value = await currencyInput . inputValue ( ) ;
212210 expect ( value ) . toContain ( '0.50' ) ;
213-
211+
214212 // Now add the minus sign - should toggle the number to negative
215213 await currencyInput . press ( 'Minus' ) ;
216-
214+
217215 // Should now contain minus sign
218216 value = await currencyInput . inputValue ( ) ;
219217 expect ( value ) . toContain ( '-' ) ;
@@ -223,27 +221,25 @@ test.describe('component parameters', () => {
223221 // First enable allowNegative
224222 const allowNegativeCheckbox = page . locator ( '[name=allowNegative]' ) ;
225223 const applyBtn = page . locator ( '[name=apply]' ) ;
224+ const currencyInput = page . locator ( '#currency-input' ) ;
226225
227226 await allowNegativeCheckbox . check ( ) ;
228227 await applyBtn . click ( ) ;
229- await page . waitForTimeout ( 200 ) ;
230-
231- const currencyInput = page . locator ( '#currency-input' ) ;
228+ await expect ( currencyInput ) . toHaveValue ( '$0.00 USD' ) ;
232229 await currencyInput . focus ( ) ;
233230 await currencyInput . selectText ( ) ;
234-
231+
235232 // Input a negative number
236233 await currencyInput . pressSequentially ( '50' ) ;
237234 await currencyInput . press ( 'Minus' ) ;
238-
235+
239236 let value = await currencyInput . inputValue ( ) ;
240237 expect ( value ) . toContain ( '-' ) ;
241-
238+
242239 // Now disable allowNegative
243240 await allowNegativeCheckbox . uncheck ( ) ;
244241 await applyBtn . click ( ) ;
245- await page . waitForTimeout ( 200 ) ;
246-
242+
247243 // Value should now be positive
248244 value = await currencyInput . inputValue ( ) ;
249245 expect ( value ) . not . toContain ( '-' ) ;
@@ -275,18 +271,14 @@ test.describe('component parameters', () => {
275271 await selectAllCheckbox . check ( ) ;
276272 await applyBtn . click ( ) ;
277273
278- await page . waitForTimeout ( 100 ) ;
279274 const currencyInput = page . locator ( '#currency-input' ) ;
280275 await currencyInput . focus ( ) ;
281276
282- // With selectAllOnFocus, all text should be selected
283- // The selection should encompass the content
284- const inputValue = await currencyInput . inputValue ( ) ;
285- const selectionStart = await currencyInput . evaluate ( ( el : HTMLInputElement ) => el . selectionStart ) ;
286- const selectionEnd = await currencyInput . evaluate ( ( el : HTMLInputElement ) => el . selectionEnd ) ;
287-
288- // Should have selected content
289- expect ( selectionEnd - selectionStart ) . toBeGreaterThan ( 0 ) ;
277+ await expect . poll ( async ( ) => {
278+ const selectionStart = await currencyInput . evaluate ( ( el : HTMLInputElement ) => el . selectionStart ?? 0 ) ;
279+ const selectionEnd = await currencyInput . evaluate ( ( el : HTMLInputElement ) => el . selectionEnd ?? 0 ) ;
280+ return selectionEnd - selectionStart ;
281+ } ) . toBeGreaterThan ( 0 ) ;
290282 } ) ;
291283 } ) ;
292284
0 commit comments