Skip to content

Commit

Permalink
Migrate test added in #45135
Browse files Browse the repository at this point in the history
  • Loading branch information
WunderBart committed Feb 21, 2023
1 parent 4b80291 commit 4dd325f
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions test/e2e/specs/editor/various/list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,123 @@ test.describe( 'List View', () => {
listView.getByRole( 'button', { name: 'Options for Group block' } )
).toBeFocused();
} );

// If list view sidebar is open and focus is not inside the sidebar, move
// focus to the sidebar when using the shortcut. If focus is inside the
// sidebar, shortcut should close the sidebar.
test( 'ensures List View global shortcut works properly', async ( {
editor,
page,
pageUtils,
} ) => {
await editor.insertBlock( { name: 'core/image' } );
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'Paragraph text' },
} );
await expect(
editor.canvas.getByRole( 'document', {
name: 'Paragraph block',
} )
).toBeFocused();

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
const listView = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

// The paragraph item should be selected.
await expect(
listView.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
} )
).toBeVisible();

// Navigate to the image block item.
await page.keyboard.press( 'ArrowUp' );
const imageItem = listView
.getByRole( 'gridcell', {
name: 'Image link',
} )
.getByRole( 'link', { includeHidden: true } );

await expect( imageItem ).toBeFocused();

// Hit enter to focus the Image block.
await page.keyboard.press( 'Enter' );
await expect(
editor.canvas
.getByRole( 'document', {
name: 'Block: Image',
} )
.getByRole( 'button', { name: 'Upload' } )
).toBeFocused();

// Since focus is now at the image block upload button in the canvas,
// pressing the list view shortcut should bring focus back to the image
// block in the list view.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
await expect( imageItem ).toBeFocused();

// Since focus is now inside the list view, the shortcut should close
// the sidebar.
await pageUtils.pressKeyWithModifier( 'access', 'o' );

// Focus should now be on the paragraph block since that is
// where we opened the list view sidebar. This is not a perfect
// solution, but current functionality prevents a better way at
// the moment.
await expect(
editor.canvas.getByRole( 'document', { name: 'Paragraph block' } )
).toBeFocused();

// List View should be closed.
await expect( listView ).not.toBeVisible();

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );

// Focus the list view close button and make sure the shortcut will
// close the list view. This is to catch a bug where elements could be
// out of range of the sidebar region. Must shift+tab 3 times to reach
// close button before tabs.
await pageUtils.pressKeyWithModifier( 'shift', 'Tab' );
await pageUtils.pressKeyWithModifier( 'shift', 'Tab' );
await pageUtils.pressKeyWithModifier( 'shift', 'Tab' );
await expect(
editor.canvas.getByRole( 'button', {
name: 'Close Document Overview Sidebar',
} )
).toBeFocused();

// Close List View and ensure it's closed.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
await expect( listView ).not.toBeVisible();

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );

// Focus the outline tab and select it. This test ensures the outline
// tab receives similar focus events based on the shortcut.
await pageUtils.pressKeyWithModifier( 'shift', 'Tab' );
const outlineButton = editor.canvas.getByRole( 'button', {
name: 'Outline',
} );
await expect( outlineButton ).toBeFocused();
await page.keyboard.press( 'Enter' );

// From here, tab in to the editor so focus can be checked on return to
// the outline tab in the sidebar.
await pageUtils.pressKeyTimes( 'Tab', 2 );
// Focus should be placed on the outline tab button since there is
// nothing to focus inside the tab itself.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
await expect( outlineButton ).toBeFocused();

// Close List View and ensure it's closed.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
await expect( listView ).not.toBeVisible();
} );
} );

0 comments on commit 4dd325f

Please sign in to comment.