Skip to content

Commit

Permalink
test(e2e): add discard action test
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Jan 6, 2025
1 parent 001dda7 commit 36a02e0
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/e2e/tests/document-actions/discard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {expect} from '@playwright/test'
import {test} from '@sanity/test'

test(`document panel displays correct title after discarding changes`, async ({
page,
createDraftDocument,
}) => {
/** ---------- START OF PUBLISH ---------- */

const title = 'Test Title'
const changedTitle = 'Title changed'

await createDraftDocument('/test/content/book')
await page.getByTestId('field-title').getByTestId('string-input').fill(title)

// Ensure the correct title is displayed before publishing.
await expect(page.getByTestId('document-panel-document-title')).toHaveText(title)

// Focus the publish button to trigger the tooltip showing the keyboard shortcut
page.getByTestId('action-publish').focus()

// There is a delay before the tooltip opens, let's explicitly wait for it
await page.waitForTimeout(300)

// Wait for the document to be published.
page.getByTestId('action-publish').click()
await expect(page.getByText('Published just now')).toBeVisible()

// Ensure the correct title is displayed after publishing.
expect(page.getByTestId('document-panel-document-title')).toHaveText(title)

/** ---------- END OF PUBLISH ---------- */

// change title
await page.getByTestId('field-title').getByTestId('string-input').fill(changedTitle)

// open action menu
page.getByTestId('action-menu-button').click()
await expect(page.getByTestId('action-Discardchanges')).toBeVisible()

// Discard changes
page.getByTestId('action-Discardchanges').click()

// confirm discard
page.getByTestId('confirm-dialog-confirm-button').click()

// Ensure the correct title is displayed after discarding changes.

await expect(page.getByText('Published just now')).toBeVisible()
expect(page.getByTestId('document-panel-document-title')).toHaveText(title)
})

0 comments on commit 36a02e0

Please sign in to comment.