fix(next): properly threads field permissions through versions diff (#9543)

The version diff view at
`/admin/collections/:collection/:id/versions/:version` was not properly
displaying diffs for iterable fields, such as blocks. There were two
main things wrong here:

1. Fields not properly inheriting parent permissions based on the new
sanitized permissions pattern in #7335
1. The diff components were expecting `permissions` but receiving
`fieldPermissions`. This was not picked up by TS because of our use of
dynamic keys when choosing which component to render for that particular
field. We should change this in the future to use a switch case that
explicitly renders each diff component. This way props are strictly
typed.
This commit is contained in:
Jacob Fletcher
2024-11-26 14:33:10 -05:00
committed by GitHub
parent b61622019e
commit f19053e049
8 changed files with 114 additions and 17 deletions

View File

@@ -734,4 +734,75 @@ describe('versions', () => {
await expect(publishSpecificLocale).toContainText('English')
})
})
describe('Versions diff view', () => {
let postID: string
let versionID: string
beforeAll(() => {
url = new AdminUrlUtil(serverURL, draftCollectionSlug)
})
beforeEach(async () => {
const newPost = await payload.create({
collection: draftCollectionSlug,
data: {
title: 'new post',
description: 'new description',
},
})
postID = newPost.id
await payload.update({
collection: draftCollectionSlug,
id: postID,
draft: true,
data: {
title: 'draft post',
description: 'draft description',
blocksField: [
{
blockName: 'block1',
blockType: 'block',
text: 'block text',
},
],
},
})
const versions = await payload.findVersions({
collection: draftCollectionSlug,
where: {
parent: { equals: postID },
},
})
versionID = versions.docs[0].id
})
test('should render diff', async () => {
const versionURL = `${serverURL}/admin/collections/${draftCollectionSlug}/${postID}/versions/${versionID}`
await page.goto(versionURL)
await page.waitForURL(versionURL)
await expect(page.locator('.render-field-diffs').first()).toBeVisible()
})
test('should render diff for nested fields', async () => {
const versionURL = `${serverURL}/admin/collections/${draftCollectionSlug}/${postID}/versions/${versionID}`
await page.goto(versionURL)
await page.waitForURL(versionURL)
await expect(page.locator('.render-field-diffs').first()).toBeVisible()
const blocksDiffLabel = page.locator('.field-diff-label', {
hasText: exactText('Blocks Field'),
})
await expect(blocksDiffLabel).toBeVisible()
const blocksDiff = blocksDiffLabel.locator('+ .iterable-diff__wrap > .render-field-diffs')
await expect(blocksDiff).toBeVisible()
const blockTypeDiffLabel = blocksDiff.locator('.render-field-diffs__field').first()
await expect(blockTypeDiffLabel).toBeVisible()
})
})
})