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): restore last e2e tests #7926

Merged
merged 10 commits into from
Dec 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {useIntentLink} from 'sanity/router'

import {MenuGroup, MenuItem, type PopoverProps} from '../../../ui-components'
import {type Intent} from '../../structureBuilder'
import {toLowerCaseNoSpaces} from '../../util/toLowerCaseNoSpaces'
import {type _PaneMenuItem, type _PaneMenuNode} from './types'

const MENU_GROUP_POPOVER_PROPS: PopoverProps = {
Expand Down Expand Up @@ -108,6 +109,7 @@ function PaneContextMenuItem(props: {disabled?: boolean; node: _PaneMenuItem}) {
pressed={node.selected}
text={title}
tone={node.tone}
data-testid={`action-${toLowerCaseNoSpaces(node.title)}`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice 🙂.

/>
</TooltipOfDisabled>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const FormView = forwardRef<HTMLDivElement, FormViewProps>(function FormV
const documentStore = useDocumentStore()
const presence = useDocumentPresence(documentId)
const {title} = useDocumentTitle()

// The `patchChannel` is an INTERNAL publish/subscribe channel that we use to notify form-builder
// nodes about both remote and local patches.
// - Used by the Portable Text input to modify selections.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import {Button, Tooltip} from '../../../../ui-components'
import {RenderActionCollectionState} from '../../../components'
import {HistoryRestoreAction} from '../../../documentActions'
import {toLowerCaseNoSpaces} from '../../../util/toLowerCaseNoSpaces'
import {useDocumentPane} from '../useDocumentPane'
import {ActionMenuButton} from './ActionMenuButton'
import {ActionStateDialog} from './ActionStateDialog'
Expand Down Expand Up @@ -58,7 +59,7 @@ const DocumentStatusBarActionsInner = memo(function DocumentStatusBarActionsInne
<Tooltip disabled={!tooltipContent} content={tooltipContent} placement="top">
<Stack>
<Button
data-testid={`action-${firstActionState.label}`}
data-testid={`action-${toLowerCaseNoSpaces(firstActionState.label)}`}
disabled={disabled || Boolean(firstActionState.disabled)}
icon={firstActionState.icon}
// eslint-disable-next-line react/jsx-handler-names
Expand Down
10 changes: 10 additions & 0 deletions packages/sanity/src/structure/util/toLowerCaseNoSpaces.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Remove the spaces and lower case the string
*
* @param str - string to remove the spaces and lower case
* @returns str with no spaces and lower case
*/
export function toLowerCaseNoSpaces(str: string | undefined): string {
if (!str) return ''
return str.toLocaleLowerCase().replaceAll(' ', '')
}
2 changes: 1 addition & 1 deletion test/e2e/tests/document-actions/delete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test(`published documents can be deleted`, async ({page, createDraftDocument}) =
await page.waitForTimeout(1000)

// Wait for the document to be published.
await page.getByTestId('action-Publish').click()
await page.getByTestId('action-publish').click()
expect(await paneFooter.textContent()).toMatch(/published/i)

await page.getByTestId('action-menu-button').click()
Expand Down
30 changes: 12 additions & 18 deletions test/e2e/tests/document-actions/discardChanges.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,48 @@ test(`isn't possible to discard changes if a changed document has no published v
await expect(discardChangesButton).toBeHidden()
})

/*
Test skipped due to on going developments around server actions that make them flaky
Re-enable this test when the server actions are stable
*/
test.skip(`is possible to discard changes if a changed document has a published version`, async ({
test(`is possible to discard changes if a changed document has a published version`, async ({
page,
createDraftDocument,
}) => {
await createDraftDocument('/test/content/book')

const titleInput = page.getByTestId('field-title').getByTestId('string-input')
const paneFooter = page.getByTestId('pane-footer')
const publishButton = page.getByTestId('action-Publish')
const publishButton = page.getByTestId('action-publish')
const actionMenuButton = page.getByTestId('action-menu-button')
const discardChangesButton = page.getByTestId('action-Discardchanges')

await titleInput.fill('This is a book')

publishButton.click()
await expect(paneFooter).toContainText('Published just now', {timeout: 50000})
// Wait for the document to be published.
await page.waitForTimeout(1_000)
await publishButton.click()
await expect(page.getByTestId('pane-footer-document-status')).toContainText('Published just now')

await titleInput.fill('This is not a book')

await actionMenuButton.click()
await expect(discardChangesButton).toBeEnabled()
})

/*
Test skipped due to on going developments around server actions that make them flaky
Re-enable this test when the server actions are stable
*/
test.skip(`displays the published document state after discarding changes`, async ({
test(`displays the published document state after discarding changes`, async ({
page,
createDraftDocument,
}) => {
await createDraftDocument('/test/content/book')

const titleInput = page.getByTestId('field-title').getByTestId('string-input')
const paneFooter = page.getByTestId('pane-footer')
const publishButton = page.getByTestId('action-Publish')
const publishButton = page.getByTestId('action-publish')
const actionMenuButton = page.getByTestId('action-menu-button')
const discardChangesButton = page.getByTestId('action-Discardchanges')
const confirmButton = page.getByTestId('confirm-dialog-confirm-button')

await titleInput.fill('This is a book')

publishButton.click()
await expect(paneFooter).toContainText('Published just now', {timeout: 50000})
// Wait for the document to be published.
await page.waitForTimeout(1_000)
await publishButton.click()
await expect(page.getByTestId('pane-footer-document-status')).toContainText('Published just now')

// Change the title.
await titleInput.fill('This is not a book')
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/tests/document-actions/publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test(`document panel displays correct title for published document`, async ({
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()
page.getByTestId('action-publish').focus()

// There is a delay before the tooltip opens, let's explicitly wait for it
await page.waitForTimeout(300)
Expand All @@ -28,7 +28,7 @@ test(`document panel displays correct title for published document`, async ({
expect(hotkeys).toHaveText(isMac ? 'CtrlOptionP' : 'CtrlAltP')

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

// Ensure the correct title is displayed after publishing.
Expand Down
98 changes: 50 additions & 48 deletions test/e2e/tests/document-actions/restore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import {expect} from '@playwright/test'
import {test} from '@sanity/test'

/*
Test skipped due to on going developments around server actions that make them flaky
Re-enable this test when the server actions are stable
*/
test.skip(`documents can be restored to an earlier revision`, async ({
page,
createDraftDocument,
}) => {
test(`documents can be restored to an earlier revision`, async ({page, createDraftDocument}) => {
const titleA = 'Title A'
const titleB = 'Title B'

const documentStatus = page.getByTestId('pane-footer-document-status')
const publishButton = page.getByTestId('action-Publish')
const restoreButton = page.getByTestId('action-Restore')
const publishButton = page.getByTestId('action-publish')
const restoreButton = page.getByTestId('action-reverttorevision')
const confirmButton = page.getByTestId('confirm-dialog-confirm-button')
const timelineMenuOpenButton = page.getByTestId('timeline-menu-open-button')
const contextMenuButton = page
.getByTestId('document-pane')
.getByTestId('pane-context-menu-button')
const historyMenuButton = page.getByTestId('action-history')
const historyPane = page.getByLabel('History').getByTestId('scroll-container')

const timelineItemButton = page.getByTestId('timeline-item-button')
const previousRevisionButton = timelineItemButton.nth(2)
const title = page.getByTestId('document-panel-document-title')
const previousRevisionButton = timelineItemButton.nth(1)
const titleInput = page.getByTestId('field-title').getByTestId('string-input')

await createDraftDocument('/test/content/book')
Expand All @@ -32,42 +29,48 @@ test.skip(`documents can be restored to an earlier revision`, async ({

// Change the title.
await titleInput.fill(titleB)
await expect(title).toHaveText(titleB)
await expect(titleInput).toHaveValue(titleB)

// Wait for the document to be published.
await page.waitForTimeout(1_000)
await publishButton.click()
await expect(documentStatus).toContainText('Published just now')

// Pick the previous revision from the revision timeline.
await timelineMenuOpenButton.click()
await expect(previousRevisionButton).toBeVisible()
await contextMenuButton.click()
await expect(contextMenuButton).toBeVisible()
await historyMenuButton.click()
await expect(historyPane).toBeVisible()

await previousRevisionButton.click({force: true})

await expect(titleInput).toHaveValue(titleA)

// Wait for the revision to be restored.
await restoreButton.click()
await confirmButton.click()
await expect(title).toHaveText(titleA)
await expect(titleInput).toHaveValue(titleA)
})

/*
Test skipped due to on going developments around server actions that make them flaky
Re-enable this test when the server actions are stable
*/
test.skip(`respects overridden restore action`, async ({page, createDraftDocument}) => {
test(`respects overridden restore action`, async ({page, createDraftDocument}) => {
// trying to avoid flaky test based on shorter timeout
test.slow()
const titleA = 'Title A'
const titleB = 'Title B'

const publishKeypress = () => page.locator('body').press('Control+Alt+p')
const documentStatus = page.getByTestId('pane-footer-document-status')
const restoreButton = page.getByTestId('action-Restore')
const restoreButton = page.getByTestId('action-reverttorevision')
const customRestoreButton = page.getByRole('button').getByText('Custom restore')
const confirmButton = page.getByTestId('confirm-dialog-confirm-button')
const timelineMenuOpenButton = page.getByTestId('timeline-menu-open-button')
const contextMenuButton = page
.getByTestId('document-pane')
.getByTestId('pane-context-menu-button')
const historyMenuButton = page.getByTestId('action-history')
const historyPane = page.getByLabel('History').getByTestId('scroll-container')

const timelineItemButton = page.getByTestId('timeline-item-button')
const previousRevisionButton = timelineItemButton.nth(2)
const previousRevisionButton = timelineItemButton.nth(1)
const titleInput = page.getByTestId('field-title').getByTestId('string-input')

await createDraftDocument('/test/content/input-debug;documentActionsTest')
Expand All @@ -77,7 +80,6 @@ test.skip(`respects overridden restore action`, async ({page, createDraftDocumen
state: 'visible',
})

const title = page.getByTestId('document-panel-document-title')
await titleInput.fill(titleA)

// Wait for the document to be published.
Expand All @@ -91,16 +93,18 @@ test.skip(`respects overridden restore action`, async ({page, createDraftDocumen

// Change the title.
await titleInput.fill(titleB)
await expect(title).toHaveText(titleB)
await expect(titleInput).toHaveValue(titleB)

// Wait for the document to be published.
await page.waitForTimeout(1_000)
await publishKeypress()
await expect(documentStatus).toContainText('Published just now')

// Pick the previous revision from the revision timeline.
await timelineMenuOpenButton.click()
await expect(previousRevisionButton).toBeVisible()
await contextMenuButton.click()
await expect(contextMenuButton).toBeVisible()
await historyMenuButton.click()
await expect(historyPane).toBeVisible()
await previousRevisionButton.click({force: true})

await expect(titleInput).toHaveValue(titleA)
Expand All @@ -122,24 +126,24 @@ test.skip(`respects overridden restore action`, async ({page, createDraftDocumen
{selector: '[data-testid="document-panel-document-title"]', testTitle: titleB},
)

await expect(title).toHaveText(titleA)
await expect(titleInput).toHaveValue(titleA)
})

/*
Test skipped due to on going developments around server actions that make them flaky
Re-enable this test when the server actions are stable
*/
test.skip(`respects removed restore action`, async ({page, createDraftDocument}) => {
test(`respects removed restore action`, async ({page, createDraftDocument}) => {
const titleA = 'Title A'
const titleB = 'Title B'

const documentStatus = page.getByTestId('pane-footer-document-status')
const publishButton = page.getByTestId('action-Publish')
const restoreButton = page.getByTestId('action-Restore')
const timelineMenuOpenButton = page.getByTestId('timeline-menu-open-button')
const publishButton = page.getByTestId('action-publish')
const restoreButton = page.getByTestId('action-reverttorevision')
const contextMenuButton = page
.getByTestId('document-pane')
.getByTestId('pane-context-menu-button')
const historyMenuButton = page.getByTestId('action-history')
const historyPane = page.getByLabel('History').getByTestId('scroll-container')

const timelineItemButton = page.getByTestId('timeline-item-button')
const previousRevisionButton = timelineItemButton.nth(2)
const title = page.getByTestId('document-panel-document-title')
const previousRevisionButton = timelineItemButton.nth(1)
const titleInput = page.getByTestId('field-title').getByTestId('string-input')

await createDraftDocument('/test/content/input-debug;removeRestoreActionTest')
Expand All @@ -152,16 +156,18 @@ test.skip(`respects removed restore action`, async ({page, createDraftDocument})

// Change the title.
await titleInput.fill(titleB)
await expect(title).toHaveText(titleB)
await expect(titleInput).toHaveValue(titleB)

// Wait for the document to be published.
await page.waitForTimeout(1_000)
await publishButton.click()
await expect(documentStatus).toContainText('Published just now')

// Pick the previous revision from the revision timeline.
await timelineMenuOpenButton.click()
await expect(previousRevisionButton).toBeVisible()
await contextMenuButton.click()
await expect(contextMenuButton).toBeVisible()
await historyMenuButton.click()
await expect(historyPane).toBeVisible()
await previousRevisionButton.click({force: true})

await expect(titleInput).toHaveValue(titleA)
Expand All @@ -170,11 +176,7 @@ test.skip(`respects removed restore action`, async ({page, createDraftDocument})
await expect(restoreButton).not.toBeVisible()
})

/*
Test skipped due to on going developments around server actions that make them flaky
Re-enable this test when the server actions are stable
*/
test.skip(`user defined restore actions should not appear in any other document action group UI`, async ({
test(`user defined restore actions should not appear in any other document action group UI`, async ({
page,
createDraftDocument,
}) => {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/document-actions/unpublish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test(`should be able to unpublish a published document`, async ({page, createDra
const titleA = 'Title A'

const documentStatus = page.getByTestId('pane-footer-document-status')
const publishButton = page.getByTestId('action-Publish')
const publishButton = page.getByTestId('action-publish')
const contextFooterMenu = page.getByTestId('action-menu-button')
const unpublishButton = page.getByTestId('action-Unpublish')
const titleInput = page.getByTestId('field-title').getByTestId('string-input')
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/tests/inputs/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test(`date input shows validation on selecting date from datepicker`, async ({
page.getByTestId('field-requiredDate').getByTestId('input-validation-icon-error'),
).toBeVisible()

await expect(page.getByTestId('action-Publish')).toBeDisabled()
await expect(page.getByTestId('action-publish')).toBeDisabled()
})

test.skip(`date input shows validation on entering date in the text field`, async ({
Expand All @@ -36,7 +36,7 @@ test.skip(`date input shows validation on entering date in the text field`, asyn
page.getByTestId('field-requiredDate').getByTestId('input-validation-icon-error'),
).toBeVisible()

await expect(page.getByTestId('action-Publish')).toBeDisabled()
await expect(page.getByTestId('action-publish')).toBeDisabled()
})

test(`publish button is disabled when invalid date is entered in the field`, async ({
Expand All @@ -51,7 +51,7 @@ test(`publish button is disabled when invalid date is entered in the field`, asy
// TODO: Remove this after fixing the blur test
await page.getByTestId('field-requiredDate').getByTestId('date-input').blur()

await expect(page.getByTestId('action-Publish')).toBeDisabled()
await expect(page.getByTestId('action-publish')).toBeDisabled()
})

test(`date input shows validation on entering date in the textfield and onBlur`, async ({
Expand All @@ -69,5 +69,5 @@ test(`date input shows validation on entering date in the textfield and onBlur`,
page.getByTestId('field-requiredDate').getByTestId('input-validation-icon-error'),
).toBeVisible()

await expect(page.getByTestId('action-Publish')).toBeDisabled()
await expect(page.getByTestId('action-publish')).toBeDisabled()
})
2 changes: 1 addition & 1 deletion test/e2e/tests/inputs/datetime.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test(`publish button is disabled when invalid date is entered in the field`, asy
// TODO: Remove this after fixing the blur test
await page.getByTestId('field-requiredDatetime').getByTestId('date-input').blur()

await expect(page.getByTestId('action-Publish')).toBeDisabled()
await expect(page.getByTestId('action-publish')).toBeDisabled()
})

test(`datetime inputs shows validation on entering date in the textfield and onBlur`, async ({
Expand Down
Loading
Loading