-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathe2e.spec.ts
708 lines (575 loc) · 26.2 KB
/
e2e.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
import type { Page } from '@playwright/test'
import { expect, test } from '@playwright/test'
import { addListFilter } from 'helpers/e2e/addListFilter.js'
import { navigateToDoc } from 'helpers/e2e/navigateToDoc.js'
import { openDocControls } from 'helpers/e2e/openDocControls.js'
import { openListFilters } from 'helpers/e2e/openListFilters.js'
import { openCreateDocDrawer, openDocDrawer } from 'helpers/e2e/toggleDocDrawer.js'
import path from 'path'
import { wait } from 'payload/shared'
import { fileURLToPath } from 'url'
import type { PayloadTestSDK } from '../../../helpers/sdk/index.js'
import type { Config, RelationshipField, TextField } from '../../payload-types.js'
import {
ensureCompilationIsDone,
exactText,
initPageConsoleErrorCatch,
saveDocAndAssert,
saveDocHotkeyAndAssert,
} from '../../../helpers.js'
import { AdminUrlUtil } from '../../../helpers/adminUrlUtil.js'
import { assertToastErrors } from '../../../helpers/assertToastErrors.js'
import { initPayloadE2ENoConfig } from '../../../helpers/initPayloadE2ENoConfig.js'
import { reInitializeDB } from '../../../helpers/reInitializeDB.js'
import { RESTClient } from '../../../helpers/rest.js'
import { POLL_TOPASS_TIMEOUT, TEST_TIMEOUT_LONG } from '../../../playwright.config.js'
import { relationshipFieldsSlug, textFieldsSlug } from '../../slugs.js'
const filename = fileURLToPath(import.meta.url)
const currentFolder = path.dirname(filename)
const dirname = path.resolve(currentFolder, '../../')
const { beforeAll, beforeEach, describe } = test
let payload: PayloadTestSDK<Config>
let client: RESTClient
let page: Page
let serverURL: string
// If we want to make this run in parallel: test.describe.configure({ mode: 'parallel' })
describe('relationship', () => {
beforeAll(async ({ browser }, testInfo) => {
testInfo.setTimeout(TEST_TIMEOUT_LONG)
process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit
;({ payload, serverURL } = await initPayloadE2ENoConfig<Config>({
dirname,
}))
const context = await browser.newContext()
page = await context.newPage()
initPageConsoleErrorCatch(page)
await ensureCompilationIsDone({ page, serverURL })
})
beforeEach(async () => {
await reInitializeDB({
serverURL,
snapshotKey: 'fieldsTest',
uploadsDir: path.resolve(dirname, './collections/Upload/uploads'),
})
if (client) {
await client.logout()
}
client = new RESTClient({ defaultSlug: 'users', serverURL })
await client.login()
await ensureCompilationIsDone({ page, serverURL })
})
let url: AdminUrlUtil
const tableRowLocator = 'table > tbody > tr'
beforeAll(() => {
url = new AdminUrlUtil(serverURL, 'relationship-fields')
})
test('should create inline relationship within field with many relations', async () => {
await page.goto(url.create)
await openCreateDocDrawer({ page, fieldSelector: '#field-relationship' })
await page
.locator('#field-relationship .relationship-add-new__relation-button--text-fields')
.click()
const textField = page.locator('.drawer__content #field-text')
await expect(textField).toBeEnabled()
const textValue = 'hello'
await textField.fill(textValue)
await page.locator('[id^=doc-drawer_text-fields_1_] #action-save').click()
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
await page.locator('[id^=close-drawer__doc-drawer_text-fields_1_]').click()
await expect(
page.locator('#field-relationship .relationship--single-value__text'),
).toContainText(textValue)
await page.locator('#action-save').click()
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
})
test('should create nested inline relationships', async () => {
await page.goto(url.create)
// Open first modal
await openCreateDocDrawer({ page, fieldSelector: '#field-relationToSelf' })
// Fill first modal's required relationship field
await page.locator('[id^=doc-drawer_relationship-fields_1_] #field-relationship').click()
await page
.locator(
'[id^=doc-drawer_relationship-fields_1_] .rs__option:has-text("Seeded text document")',
)
.click()
const secondModalButton = page.locator(
'[id^=doc-drawer_relationship-fields_1_] #relationToSelf-add-new button',
)
await secondModalButton.click()
// Fill second modal's required relationship field
await page.locator('[id^=doc-drawer_relationship-fields_2_] #field-relationship').click()
await page
.locator(
'[id^=doc-drawer_relationship-fields_2_] .rs__option:has-text("Seeded text document")',
)
.click()
// Save then close the second modal
await page.locator('[id^=doc-drawer_relationship-fields_2_] #action-save').click()
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('create')
await page.locator('[id^=close-drawer__doc-drawer_relationship-fields_2_]').click()
// Assert that the first modal is still open and the value matches
await expect(page.locator('[id^=doc-drawer_relationship-fields_1_]')).toBeVisible()
await expect(
page.locator(
'[id^=doc-drawer_relationship-fields_1_] #field-relationToSelf .relationship--single-value__text',
),
).toBeVisible() // TODO: use '.toContainText('doc_id')' with the doc in the second modal
// Save then close the first modal
await page.locator('[id^=doc-drawer_relationship-fields_1_] #action-save').click()
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('create')
await page.locator('[id^=close-drawer__doc-drawer_relationship-fields_1_]').click()
// Expect the original field to have a value filled
await expect(
page.locator('#field-relationToSelf .relationship--single-value__text'),
).toBeVisible()
// Fill the required field
await page.locator('#field-relationship').click()
await page.locator('.rs__option:has-text("Seeded text document")').click()
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('create')
await page.locator('#action-save').click()
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
})
test('should hide relationship add new button', async () => {
await page.goto(url.create)
const locator1 = page.locator(
'#relationWithAllowEditToFalse-add-new .relationship-add-new__add-button',
)
await expect(locator1).toHaveCount(1)
// expect the button to not exist in the field
const locator2 = page.locator(
'#relationWithAllowCreateToFalse-add-new .relationship-add-new__add-button',
)
await expect(locator2).toHaveCount(0)
})
test('should hide relationship edit button', async () => {
await page.goto(url.create)
const locator1 = page
.locator('#field-relationWithAllowEditToFalse')
await expect(locator1).toHaveCount(0)
const locator2 = page
.locator('#field-relationWithAllowCreateToFalse')
await expect(locator2).toHaveCount(1)
// The reason why I check for locator 1 again is that I've noticed that sometimes
// the default value does not appear after the first locator is tested. IDK why.
await expect(locator1).toHaveCount(0)
})
test('should hide edit button in main doc when relationship deleted', async () => {
const createdRelatedDoc = await payload.create({
collection: textFieldsSlug,
data: {
text: 'doc to be deleted',
},
})
const doc = await payload.create({
collection: relationshipFieldsSlug,
data: {
relationship: {
value: createdRelatedDoc.id,
relationTo: textFieldsSlug,
},
},
})
await payload.delete({
collection: textFieldsSlug,
id: createdRelatedDoc.id,
})
await page.goto(url.edit(doc.id))
const editBtn = page.locator(
'#field-relationship button.relationship--single-value__drawer-toggler',
)
await expect(editBtn).toHaveCount(0)
})
// TODO: Flaky test in CI - fix this. https://github.com/payloadcms/payload/actions/runs/8910825395/job/24470963991
test.skip('should clear relationship values', async () => {
await page.goto(url.create)
const field = page.locator('#field-relationship')
// wait for relationship options to load
const textFieldPromise = page.waitForResponse(/api\/text-fields/)
const arrayFieldPromise = page.waitForResponse(/api\/array-fields/)
await field.click()
await textFieldPromise
await arrayFieldPromise
await page.locator('.rs__option:has-text("Seeded text document")').click()
await field.locator('.clear-indicator').click()
await expect(field.locator('.rs__placeholder')).toBeVisible()
})
// TODO: React-Select not loading things sometimes. Fix later
test.skip('should display `hasMany` polymorphic relationships', async () => {
await page.goto(url.create)
const field = page.locator('#field-relationHasManyPolymorphic')
await field.click()
await page
.locator('.rs__option', {
hasText: exactText('Seeded text document'),
})
.click()
await expect(
page
.locator('#field-relationHasManyPolymorphic .relationship--multi-value-label__text', {
hasText: exactText('Seeded text document'),
})
.first(),
).toBeVisible()
// await fill the required fields then save the document and check again
await page.locator('#field-relationship').click()
await page.locator('#field-relationship .rs__option:has-text("Seeded text document")').click()
await saveDocAndAssert(page)
const valueAfterSave = page.locator('#field-relationHasManyPolymorphic .multi-value').first()
await expect(
valueAfterSave
.locator('.relationship--multi-value-label__text', {
hasText: exactText('Seeded text document'),
})
.first(),
).toBeVisible()
})
test('should populate relationship dynamic default value', async () => {
await page.goto(url.create)
await expect(
page.locator('#field-relationWithDynamicDefault .relationship--single-value__text'),
await expect(
page.locator('#field-relationHasManyWithDynamicDefault .relationship--single-value__text'),
})
test('should filter relationship options', async () => {
await page.goto(url.create)
await page.locator('#field-relationship .rs__control').click()
await page.keyboard.type('seeded')
await page.locator('.rs__option:has-text("Seeded text document")').click()
await saveDocAndAssert(page)
})
// Related issue: https://github.com/payloadcms/payload/issues/2815
test('should edit document in relationship drawer', async () => {
await page.goto(url.create)
// First fill out the relationship field, as it's required
await openCreateDocDrawer({ page, fieldSelector: '#field-relationship' })
await page
.locator('#field-relationship .relationship-add-new__relation-button--text-fields')
.click()
await page.locator('.drawer__content #field-text').fill('something')
await page.locator('[id^=doc-drawer_text-fields_1_] #action-save').click()
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
await page.locator('[id^=close-drawer__doc-drawer_text-fields_1_]').click()
await page.locator('#action-save').click()
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
// Create a new doc for the `relationshipHasMany` field
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).not.toContain('create')
await openCreateDocDrawer({ page, fieldSelector: '#field-relationshipHasMany' })
const value = 'Hello, world!'
await page.locator('.drawer__content #field-text').fill(value)
// Save and close the drawer
await page.locator('[id^=doc-drawer_text-fields_1_] #action-save').click()
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
await page.locator('[id^=close-drawer__doc-drawer_text-fields_1_]').click()
// Now open the drawer again to edit the `text` field _using the keyboard_
// Mimic real user behavior by typing into the field with spaces and backspaces
// Explicitly use both `down` and `type` to cover edge cases
await openDocDrawer({
page,
selector: '#field-relationshipHasMany button.relationship--multi-value-label__drawer-toggler',
})
await page.locator('[id^=doc-drawer_text-fields_1_] #field-text').click()
await page.keyboard.down('1')
await page.keyboard.type('23')
await expect(page.locator('[id^=doc-drawer_text-fields_1_] #field-text')).toHaveValue(
`${value}123`,
)
await page.keyboard.type('4567')
await page.keyboard.press('Backspace')
await expect(page.locator('[id^=doc-drawer_text-fields_1_] #field-text')).toHaveValue(
`${value}123456`,
)
// save drawer
await page.locator('[id^=doc-drawer_text-fields_1_] #action-save').click()
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
// close drawer
await page.locator('[id^=close-drawer__doc-drawer_text-fields_1_]').click()
// save document and reload
await page.locator('#action-save').click()
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
await page.reload()
// check if the value is saved
await expect(
page.locator('#field-relationshipHasMany .relationship--multi-value-label__text'),
).toHaveText(`${value}123456`)
})
// Drawers opened through the edit button are prone to issues due to the use of stopPropagation for certain
// events - specifically for drawers opened through the edit button. This test is to ensure that drawers
// opened through the edit button can be saved using the hotkey.
test('should save using hotkey in document drawer', async () => {
await page.goto(url.create)
// First fill out the relationship field, as it's required
await openCreateDocDrawer({ page, fieldSelector: '#field-relationship' })
await page.locator('#field-relationship .value-container').click()
await wait(500)
// Select "Seeded text document" relationship
await page.getByText('Seeded text document', { exact: true }).click()
// Need to wait to properly open drawer - without this the drawer state is flakey and closes before
// the text below can be filled before the save on the drawer
await wait(1000)
// Click edit button which opens drawer
await page.getByRole('button', { name: 'Edit Seeded text document' }).click()
// Fill 'text' field of 'Seeded text document'
await page.locator('.drawer__content #field-text').fill('some updated text value')
// Save drawer (not parent page) with hotkey
await saveDocHotkeyAndAssert(page)
const seededTextDocument = await payload.find({
collection: textFieldsSlug,
where: {
text: {
equals: 'some updated text value',
},
},
})
const relationshipDocuments = await payload.find({
collection: relationshipFieldsSlug,
})
// The Seeded text document should now have a text field with value 'some updated text value',
expect(seededTextDocument.docs.length).toEqual(1)
// but the relationship document should NOT exist, as the hotkey should have saved the drawer and not the parent page
// NOTE: the value here represents the number of documents _before_ the test was run
expect(relationshipDocuments.docs.length).toEqual(2)
})
describe('should create document within document drawer', () => {
test('has one', async () => {
await navigateToDoc(page, url)
const originalValue = await page
.locator('#field-relationship .relationship--single-value')
.textContent()
await openDocDrawer({
page,
selector: '#field-relationship .relationship--single-value__drawer-toggler',
})
const drawer1Content = page.locator('[id^=doc-drawer_text-fields_1_] .drawer__content')
const originalDrawerID = await drawer1Content.locator('.id-label').textContent()
await openDocControls(drawer1Content)
await drawer1Content.locator('#action-create').click()
await wait(1000) // wait for /form-state to return
const title = 'Created from drawer'
await drawer1Content.locator('#field-text').fill(title)
await saveDocAndAssert(page, '[id^=doc-drawer_text-fields_1_] .drawer__content #action-save')
const newDrawerID = drawer1Content.locator('.id-label')
await expect(newDrawerID).not.toHaveText(originalDrawerID)
await page.locator('[id^=doc-drawer_text-fields_1_] .drawer__close').click()
await page.locator('#field-relationship').scrollIntoViewIfNeeded()
await expect(
page.locator('#field-relationship .relationship--single-value__text', {
hasText: exactText(originalValue),
}),
).toBeHidden()
await expect(
page.locator('#field-relationship .relationship--single-value__text', {
hasText: exactText(title),
}),
).toBeVisible()
await page.locator('#field-relationship .rs__control').click()
await expect(
page.locator('.rs__option', {
hasText: exactText(title),
}),
).toBeVisible()
})
})
describe('should duplicate document within document drawer', () => {
test('has one', async () => {
await navigateToDoc(page, url)
await wait(500)
const fieldControl = page.locator('#field-relationship .rs__control')
const originalValue = await page
.locator('#field-relationship .relationship--single-value__text')
.textContent()
await fieldControl.click()
await expect(
page.locator('.rs__option', {
hasText: exactText(originalValue),
}),
).toBeVisible()
await openDocDrawer({
page,
selector: '#field-relationship .relationship--single-value__drawer-toggler',
})
const drawer1Content = page.locator('[id^=doc-drawer_text-fields_1_] .drawer__content')
const originalID = await drawer1Content.locator('.id-label').textContent()
const originalText = 'Text'
await drawer1Content.locator('#field-text').fill(originalText)
await saveDocAndAssert(page, '[id^=doc-drawer_text-fields_1_] .drawer__content #action-save')
await openDocControls(drawer1Content)
await drawer1Content.locator('#action-duplicate').click()
const duplicateID = drawer1Content.locator('.id-label')
await expect(duplicateID).not.toHaveText(originalID)
await page.locator('[id^=doc-drawer_text-fields_1_] .drawer__close').click()
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
await page.locator('#field-relationship').scrollIntoViewIfNeeded()
const newValue = `${originalText} - duplicate` // this is added via a `beforeDuplicate` hook
await expect(
page.locator('#field-relationship .relationship--single-value__text', {
hasText: exactText(originalValue),
}),
).toBeHidden()
await expect(
page.locator('#field-relationship .relationship--single-value__text', {
hasText: exactText(newValue),
}),
).toBeVisible()
await page.locator('#field-relationship .rs__control').click()
await expect(
page.locator('.rs__option', {
hasText: exactText(newValue),
}),
).toBeVisible()
})
})
describe('should delete document within document drawer', () => {
test('has one', async () => {
await navigateToDoc(page, url)
await wait(500)
const originalValue = await page
.locator('#field-relationship .relationship--single-value__text')
.textContent()
await page.locator('#field-relationship .rs__control').click()
await expect(
page.locator('#field-relationship .rs__option', {
hasText: exactText(originalValue),
}),
).toBeVisible()
await openDocDrawer({
page,
selector: '#field-relationship button.relationship--single-value__drawer-toggler',
})
const drawer1Content = page.locator('[id^=doc-drawer_text-fields_1_] .drawer__content')
const originalID = await drawer1Content.locator('.id-label').textContent()
await openDocControls(drawer1Content)
await drawer1Content.locator('#action-delete').click()
await page
.locator('[id^=delete-].payload__modal-item.confirmation-modal[open] button#confirm-action')
.click()
await expect(drawer1Content).toBeHidden()
await expect(
page.locator('#field-relationship .relationship--single-value__text'),
).toBeHidden()
await expect(page.locator('#field-relationship .rs__placeholder')).toBeVisible()
await page.locator('#field-relationship .rs__control').click()
await wait(500)
await expect(
page.locator('#field-relationship .rs__option', {
hasText: exactText(originalValue),
}),
).toBeHidden()
await expect(
page.locator('#field-relationship .rs__option', {
hasText: exactText(`Untitled - ${originalID}`),
}),
).toBeHidden()
})
})
// TODO: Fix this. This test flakes due to react select
test.skip('should bypass min rows validation when no rows present and field is not required', async () => {
await page.goto(url.create)
// First fill out the relationship field, as it's required
await openCreateDocDrawer({ page, fieldSelector: '#field-relationship' })
await page.locator('#field-relationship .value-container').click()
await page.getByText('Seeded text document', { exact: true }).click()
await saveDocAndAssert(page)
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
})
test('should fail min rows validation when rows are present', async () => {
await page.goto(url.create)
// First fill out the relationship field, as it's required
await openCreateDocDrawer({ page, fieldSelector: '#field-relationship' })
await page.locator('#field-relationship .value-container').click()
await page.getByText('Seeded text document', { exact: true }).click()
// Need to wait to allow for field to retrieve documents before the save occurs
await wait(200)
await page.locator('#field-relationshipWithMinRows .value-container').click()
await page
.locator('#field-relationshipWithMinRows .rs__option:has-text("Seeded text document")')
.click()
await page.click('#action-save', { delay: 100 })
await assertToastErrors({
page,
errors: ['Relationship With Min Rows'],
})
})
test('should sort relationship options by sortOptions property (ID in ascending order)', async () => {
await page.goto(url.create)
const field = page.locator('#field-relationship')
await field.click()
await wait(400)
const textDocsGroup = page.locator('.rs__group-heading:has-text("Text Fields")')
const firstTextDocOption = textDocsGroup.locator('+div .rs__option').first()
const firstOptionLabel = await firstTextDocOption.textContent()
expect(firstOptionLabel?.trim()).toBe('Another text document')
})
test('should sort relationHasManyPolymorphic options by sortOptions property: text-fields collection (items in descending order)', async () => {
await page.goto(url.create)
const field = page.locator('#field-relationHasManyPolymorphic')
// wait for relationship options to load
const textFieldPromise = page.waitForResponse(/api\/text-fields/)
const arrayFieldPromise = page.waitForResponse(/api\/array-fields/)
await field.click()
await textFieldPromise
await arrayFieldPromise
const textDocsGroup = page.locator('.rs__group-heading:has-text("Text Fields")')
const firstTextDocOption = textDocsGroup.locator('+div .rs__option').first()
const firstOptionLabel = firstTextDocOption
await expect(firstOptionLabel).toHaveText('Seeded text document')
})
test('should allow filtering by relationship field / equals', async () => {
const textDoc = await createTextFieldDoc()
await createRelationshipFieldDoc({ value: textDoc.id, relationTo: 'text-fields' })
await page.goto(url.list)
await addListFilter({
page,
fieldLabel: 'Relationship',
operatorLabel: 'equals',
value: 'some text',
})
await expect(page.locator(tableRowLocator)).toHaveCount(1)
})
test('should not allow filtering by relationship field hasMany false / in & not in', async () => {
await page.goto(url.list)
await openListFilters(page, {})
const whereBuilder = page.locator('.where-builder')
await whereBuilder.locator('.where-builder__add-first-filter').click()
const conditionField = whereBuilder.locator('.condition__field')
await conditionField.click()
await conditionField
.locator('.rs__option', {
hasText: exactText('Relationship'),
})
?.click()
await expect(whereBuilder.locator('.condition__field')).toContainText('Relationship')
const operatorInput = whereBuilder.locator('.condition__operator')
await operatorInput.click()
const operatorOptions = operatorInput.locator('.rs__option')
const optionTexts = await operatorOptions.allTextContents()
await expect.poll(() => optionTexts).not.toContain('is in')
await expect.poll(() => optionTexts).not.toContain('is not in')
})
})
async function createTextFieldDoc(overrides?: Partial<TextField>): Promise<TextField> {
return payload.create({
collection: 'text-fields',
data: {
text: 'some text',
localizedText: 'some localized text',
...overrides,
},
}) as unknown as Promise<TextField>
}
async function createRelationshipFieldDoc(
relationship: RelationshipField['relationship'],
overrides?: Partial<RelationshipField>,
): Promise<RelationshipField> {
return payload.create({
collection: 'relationship-fields',
data: {
relationship,
...overrides,
},
}) as unknown as Promise<RelationshipField>
}