Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add checks for properties in reference tests #8214

Draft
wants to merge 3 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dev/test-studio/schema/debug/simpleReferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'}],
},
],
}
131 changes: 131 additions & 0 deletions test/e2e/tests/inputs/reference.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,135 @@ 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,
}) => {
// 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…'}).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(
'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()
})

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()
})
})
Loading