Skip to content

Commit

Permalink
This PR adds a follow up E2E test for #52674
Browse files Browse the repository at this point in the history
It also adds an aria label to the edit template button to indicate its state (pressed or not pressed).
  • Loading branch information
ramonjd committed Nov 14, 2023
1 parent f927f2d commit 81c91c8
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export default function EditTemplate() {
icon={
! isTemplateHidden ? check : undefined
}
isPressed={ ! isTemplateHidden }
onClick={ () => {
setPageContentFocusType(
isTemplateHidden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
.components-popover__content {
min-width: 240px;
}
.components-button.is-pressed,
.components-button.is-pressed:hover {
background: inherit;
color: inherit;
}
}

.edit-site-page-panels-edit-slug__dropdown {
Expand All @@ -92,3 +97,4 @@
padding: $grid-unit-20;
}
}

98 changes: 98 additions & 0 deletions test/e2e/specs/site-editor/pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,103 @@ test.describe( 'Pages', () => {
)
).toBeVisible();
} );

test( 'toggle template preview', async ( { page, editor } ) => {
await draftNewPage( page );
await editor.openDocumentSettingsSidebar();

// Header template area and page content are visible.
await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: header',
} )
).toBeVisible();
await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: Content',
} )
).toBeVisible();
await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: Title',
} )
).toBeVisible();

// Toggle template preview to "off".
const templateOptionsButton = page
.getByRole( 'region', { name: 'Editor settings' } )
.getByRole( 'button', { name: 'Template options' } );
await templateOptionsButton.click();
const templatePreviewButton = page
.getByRole( 'menu', { name: 'Template options' } )
.getByRole( 'menuitem', { name: 'Template preview' } );

await expect( templatePreviewButton ).toHaveAttribute(
'aria-pressed',
'true'
);
await templatePreviewButton.click();
await expect( templatePreviewButton ).toHaveAttribute(
'aria-pressed',
'false'
);

// Header template area should be hidden.
await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: header',
} )
).toBeHidden();

// Content block is still visible and wrapped in a container.
await expect(
editor.canvas
.getByRole( 'document', {
name: 'Block: Group',
} )
.getByRole( 'document', {
name: 'Block: Content',
} )
).toBeVisible();
await expect(
editor.canvas
.getByRole( 'document', {
name: 'Block: Group',
} )
.getByRole( 'document', {
name: 'Block: Title',
} )
).toBeVisible();

// Remove focus from templateOptionsButton button.
await editor.canvas.locator( 'body' ).click();

// Toggle template preview to "on".
await templateOptionsButton.click();
await templatePreviewButton.click();
await expect( templatePreviewButton ).toHaveAttribute(
'aria-pressed',
'true'
);

// Header template area and page content are once again visible.
await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: header',
} )
).toBeVisible();
await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: Content',
} )
).toBeVisible();
await expect(
editor.canvas.getByRole( 'document', {
name: 'Block: Title',
} )
).toBeVisible();
} );

test( 'swap template and reset to default', async ( {
admin,
page,
Expand Down Expand Up @@ -195,6 +292,7 @@ test.describe( 'Pages', () => {
await resetButton.click();
await expect( templateOptionsButton ).toHaveText( 'Single Entries' );
} );

test( 'swap template options should respect the declared `postTypes`', async ( {
page,
editor,
Expand Down

0 comments on commit 81c91c8

Please sign in to comment.