From 6e2b837a8851bc7dfaa6f0f2eb16b834d364d446 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Fri, 28 Oct 2022 22:34:25 +1100 Subject: [PATCH] Add stories to check shortcuts aren't called from play --- code/lib/preview-web/src/PreviewWeb.test.ts | 3 +- .../template/stories/shortcuts.stories.ts | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 code/lib/store/template/stories/shortcuts.stories.ts diff --git a/code/lib/preview-web/src/PreviewWeb.test.ts b/code/lib/preview-web/src/PreviewWeb.test.ts index 2f085ccf36d..36cf0b17ce7 100644 --- a/code/lib/preview-web/src/PreviewWeb.test.ts +++ b/code/lib/preview-web/src/PreviewWeb.test.ts @@ -3333,8 +3333,7 @@ describe('PreviewWeb', () => { componentOneExports.b.play.mockImplementationOnce(async () => gate); preview.renderStoryToElement( await preview.storyStore.loadStory({ storyId: 'component-one--b' }), - {} as any, - { runPlayFunction: true } + {} as any ); await waitForRenderPhase('playing'); diff --git a/code/lib/store/template/stories/shortcuts.stories.ts b/code/lib/store/template/stories/shortcuts.stories.ts new file mode 100644 index 00000000000..36fd93ee6ac --- /dev/null +++ b/code/lib/store/template/stories/shortcuts.stories.ts @@ -0,0 +1,29 @@ +import globalThis from 'global'; +import { userEvent, within } from '@storybook/testing-library'; +import { PREVIEW_KEYDOWN } from '@storybook/core-events'; +import { jest, expect } from '@storybook/jest'; + +export default { + component: globalThis.Components.Form, + tags: ['docsPage'], +}; + +export const KeydownDuringPlay = { + play: async ({ canvasElement }) => { + const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__; + + const previewKeydown = jest.fn(); + channel.on(PREVIEW_KEYDOWN, previewKeydown); + // eslint-disable-next-line storybook/await-interactions + const promise = userEvent.type(await within(canvasElement).findByTestId('value'), '000000', { + delay: 100, + }); + + const button = await within(canvasElement).findByRole('button'); + button.focus(); + + await promise; + + expect(previewKeydown).not.toBeCalled(); + }, +};