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
|
// When (`relationTo` || `filterOptions` || `locale`) changes, reset component
|
||||||
// Note - effect should not run on first run
|
// Note - effect should not run on first run
|
||||||
useEffect(() => {
|
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)
|
setIsLoading(true)
|
||||||
void getResults({
|
void getResults({
|
||||||
lastLoadedPage: {},
|
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' })
|
dispatchOptions({ type: 'CLEAR' })
|
||||||
setLastFullyLoadedRelation(-1)
|
setLastFullyLoadedRelation(-1)
|
||||||
setLastLoadedPage({})
|
setLastLoadedPage({})
|
||||||
hasLoadedFirstPageRef.current = false
|
hasLoadedFirstPageRef.current = false
|
||||||
}, [relationTo, filterOptions, locale, menuIsOpen, getResults, valueRef, hasLoadedFirstPageRef])
|
}, [
|
||||||
|
relationTo,
|
||||||
|
filterOptions,
|
||||||
|
locale,
|
||||||
|
menuIsOpen,
|
||||||
|
getResults,
|
||||||
|
valueRef,
|
||||||
|
hasLoadedFirstPageRef,
|
||||||
|
path,
|
||||||
|
])
|
||||||
|
|
||||||
const onSave = useCallback<DocumentDrawerProps['onSave']>(
|
const onSave = useCallback<DocumentDrawerProps['onSave']>(
|
||||||
(args) => {
|
(args) => {
|
||||||
|
|||||||
@@ -244,8 +244,10 @@ describe('fields - relationship', () => {
|
|||||||
|
|
||||||
// fill the first relation field
|
// fill the first relation field
|
||||||
const field = page.locator('#field-relationship')
|
const field = page.locator('#field-relationship')
|
||||||
|
|
||||||
await field.click({ delay: 100 })
|
await field.click({ delay: 100 })
|
||||||
const options = page.locator('.rs__option')
|
const options = page.locator('.rs__option')
|
||||||
|
|
||||||
await options.nth(0).click()
|
await options.nth(0).click()
|
||||||
await expect(field).toContainText(relationOneDoc.id)
|
await expect(field).toContainText(relationOneDoc.id)
|
||||||
|
|
||||||
@@ -262,18 +264,21 @@ describe('fields - relationship', () => {
|
|||||||
await options.nth(1).click()
|
await options.nth(1).click()
|
||||||
await expect(field).toContainText(anotherRelationOneDoc.id)
|
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
|
// 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 page.locator('#action-save').click()
|
||||||
await expect(page.locator('.Toastify')).toContainText(`is invalid: ${fieldName}`)
|
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
|
// then verify that the filtered field's options match
|
||||||
filteredField = page.locator(`#field-${fieldName} .react-select`)
|
filteredField = page.locator(`#field-${fieldName} .react-select`)
|
||||||
|
|
||||||
await filteredField.click({ delay: 100 })
|
await filteredField.click({ delay: 100 })
|
||||||
|
|
||||||
filteredOptions = filteredField.locator('.rs__option')
|
filteredOptions = filteredField.locator('.rs__option')
|
||||||
|
|
||||||
await expect(filteredOptions).toHaveCount(2) // two options because the currently selected option is still there
|
await expect(filteredOptions).toHaveCount(2) // two options because the currently selected option is still there
|
||||||
await filteredOptions.nth(1).click()
|
await filteredOptions.nth(1).click()
|
||||||
await expect(filteredField).toContainText(anotherRelationOneDoc.id)
|
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)
|
// 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')
|
await runFilterOptionsTest('relationshipFiltered')
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Flaky test. Fix this! (This is an actual issue not just an e2e flake)
|
// 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')
|
await runFilterOptionsTest('relationshipFilteredAsync')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@payload-config": [
|
"@payload-config": [
|
||||||
"./test/uploads/config.ts"
|
"./test/fields-relationship/config.ts"
|
||||||
],
|
],
|
||||||
"@payloadcms/live-preview": [
|
"@payloadcms/live-preview": [
|
||||||
"./packages/live-preview/src"
|
"./packages/live-preview/src"
|
||||||
@@ -160,4 +160,4 @@
|
|||||||
".next/types/**/*.ts",
|
".next/types/**/*.ts",
|
||||||
"scripts/**/*.ts"
|
"scripts/**/*.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user