@@ -2,6 +2,7 @@ import type { Page } from '@playwright/test'
2
2
3
3
import { expect , test } from '@playwright/test'
4
4
import path from 'path'
5
+ import { wait } from 'payload/utilities'
5
6
import { fileURLToPath } from 'url'
6
7
7
8
import type { PayloadTestSDK } from '../../../helpers/sdk/index.js'
@@ -205,4 +206,139 @@ describe('Text', () => {
205
206
await expect ( field . locator ( '.rs__value-container' ) ) . toContainText ( input )
206
207
await expect ( field . locator ( '.rs__value-container' ) ) . toContainText ( furtherInput )
207
208
} )
209
+
210
+ test ( 'should reset filter conditions when adding additional filters' , async ( ) => {
211
+ await page . goto ( url . list )
212
+
213
+ // open the first filter options
214
+ await page . locator ( '.list-controls__toggle-where' ) . click ( )
215
+ await expect ( page . locator ( '.list-controls__where.rah-static--height-auto' ) ) . toBeVisible ( )
216
+ await page . locator ( '.where-builder__add-first-filter' ) . click ( )
217
+
218
+ const firstInitialField = page . locator ( '.condition__field' )
219
+ const firstOperatorField = page . locator ( '.condition__operator' )
220
+ const firstValueField = page . locator ( '.condition__value >> input' )
221
+
222
+ await firstInitialField . click ( )
223
+ const firstInitialFieldOptions = firstInitialField . locator ( '.rs__option' )
224
+ await firstInitialFieldOptions . locator ( 'text=text' ) . first ( ) . click ( )
225
+ await expect ( firstInitialField . locator ( '.rs__single-value' ) ) . toContainText ( 'Text' )
226
+
227
+ await firstOperatorField . click ( )
228
+ await firstOperatorField . locator ( '.rs__option' ) . locator ( 'text=equals' ) . click ( )
229
+
230
+ await firstValueField . fill ( 'hello' )
231
+
232
+ await wait ( 500 )
233
+
234
+ await expect ( firstValueField ) . toHaveValue ( 'hello' )
235
+
236
+ // open the second filter options
237
+ await page . locator ( '.condition__actions-add' ) . click ( )
238
+
239
+ const secondLi = page . locator ( '.where-builder__and-filters li:nth-child(2)' )
240
+
241
+ await expect ( secondLi ) . toBeVisible ( )
242
+
243
+ const secondInitialField = secondLi . locator ( '.condition__field' )
244
+ const secondOperatorField = secondLi . locator ( '.condition__operator >> input' )
245
+ const secondValueField = secondLi . locator ( '.condition__value >> input' )
246
+
247
+ await expect ( secondInitialField . locator ( '.rs__single-value' ) ) . toContainText ( 'Text' )
248
+ await expect ( secondOperatorField ) . toHaveValue ( '' )
249
+ await expect ( secondValueField ) . toHaveValue ( '' )
250
+ } )
251
+
252
+ test ( 'should not re-render page upon typing in a value in the filter value field' , async ( ) => {
253
+ await page . goto ( url . list )
254
+
255
+ // open the first filter options
256
+ await page . locator ( '.list-controls__toggle-where' ) . click ( )
257
+ await expect ( page . locator ( '.list-controls__where.rah-static--height-auto' ) ) . toBeVisible ( )
258
+ await page . locator ( '.where-builder__add-first-filter' ) . click ( )
259
+
260
+ const firstInitialField = page . locator ( '.condition__field' )
261
+ const firstOperatorField = page . locator ( '.condition__operator' )
262
+ const firstValueField = page . locator ( '.condition__value >> input' )
263
+
264
+ await firstInitialField . click ( )
265
+ const firstInitialFieldOptions = firstInitialField . locator ( '.rs__option' )
266
+ await firstInitialFieldOptions . locator ( 'text=text' ) . first ( ) . click ( )
267
+ await expect ( firstInitialField . locator ( '.rs__single-value' ) ) . toContainText ( 'Text' )
268
+
269
+ await firstOperatorField . click ( )
270
+ await firstOperatorField . locator ( '.rs__option' ) . locator ( 'text=equals' ) . click ( )
271
+
272
+ // Type into the input field instead of filling it
273
+ await firstValueField . click ( )
274
+ await firstValueField . type ( 'hello' , { delay : 100 } ) // Add a delay to simulate typing speed
275
+
276
+ // Wait for a short period to see if the input loses focus
277
+ await page . waitForTimeout ( 500 )
278
+
279
+ // Check if the input still has the correct value
280
+ await expect ( firstValueField ) . toHaveValue ( 'hello' )
281
+ } )
282
+
283
+ test ( 'should still show second filter if two filters exist and first filter is removed' , async ( ) => {
284
+ await page . goto ( url . list )
285
+
286
+ // open the first filter options
287
+ await page . locator ( '.list-controls__toggle-where' ) . click ( )
288
+ await expect ( page . locator ( '.list-controls__where.rah-static--height-auto' ) ) . toBeVisible ( )
289
+ await page . locator ( '.where-builder__add-first-filter' ) . click ( )
290
+
291
+ const firstInitialField = page . locator ( '.condition__field' )
292
+ const firstOperatorField = page . locator ( '.condition__operator' )
293
+ const firstValueField = page . locator ( '.condition__value >> input' )
294
+
295
+ await firstInitialField . click ( )
296
+ const firstInitialFieldOptions = firstInitialField . locator ( '.rs__option' )
297
+ await firstInitialFieldOptions . locator ( 'text=text' ) . first ( ) . click ( )
298
+ await expect ( firstInitialField . locator ( '.rs__single-value' ) ) . toContainText ( 'Text' )
299
+
300
+ await firstOperatorField . click ( )
301
+ await firstOperatorField . locator ( '.rs__option' ) . locator ( 'text=equals' ) . click ( )
302
+
303
+ await firstValueField . fill ( 'hello' )
304
+
305
+ await wait ( 500 )
306
+
307
+ await expect ( firstValueField ) . toHaveValue ( 'hello' )
308
+
309
+ // open the second filter options
310
+ await page . locator ( '.condition__actions-add' ) . click ( )
311
+
312
+ const secondLi = page . locator ( '.where-builder__and-filters li:nth-child(2)' )
313
+
314
+ await expect ( secondLi ) . toBeVisible ( )
315
+
316
+ const secondInitialField = secondLi . locator ( '.condition__field' )
317
+ const secondOperatorField = secondLi . locator ( '.condition__operator' )
318
+ const secondValueField = secondLi . locator ( '.condition__value >> input' )
319
+
320
+ await secondInitialField . click ( )
321
+ const secondInitialFieldOptions = secondInitialField . locator ( '.rs__option' )
322
+ await secondInitialFieldOptions . locator ( 'text=text' ) . first ( ) . click ( )
323
+ await expect ( secondInitialField . locator ( '.rs__single-value' ) ) . toContainText ( 'Text' )
324
+
325
+ await secondOperatorField . click ( )
326
+ await secondOperatorField . locator ( '.rs__option' ) . locator ( 'text=equals' ) . click ( )
327
+
328
+ await secondValueField . fill ( 'world' )
329
+ await expect ( secondValueField ) . toHaveValue ( 'world' )
330
+
331
+ await wait ( 500 )
332
+
333
+ const firstLi = page . locator ( '.where-builder__and-filters li:nth-child(1)' )
334
+ const removeButton = firstLi . locator ( '.condition__actions-remove' )
335
+
336
+ // remove first filter
337
+ await removeButton . click ( )
338
+
339
+ const filterListItems = page . locator ( '.where-builder__and-filters li' )
340
+ await expect ( filterListItems ) . toHaveCount ( 1 )
341
+
342
+ await expect ( firstValueField ) . toHaveValue ( 'world' )
343
+ } )
208
344
} )
0 commit comments