diff --git a/packages/next/src/views/Version/RenderFieldsToDiff/fields/Iterable/index.tsx b/packages/next/src/views/Version/RenderFieldsToDiff/fields/Iterable/index.tsx index b6bd2c3c322..de574b86b1b 100644 --- a/packages/next/src/views/Version/RenderFieldsToDiff/fields/Iterable/index.tsx +++ b/packages/next/src/views/Version/RenderFieldsToDiff/fields/Iterable/index.tsx @@ -17,10 +17,10 @@ const Iterable: React.FC = ({ comparison, diffComponents, field, + fieldPermissions, i18n, locale, locales, - permissions, version, }) => { const versionRowCount = Array.isArray(version) ? version.length : 0 @@ -86,7 +86,7 @@ const Iterable: React.FC = ({ = ({ diffComponents, disableGutter = false, field, + fieldPermissions, fields, i18n, locale, locales, - permissions, version, }) => { return ( @@ -38,7 +38,7 @@ const Nested: React.FC = ({ > = ({ comparison, diffComponents, field, + fieldPermissions, i18n, locale, locales, - permissions, version, }) => { return ( @@ -30,12 +30,12 @@ const Tabs: React.FC> = ({ comparison={comparison?.[tab.name]} diffComponents={diffComponents} field={field} + fieldPermissions={fieldPermissions} fields={tab.fields} i18n={i18n} key={i} locale={locale} locales={locales} - permissions={permissions} version={version?.[tab.name]} /> ) @@ -45,7 +45,7 @@ const Tabs: React.FC> = ({ = { readonly diffMethod?: DiffMethod readonly disableGutter?: boolean readonly field: TField + readonly fieldPermissions?: + | { + [key: string]: SanitizedFieldPermissions + } + | true readonly fields: ClientField[] readonly i18n: I18nClient readonly isRichText?: boolean readonly locale?: string readonly locales?: string[] - readonly permissions?: - | { - [key: string]: SanitizedFieldPermissions - } - | true readonly version: any } diff --git a/packages/next/src/views/Version/RenderFieldsToDiff/index.tsx b/packages/next/src/views/Version/RenderFieldsToDiff/index.tsx index ffe061771bf..340dcdf6429 100644 --- a/packages/next/src/views/Version/RenderFieldsToDiff/index.tsx +++ b/packages/next/src/views/Version/RenderFieldsToDiff/index.tsx @@ -57,7 +57,9 @@ const RenderFieldsToDiff: React.FC = ({ fieldPermissions?.[fieldName]?.read const subFieldPermissions = - fieldPermissions?.[fieldName] === true || fieldPermissions?.[fieldName]?.fields + fieldPermissions === true || + fieldPermissions?.[fieldName] === true || + fieldPermissions?.[fieldName]?.fields if (!hasPermission) { return null @@ -116,6 +118,7 @@ const RenderFieldsToDiff: React.FC = ({ comparison={comparison} diffComponents={diffComponents} field={field} + fieldPermissions={fieldPermissions} fields={[]} i18n={i18n} key={i} @@ -133,11 +136,11 @@ const RenderFieldsToDiff: React.FC = ({ diffComponents={diffComponents} disableGutter field={field} + fieldPermissions={fieldPermissions} fields={field.fields} i18n={i18n} key={i} locales={locales} - permissions={fieldPermissions} version={version} /> ) diff --git a/test/helpers/sdk/index.ts b/test/helpers/sdk/index.ts index efa8431e548..2c5cfb280ea 100644 --- a/test/helpers/sdk/index.ts +++ b/test/helpers/sdk/index.ts @@ -21,7 +21,9 @@ export class PayloadTestSDK res.json()) - if (reduceJSON) return reduceJSON(json) + if (reduceJSON) { + return reduceJSON(json) + } return json } @@ -70,6 +74,17 @@ export class PayloadTestSDK({ + jwt, + ...args + }: FindArgs) => { + return this.fetch>({ + operation: 'findVersions', + args, + jwt, + }) + } + login = async ({ jwt, ...args diff --git a/test/helpers/sdk/types.ts b/test/helpers/sdk/types.ts index f072a1b1ef1..79bf3500cc0 100644 --- a/test/helpers/sdk/types.ts +++ b/test/helpers/sdk/types.ts @@ -25,7 +25,15 @@ export type GeneratedTypes = { export type FetchOptions = { args?: Record jwt?: string - operation: 'create' | 'delete' | 'find' | 'login' | 'sendEmail' | 'update' | 'updateGlobal' + operation: + | 'create' + | 'delete' + | 'find' + | 'findVersions' + | 'login' + | 'sendEmail' + | 'update' + | 'updateGlobal' reduceJSON?: (json: any) => R } diff --git a/test/versions/e2e.spec.ts b/test/versions/e2e.spec.ts index ef300e4db19..ab9421a28f2 100644 --- a/test/versions/e2e.spec.ts +++ b/test/versions/e2e.spec.ts @@ -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() + }) + }) })