mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
add interaction component test
This commit is contained in:
parent
14f3ab4cc0
commit
adf6180170
@ -58,6 +58,7 @@ export const useContextMenu = (context: API_HashEntry, links: Link[], api: API)
|
||||
data-displayed={isOpen ? 'on' : 'off'}
|
||||
closeOnOutsideClick
|
||||
placement="bottom-end"
|
||||
data-testid="context-menu"
|
||||
onVisibleChange={(visible) => {
|
||||
if (!visible) {
|
||||
handlers.onClose();
|
||||
|
@ -2,7 +2,7 @@
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import type { Meta, StoryObj } from '@storybook/react';
|
||||
import { expect, fn, within } from '@storybook/test';
|
||||
import { expect, fn, userEvent, within } from '@storybook/test';
|
||||
|
||||
import { type ComponentEntry, type IndexHash, ManagerContext } from '@storybook/core/manager-api';
|
||||
|
||||
@ -19,12 +19,45 @@ const managerContext: any = {
|
||||
autodocs: 'tag',
|
||||
docsMode: false,
|
||||
},
|
||||
testProviders: {},
|
||||
testProviders: {
|
||||
'component-tests': {
|
||||
type: 'experimental_TEST_PROVIDER',
|
||||
id: 'component-tests',
|
||||
render: () => 'Component tests',
|
||||
contextMenu: () => <div>TEST_PROVIDER_CONTEXT_CONTENT</div>,
|
||||
runnable: true,
|
||||
watchable: true,
|
||||
},
|
||||
'visual-tests': {
|
||||
type: 'experimental_TEST_PROVIDER',
|
||||
id: 'visual-tests',
|
||||
render: () => 'Visual tests',
|
||||
contextMenu: () => null,
|
||||
runnable: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
api: {
|
||||
on: fn().mockName('api::on'),
|
||||
off: fn().mockName('api::off'),
|
||||
getElements: fn(() => ({})),
|
||||
emit: fn().mockName('api::emit'),
|
||||
getElements: fn(() => ({
|
||||
'component-tests': {
|
||||
type: 'experimental_TEST_PROVIDER',
|
||||
id: 'component-tests',
|
||||
render: () => 'Component tests',
|
||||
contextMenu: () => <div>TEST_PROVIDER_CONTEXT_CONTENT</div>,
|
||||
runnable: true,
|
||||
watchable: true,
|
||||
},
|
||||
'visual-tests': {
|
||||
type: 'experimental_TEST_PROVIDER',
|
||||
id: 'visual-tests',
|
||||
render: () => 'Visual tests',
|
||||
contextMenu: () => null,
|
||||
runnable: true,
|
||||
},
|
||||
})),
|
||||
},
|
||||
};
|
||||
|
||||
@ -254,3 +287,41 @@ export const SkipToCanvasLinkFocused: Story = {
|
||||
await expect(link).toBeVisible();
|
||||
},
|
||||
};
|
||||
|
||||
// SkipToCanvas Link only shows on desktop widths
|
||||
export const WithContextContent: Story = {
|
||||
...DocsOnlySingleStoryComponents,
|
||||
parameters: {
|
||||
chromatic: { viewports: [1280] },
|
||||
viewport: {
|
||||
options: {
|
||||
desktop: {
|
||||
name: 'Desktop',
|
||||
styles: {
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
globals: {
|
||||
viewport: { value: 'desktop' },
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const screen = await within(canvasElement);
|
||||
|
||||
const link = await screen.findByText('TooltipBuildList');
|
||||
await userEvent.hover(link);
|
||||
|
||||
const contextButton = await screen.findByTestId('context-menu');
|
||||
await userEvent.click(contextButton);
|
||||
|
||||
const body = await within(document.body);
|
||||
|
||||
const tooltip = await body.findByTestId('tooltip');
|
||||
|
||||
await expect(tooltip).toBeVisible();
|
||||
expect(tooltip).toHaveTextContent('TEST_PROVIDER_CONTEXT_CONTENT');
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user