fix: access control test suite (#5548)
* chore: improve flakiness with access control test suite * fix issue with redirecting from a drawer * chore: watches for created id in drawers --------- Co-authored-by: James <james@trbl.design>
This commit is contained in:
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -217,7 +217,7 @@ jobs:
|
|||||||
# find test -type f -name 'e2e.spec.ts' | sort | xargs dirname | xargs -I {} basename {}
|
# find test -type f -name 'e2e.spec.ts' | sort | xargs dirname | xargs -I {} basename {}
|
||||||
suite:
|
suite:
|
||||||
- _community
|
- _community
|
||||||
# - access-control
|
- access-control
|
||||||
# - admin
|
# - admin
|
||||||
- auth
|
- auth
|
||||||
- field-error-states
|
- field-error-states
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ export const DefaultEditView: React.FC = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEditing) {
|
if (!isEditing && depth < 2) {
|
||||||
// Redirect to the same locale if it's been set
|
// Redirect to the same locale if it's been set
|
||||||
const redirectRoute = `${adminRoute}/collections/${collectionSlug}/${json?.doc?.id}${locale ? `?locale=${locale}` : ''}`
|
const redirectRoute = `${adminRoute}/collections/${collectionSlug}/${json?.doc?.id}${locale ? `?locale=${locale}` : ''}`
|
||||||
router.push(redirectRoute)
|
router.push(redirectRoute)
|
||||||
@@ -144,6 +144,7 @@ export const DefaultEditView: React.FC = () => {
|
|||||||
id,
|
id,
|
||||||
entitySlug,
|
entitySlug,
|
||||||
user,
|
user,
|
||||||
|
depth,
|
||||||
collectionSlug,
|
collectionSlug,
|
||||||
getVersions,
|
getVersions,
|
||||||
getDocPermissions,
|
getDocPermissions,
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export const DocumentDrawerContent: React.FC<DocumentDrawerProps> = ({
|
|||||||
const { closeModal, modalState, toggleModal } = useModal()
|
const { closeModal, modalState, toggleModal } = useModal()
|
||||||
const locale = useLocale()
|
const locale = useLocale()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const [createdID, setCreatedID] = useState()
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
const [collectionConfig] = useRelatedCollections(collectionSlug)
|
const [collectionConfig] = useRelatedCollections(collectionSlug)
|
||||||
const { formQueryParams } = useFormQueryParams()
|
const { formQueryParams } = useFormQueryParams()
|
||||||
@@ -69,6 +70,7 @@ export const DocumentDrawerContent: React.FC<DocumentDrawerProps> = ({
|
|||||||
|
|
||||||
const onSave = useCallback<DocumentDrawerProps['onSave']>(
|
const onSave = useCallback<DocumentDrawerProps['onSave']>(
|
||||||
(args) => {
|
(args) => {
|
||||||
|
setCreatedID(args.doc.id)
|
||||||
if (typeof onSaveFromProps === 'function') {
|
if (typeof onSaveFromProps === 'function') {
|
||||||
void onSaveFromProps({
|
void onSaveFromProps({
|
||||||
...args,
|
...args,
|
||||||
@@ -113,7 +115,7 @@ export const DocumentDrawerContent: React.FC<DocumentDrawerProps> = ({
|
|||||||
// Same reason as above. We need to fully-fetch the docPreferences from the server. This is done in DocumentInfoProvider if we set it to null here.
|
// Same reason as above. We need to fully-fetch the docPreferences from the server. This is done in DocumentInfoProvider if we set it to null here.
|
||||||
hasSavePermission={null}
|
hasSavePermission={null}
|
||||||
// isLoading,
|
// isLoading,
|
||||||
id={id}
|
id={id || createdID}
|
||||||
isEditing={isEditing}
|
isEditing={isEditing}
|
||||||
onLoadError={onLoadError}
|
onLoadError={onLoadError}
|
||||||
onSave={onSave}
|
onSave={onSave}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
} from '../helpers.js'
|
} from '../helpers.js'
|
||||||
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
|
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
|
||||||
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
|
import { initPayloadE2E } from '../helpers/initPayloadE2E.js'
|
||||||
|
import { POLL_TOPASS_TIMEOUT } from '../playwright.config.js'
|
||||||
import config from './config.js'
|
import config from './config.js'
|
||||||
import {
|
import {
|
||||||
docLevelAccessSlug,
|
docLevelAccessSlug,
|
||||||
@@ -258,8 +259,11 @@ describe('access control', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// TODO: Test flakes. In CI, test global does not appear in nav. Perhaps the checkbox setValue is not triggered BEFORE the document is saved, as the custom save button can be clicked even if the form has not been set to modified.
|
// TODO: Test flakes. In CI, test global does not appear in nav. Perhaps the checkbox setValue is not triggered BEFORE the document is saved, as the custom save button can be clicked even if the form has not been set to modified.
|
||||||
test.skip('should show test global immediately after allowing access', async () => {
|
test('should show test global immediately after allowing access', async () => {
|
||||||
await page.goto(`${serverURL}/admin/globals/settings`)
|
const url = `${serverURL}/admin/globals/settings`
|
||||||
|
await page.goto(url)
|
||||||
|
|
||||||
|
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain(url)
|
||||||
|
|
||||||
await openNav(page)
|
await openNav(page)
|
||||||
|
|
||||||
@@ -278,8 +282,11 @@ describe('access control', () => {
|
|||||||
|
|
||||||
await openNav(page)
|
await openNav(page)
|
||||||
|
|
||||||
// Now test collection should appear in the menu.
|
const globalTest = page.locator('#nav-global-test')
|
||||||
await expect(page.locator('#nav-global-test')).toBeVisible()
|
|
||||||
|
await expect(async () => await globalTest.isVisible()).toPass({
|
||||||
|
timeout: POLL_TOPASS_TIMEOUT,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('maintain access control in document drawer', async () => {
|
test('maintain access control in document drawer', async () => {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@payload-config": [
|
"@payload-config": [
|
||||||
"./test/versions/config.ts"
|
"./test/_community/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