Skip to content

Commit

Permalink
test(e2e): update test for when weak property is set up in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Jan 8, 2025
1 parent 7639fe8 commit cf00805
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
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'}],
},
],
}
52 changes: 50 additions & 2 deletions test/e2e/tests/inputs/reference.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
})
})

0 comments on commit cf00805

Please sign in to comment.