-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19668 from storybookjs/tom/sb-889-disable-keyboar…
…d-shortcuts-during-the Disable keyboard shortcuts during (docs) play functions and add tests
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import process from 'process'; | ||
import { SbPage } from './util'; | ||
|
||
const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; | ||
|
||
test.describe('preview-web', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto(storybookUrl); | ||
await new SbPage(page).waitUntilLoaded(); | ||
}); | ||
|
||
test('should pass over shortcuts, but not from play functions, story', async ({ page }) => { | ||
const sbPage = new SbPage(page); | ||
await sbPage.navigateToStory('lib/store/shortcuts', 'keydown-during-play'); | ||
|
||
await expect(sbPage.page.locator('.sidebar-container')).toBeVisible(); | ||
|
||
await sbPage.previewRoot().locator('button').press('s'); | ||
await expect(sbPage.page.locator('.sidebar-container')).not.toBeVisible(); | ||
}); | ||
|
||
test('should pass over shortcuts, but not from play functions, docs', async ({ page }) => { | ||
const sbPage = new SbPage(page); | ||
await sbPage.navigateToStory('lib/store/shortcuts', 'docs'); | ||
|
||
await expect(sbPage.page.locator('.sidebar-container')).toBeVisible(); | ||
|
||
await sbPage.previewRoot().getByRole('button').getByText('Submit').press('s'); | ||
await expect(sbPage.page.locator('.sidebar-container')).not.toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import globalThis from 'global'; | ||
import { userEvent, within } from '@storybook/testing-library'; | ||
import { PREVIEW_KEYDOWN } from '@storybook/core-events'; | ||
import { jest, expect } from '@storybook/jest'; | ||
import type { PlayFunctionContext } from '@storybook/csf'; | ||
|
||
export default { | ||
component: globalThis.Components.Form, | ||
tags: ['docsPage'], | ||
}; | ||
|
||
export const KeydownDuringPlay = { | ||
play: async ({ canvasElement }: PlayFunctionContext) => { | ||
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__; | ||
|
||
const previewKeydown = jest.fn(); | ||
channel.on(PREVIEW_KEYDOWN, previewKeydown); | ||
const button = await within(canvasElement).findByText('Submit'); | ||
await userEvent.type(button, 's'); | ||
|
||
expect(previewKeydown).not.toBeCalled(); | ||
}, | ||
}; |