From e9224d276bd047b911be8a257c57bbd749014b26 Mon Sep 17 00:00:00 2001 From: Rita Date: Wed, 8 Jan 2025 15:02:15 +0100 Subject: [PATCH 1/3] test(e2e): add checks for properties in reference tests --- test/e2e/tests/inputs/reference.spec.ts | 81 +++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/test/e2e/tests/inputs/reference.spec.ts b/test/e2e/tests/inputs/reference.spec.ts index 7f3978fdb45..8b2c2efd04b 100644 --- a/test/e2e/tests/inputs/reference.spec.ts +++ b/test/e2e/tests/inputs/reference.spec.ts @@ -64,4 +64,85 @@ withDefaultClient((context) => { publishButton.click() await expect(paneFooter).toContainText('Published just now') }) + + test(`_strengthenOnPublish and _weak properties exist when adding reference`, async ({ + page, + createDraftDocument, + }) => { + const originalTitle = 'Initial Doc' + + await createDraftDocument('/test/content/input-standard;referenceTest') + page.getByTestId('string-input').fill(originalTitle) + + /** create reference */ + await page + .locator( + 'div:nth-child(4) > div > div > div > div:nth-child(2) > div > div > div > div > div > div > button', + ) + .click() + + // Wait for the new document referenced to be created & loaded + await expect(page.getByTestId('document-panel-document-title').nth(1)).toContainText( + 'New Reference test', + ) + + // switch to original doc + page.getByRole('button', {name: originalTitle}).click() + + // open the context menu + page.getByTestId('pane-context-menu-button').first().click() + page.getByTestId('action-inspect').click() + + /** Checks that the properties were added when a weak reference is added */ + await expect( + page.getByText('aliasRef._strengthenOnPublish_strengthenOnPublish:{…} 3 properties'), + ).toBeVisible() + await expect(page.getByText('aliasRef._weak_weak:true')).toBeVisible() + }) + + test(`_strengthenOnPublish and _weak properties are removed when the reference and document are published`, async ({ + page, + createDraftDocument, + }) => { + test.slow() + const originalTitle = 'Initial Doc' + const documentStatus = page.getByTestId('pane-footer-document-status') + + await createDraftDocument('/test/content/input-debug;simpleReferences') + page.getByTestId('string-input').fill(originalTitle) + + /** create reference */ + await expect(page.getByRole('button', {name: 'Create…'})).toBeVisible() + page.getByRole('button', {name: 'Create…'}).click() + + // wait for the reference document to open + await expect(page.getByTestId('document-panel-document-title').nth(1)).toContainText( + 'New Simple references test', + ) + + // update and publish the reference + page.getByTestId('string-input').nth(1).fill('Reference test') + await expect(page.getByTestId('document-panel-document-title').nth(1)).toContainText( + 'Reference test', + ) + page.getByTestId('action-publish').nth(1).click() // publish reference + await expect(documentStatus.nth(1)).toContainText('Published just now') + + /** --- IN ORIGINAL DOC --- */ + page.getByRole('button', {name: originalTitle}).click() + + page.getByTestId('action-publish').first().click() // publish reference + + await expect(documentStatus.first()).toContainText('Published just now') + + // open the context menu + page.getByTestId('pane-context-menu-button').first().click() + page.getByTestId('action-inspect').click() + + /** Checks that the properties were added when a weak reference is added */ + await expect( + page.getByText('referenceField._strengthenOnPublish_strengthenOnPublish:{…} 3 properties'), + ).not.toBeVisible() + await expect(page.getByText('referenceField._weak_weak:true')).not.toBeVisible() + }) }) From 7639fe86ffec8343d5cd45ec06c9689df000f171 Mon Sep 17 00:00:00 2001 From: Rita Date: Wed, 8 Jan 2025 15:06:33 +0100 Subject: [PATCH 2/3] docs(e2e): update comments --- test/e2e/tests/inputs/reference.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/e2e/tests/inputs/reference.spec.ts b/test/e2e/tests/inputs/reference.spec.ts index 8b2c2efd04b..143d9b0f64e 100644 --- a/test/e2e/tests/inputs/reference.spec.ts +++ b/test/e2e/tests/inputs/reference.spec.ts @@ -104,6 +104,8 @@ withDefaultClient((context) => { page, createDraftDocument, }) => { + // this is in a situation where the _strengthenOnPublish.weak is not set + test.slow() const originalTitle = 'Initial Doc' const documentStatus = page.getByTestId('pane-footer-document-status') From cf008057eb6936b3f3f80ce503f263998e6cc3c7 Mon Sep 17 00:00:00 2001 From: Rita Date: Wed, 8 Jan 2025 15:24:19 +0100 Subject: [PATCH 3/3] test(e2e): update test for when weak property is set up in schema --- .../schema/debug/simpleReferences.js | 8 +++ test/e2e/tests/inputs/reference.spec.ts | 52 ++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/dev/test-studio/schema/debug/simpleReferences.js b/dev/test-studio/schema/debug/simpleReferences.js index e373c2bc4d3..dc9708c8b34 100644 --- a/dev/test-studio/schema/debug/simpleReferences.js +++ b/dev/test-studio/schema/debug/simpleReferences.js @@ -20,5 +20,13 @@ export const simpleReferences = { type: 'reference', to: [{type: 'simpleReferences'}], }, + { + name: 'referenceFieldWeak', + title: 'Reference field', + description: 'A simple reference field where weak is set to true', + type: 'reference', + weak: true, + to: [{type: 'simpleReferences'}], + }, ], } diff --git a/test/e2e/tests/inputs/reference.spec.ts b/test/e2e/tests/inputs/reference.spec.ts index 143d9b0f64e..5e19dc92be5 100644 --- a/test/e2e/tests/inputs/reference.spec.ts +++ b/test/e2e/tests/inputs/reference.spec.ts @@ -114,8 +114,8 @@ withDefaultClient((context) => { page.getByTestId('string-input').fill(originalTitle) /** create reference */ - await expect(page.getByRole('button', {name: 'Create…'})).toBeVisible() - page.getByRole('button', {name: 'Create…'}).click() + await expect(page.getByRole('button', {name: 'Create…'}).first()).toBeVisible() + page.getByRole('button', {name: 'Create…'}).first().click() // wait for the reference document to open await expect(page.getByTestId('document-panel-document-title').nth(1)).toContainText( @@ -147,4 +147,52 @@ withDefaultClient((context) => { ).not.toBeVisible() await expect(page.getByText('referenceField._weak_weak:true')).not.toBeVisible() }) + + test(`when reference is set to weak: true, it shouldn't strength on publish`, async ({ + page, + createDraftDocument, + }) => { + // this is in a situation where the _strengthenOnPublish.weak is not set + + test.slow() + const originalTitle = 'Initial Doc' + const documentStatus = page.getByTestId('pane-footer-document-status') + + await createDraftDocument('/test/content/input-debug;simpleReferences') + page.getByTestId('string-input').fill(originalTitle) + + /** create reference */ + await expect(page.getByRole('button', {name: 'Create…'}).nth(1)).toBeVisible() + page.getByRole('button', {name: 'Create…'}).nth(1).click() + + // wait for the reference document to open + await expect(page.getByTestId('document-panel-document-title').nth(1)).toContainText( + 'New Simple references test', + ) + + // update and publish the reference + page.getByTestId('string-input').nth(1).fill('Reference test') + await expect(page.getByTestId('document-panel-document-title').nth(1)).toContainText( + 'Reference test', + ) + page.getByTestId('action-publish').nth(1).click() // publish reference + await expect(documentStatus.nth(1)).toContainText('Published just now') + + /** --- IN ORIGINAL DOC --- */ + page.getByRole('button', {name: originalTitle}).click() + + page.getByTestId('action-publish').first().click() // publish reference + + await expect(documentStatus.first()).toContainText('Published just now') + + // open the context menu + page.getByTestId('pane-context-menu-button').first().click() + page.getByTestId('action-inspect').click() + + /** Checks that the properties were added when a weak reference is added */ + await expect( + page.getByText('referenceField._strengthenOnPublish_strengthenOnPublish:{…} 3 properties'), + ).not.toBeVisible() + await expect(page.getByText('referenceField._weak_weak:true')).toBeVisible() + }) })