chore: re-enables fields-relationship tests
This commit is contained in:
@@ -378,7 +378,11 @@ const RelationshipField: React.FC<RelationshipFieldProps> = (props) => {
|
||||
// When (`relationTo` || `filterOptions` || `locale`) changes, reset component
|
||||
// Note - effect should not run on first run
|
||||
useEffect(() => {
|
||||
if (hasLoadedFirstPageRef.current && menuIsOpen) {
|
||||
// If the menu is open while filterOptions changes
|
||||
// due to latency of getFormState and fast clicking into this field,
|
||||
// re-fetch options
|
||||
|
||||
if (hasLoadedFirstPageRef.current && menuIsOpen.current) {
|
||||
setIsLoading(true)
|
||||
void getResults({
|
||||
lastLoadedPage: {},
|
||||
@@ -390,11 +394,24 @@ const RelationshipField: React.FC<RelationshipFieldProps> = (props) => {
|
||||
})
|
||||
}
|
||||
|
||||
// If the menu is not open, still reset the field state
|
||||
// because we need to get new options next time the menu
|
||||
// opens by the user
|
||||
|
||||
dispatchOptions({ type: 'CLEAR' })
|
||||
setLastFullyLoadedRelation(-1)
|
||||
setLastLoadedPage({})
|
||||
hasLoadedFirstPageRef.current = false
|
||||
}, [relationTo, filterOptions, locale, menuIsOpen, getResults, valueRef, hasLoadedFirstPageRef])
|
||||
}, [
|
||||
relationTo,
|
||||
filterOptions,
|
||||
locale,
|
||||
menuIsOpen,
|
||||
getResults,
|
||||
valueRef,
|
||||
hasLoadedFirstPageRef,
|
||||
path,
|
||||
])
|
||||
|
||||
const onSave = useCallback<DocumentDrawerProps['onSave']>(
|
||||
(args) => {
|
||||
|
||||
@@ -244,8 +244,10 @@ describe('fields - relationship', () => {
|
||||
|
||||
// fill the first relation field
|
||||
const field = page.locator('#field-relationship')
|
||||
|
||||
await field.click({ delay: 100 })
|
||||
const options = page.locator('.rs__option')
|
||||
|
||||
await options.nth(0).click()
|
||||
await expect(field).toContainText(relationOneDoc.id)
|
||||
|
||||
@@ -262,18 +264,21 @@ describe('fields - relationship', () => {
|
||||
await options.nth(1).click()
|
||||
await expect(field).toContainText(anotherRelationOneDoc.id)
|
||||
|
||||
// Need to wait form state to come back
|
||||
// before clicking save
|
||||
await wait(2000)
|
||||
|
||||
// Now, save the document. This should fail, as the filitered field doesn't match the selected relationship value
|
||||
await page.locator('#action-save').click()
|
||||
await expect(page.locator('.Toastify')).toContainText(`is invalid: ${fieldName}`)
|
||||
|
||||
// TODO: Playwright is not passing because of a race condition
|
||||
// that is difficult to pinpoint.
|
||||
// Need to revisit this
|
||||
|
||||
// then verify that the filtered field's options match
|
||||
filteredField = page.locator(`#field-${fieldName} .react-select`)
|
||||
|
||||
await filteredField.click({ delay: 100 })
|
||||
|
||||
filteredOptions = filteredField.locator('.rs__option')
|
||||
|
||||
await expect(filteredOptions).toHaveCount(2) // two options because the currently selected option is still there
|
||||
await filteredOptions.nth(1).click()
|
||||
await expect(filteredField).toContainText(anotherRelationOneDoc.id)
|
||||
@@ -283,12 +288,12 @@ describe('fields - relationship', () => {
|
||||
}
|
||||
|
||||
// TODO: Flaky test. Fix this! (This is an actual issue not just an e2e flake)
|
||||
test.skip('should allow dynamic filterOptions', async () => {
|
||||
test('should allow dynamic filterOptions', async () => {
|
||||
await runFilterOptionsTest('relationshipFiltered')
|
||||
})
|
||||
|
||||
// TODO: Flaky test. Fix this! (This is an actual issue not just an e2e flake)
|
||||
test.skip('should allow dynamic async filterOptions', async () => {
|
||||
test('should allow dynamic async filterOptions', async () => {
|
||||
await runFilterOptionsTest('relationshipFilteredAsync')
|
||||
})
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
],
|
||||
"paths": {
|
||||
"@payload-config": [
|
||||
"./test/uploads/config.ts"
|
||||
"./test/fields-relationship/config.ts"
|
||||
],
|
||||
"@payloadcms/live-preview": [
|
||||
"./packages/live-preview/src"
|
||||
|
||||
Reference in New Issue
Block a user