Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon Test: Context menu updates #30107

Open
wants to merge 10 commits into
base: next
Choose a base branch
from
198 changes: 118 additions & 80 deletions code/addons/test/src/components/TestProviderRender.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, { type ComponentProps, type FC, useCallback, useMemo, useRef, useState } from 'react';

import { Button, ListItem, ProgressSpinner } from 'storybook/internal/components';
import {
Button,
ListItem,
ProgressSpinner,
TooltipNote,
WithTooltip,
} from 'storybook/internal/components';
import {
TESTING_MODULE_CONFIG_CHANGE,
type TestProviderConfig,
Expand Down Expand Up @@ -206,52 +212,78 @@ export const TestProviderRender: FC<
</Info>

<Actions>
<Button
aria-label={`${isEditing ? 'Close' : 'Open'} settings for ${state.name}`}
variant="ghost"
padding="small"
active={isEditing}
disabled={state.running && !isEditing}
onClick={() => setIsEditing(!isEditing)}
>
<EditIcon />
</Button>
{state.watchable && !entryId && (
<Button
aria-label={`${state.watching ? 'Disable' : 'Enable'} watch mode for ${state.name}`}
variant="ghost"
padding="small"
active={state.watching}
onClick={() => api.setTestProviderWatchMode(state.id, !state.watching)}
disabled={state.running || isEditing}
{!entryId && (
<WithTooltip
hasChrome={false}
trigger="hover"
tooltip={<TooltipNote note={`${isEditing ? 'Hide' : 'Show'} settings`} />}
>
<Button
aria-label={`${isEditing ? 'Hide' : 'Show'} settings`}
variant="ghost"
padding="small"
active={isEditing}
disabled={state.running && !isEditing}
onClick={() => setIsEditing(!isEditing)}
>
<EditIcon />
</Button>
</WithTooltip>
)}
{!entryId && state.watchable && (
<WithTooltip
hasChrome={false}
trigger="hover"
tooltip={<TooltipNote note={`${state.watching ? 'Disable' : 'Enable'} watch mode`} />}
>
<EyeIcon />
</Button>
<Button
aria-label={`${state.watching ? 'Disable' : 'Enable'} watch mode`}
variant="ghost"
padding="small"
active={state.watching}
onClick={() => api.setTestProviderWatchMode(state.id, !state.watching)}
disabled={state.running || isEditing}
>
<EyeIcon />
</Button>
</WithTooltip>
)}
{state.runnable && (
<>
{state.running && state.cancellable ? (
<Button
aria-label={`Stop ${state.name}`}
variant="ghost"
padding="none"
onClick={() => api.cancelTestProvider(state.id)}
disabled={state.cancelling}
<WithTooltip
hasChrome={false}
trigger="hover"
tooltip={<TooltipNote note="Stop test run" />}
>
<Progress percentage={state.progress?.percentageCompleted}>
<StopIcon />
</Progress>
</Button>
<Button
aria-label="Stop test run"
variant="ghost"
padding="none"
onClick={() => api.cancelTestProvider(state.id)}
disabled={state.cancelling}
>
<Progress percentage={state.progress?.percentageCompleted}>
<StopIcon />
</Progress>
</Button>
</WithTooltip>
) : (
<Button
aria-label={`Start ${state.name}`}
variant="ghost"
padding="small"
onClick={() => api.runTestProvider(state.id, { entryId })}
disabled={state.running || isEditing}
<WithTooltip
hasChrome={false}
trigger="hover"
tooltip={<TooltipNote note="Start test run" />}
>
<PlayHollowIcon />
</Button>
<Button
aria-label="Start test run"
variant="ghost"
padding="small"
onClick={() => api.runTestProvider(state.id, { entryId })}
disabled={state.running || isEditing}
>
<PlayHollowIcon />
</Button>
</WithTooltip>
)}
</>
)}
Expand All @@ -266,19 +298,6 @@ export const TestProviderRender: FC<
icon={<PointerHandIcon color={theme.textMutedColor} />}
right={<Checkbox type="checkbox" checked disabled />}
/>
<ListItem
as="label"
title={<ItemTitle enabled={config.coverage}>Coverage</ItemTitle>}
icon={<ShieldIcon color={theme.textMutedColor} />}
right={
<Checkbox
type="checkbox"
checked={state.watching ? false : config.coverage}
disabled={state.watching}
onChange={() => updateConfig({ coverage: !config.coverage })}
/>
}
/>
{isA11yAddon && (
<ListItem
as="label"
Expand All @@ -293,6 +312,21 @@ export const TestProviderRender: FC<
}
/>
)}
{!entryId && (
<ListItem
as="label"
title={<ItemTitle enabled={config.coverage}>Coverage</ItemTitle>}
icon={<ShieldIcon color={theme.textMutedColor} />}
right={
<Checkbox
type="checkbox"
checked={state.watching ? false : config.coverage}
disabled={state.watching}
onChange={() => updateConfig({ coverage: !config.coverage })}
/>
}
/>
)}
</Extras>
) : (
<Extras>
Expand All @@ -318,34 +352,6 @@ export const TestProviderRender: FC<
)
}
/>
{coverageSummary ? (
<ListItem
title={<ItemTitle enabled={config.coverage}>Coverage</ItemTitle>}
href={'/coverage/index.html'}
// @ts-expect-error ListItem doesn't include all anchor attributes in types, but it is an achor element
target="_blank"
aria-label="Open coverage report"
icon={
<TestStatusIcon
percentage={coverageSummary.percentage}
status={coverageSummary.status}
aria-label={`status: ${coverageSummary.status}`}
/>
}
right={
coverageSummary.percentage ? (
<span aria-label={`${coverageSummary.percentage} percent coverage`}>
{coverageSummary.percentage} %
</span>
) : null
}
/>
) : (
<ListItem
title={<ItemTitle enabled={config.coverage}>Coverage</ItemTitle>}
icon={<TestStatusIcon status="unknown" aria-label={`status: unknown`} />}
/>
)}
{isA11yAddon && (
<ListItem
title={<ItemTitle enabled={config.a11y}>Accessibility {a11ySkippedLabel}</ItemTitle>}
Expand All @@ -367,6 +373,38 @@ export const TestProviderRender: FC<
right={isStoryEntry ? null : a11yNotPassedAmount || null}
/>
)}
{!entryId && (
<>
{coverageSummary ? (
<ListItem
title={<ItemTitle enabled={config.coverage}>Coverage</ItemTitle>}
href={'/coverage/index.html'}
// @ts-expect-error ListItem doesn't include all anchor attributes in types, but it is an achor element
target="_blank"
aria-label="Open coverage report"
icon={
<TestStatusIcon
percentage={coverageSummary.percentage}
status={coverageSummary.status}
aria-label={`status: ${coverageSummary.status}`}
/>
}
right={
coverageSummary.percentage ? (
<span aria-label={`${coverageSummary.percentage} percent coverage`}>
{coverageSummary.percentage} %
</span>
) : null
}
/>
) : (
<ListItem
title={<ItemTitle enabled={config.coverage}>Coverage</ItemTitle>}
icon={<TestStatusIcon status="unknown" aria-label={`status: unknown`} />}
/>
)}
</>
)}
</Extras>
)}
</Container>
Expand Down
86 changes: 54 additions & 32 deletions code/core/src/manager/components/sidebar/LegacyRender.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { Button, ProgressSpinner } from '@storybook/core/components';
import { Button, ProgressSpinner, TooltipNote, WithTooltip } from '@storybook/core/components';
import { styled } from '@storybook/core/theming';
import { EyeIcon, PlayHollowIcon, StopAltIcon } from '@storybook/icons';

Expand Down Expand Up @@ -61,46 +61,68 @@ export const LegacyRender = ({ ...state }: TestProviders[keyof TestProviders]) =

<Actions>
{state.watchable && (
<Button
aria-label={`${state.watching ? 'Disable' : 'Enable'} watch mode for ${name}`}
variant="ghost"
padding="small"
active={state.watching}
onClick={() => api.setTestProviderWatchMode(state.id, !state.watching)}
disabled={state.crashed || state.running}
<WithTooltip
hasChrome={false}
trigger="hover"
tooltip={
<TooltipNote
note={`${state.watching ? 'Disable' : 'Enable'} watch mode for ${state.name}`}
/>
}
>
<EyeIcon />
</Button>
<Button
aria-label={`${state.watching ? 'Disable' : 'Enable'} watch mode for ${state.name}`}
variant="ghost"
padding="small"
active={state.watching}
onClick={() => api.setTestProviderWatchMode(state.id, !state.watching)}
disabled={state.crashed || state.running}
>
<EyeIcon />
</Button>
</WithTooltip>
)}
{state.runnable && (
<>
{state.running && state.cancellable ? (
<Button
aria-label={`Stop ${name}`}
variant="ghost"
padding="none"
onClick={() => api.cancelTestProvider(state.id)}
disabled={state.cancelling}
<WithTooltip
hasChrome={false}
trigger="hover"
tooltip={<TooltipNote note={`Stop ${state.name}`} />}
>
<Progress
percentage={
state.progress?.percentageCompleted ??
(state.details as any)?.buildProgressPercentage
}
<Button
aria-label={`Stop ${state.name}`}
variant="ghost"
padding="none"
onClick={() => api.cancelTestProvider(state.id)}
disabled={state.cancelling}
>
<StopIcon />
</Progress>
</Button>
<Progress
percentage={
state.progress?.percentageCompleted ??
(state.details as any)?.buildProgressPercentage
}
>
<StopIcon />
</Progress>
</Button>
</WithTooltip>
) : (
<Button
aria-label={`Start ${state.name}`}
variant="ghost"
padding="small"
onClick={() => api.runTestProvider(state.id)}
disabled={state.crashed || state.running}
<WithTooltip
hasChrome={false}
trigger="hover"
tooltip={<TooltipNote note={`Start ${state.name}`} />}
>
<PlayHollowIcon />
</Button>
<Button
aria-label={`Start ${state.name}`}
variant="ghost"
padding="small"
onClick={() => api.runTestProvider(state.id)}
disabled={state.crashed || state.running}
>
<PlayHollowIcon />
</Button>
</WithTooltip>
)}
</>
)}
Expand Down
Loading
Loading