Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@ const configFileMap = {

const config: StorybookConfig = {
addons: [
{
name: '@storybook/addon-essentials',
options: {
backgrounds: false,
viewport: false,
},
},
'@storybook/addon-interactions',
// TODO: re-enable addon-designs when it is compatible with SB 9
// '@storybook/addon-designs',
'@storybook/addon-docs',
'@storybook/addon-designs',
{
name: useDistVersion ? '../dist/preset.js' : '../src/dev.ts',
options: {
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
"@graphql-typed-document-node/core": "^3.2.0",
"@parcel/watcher": "^2.4.1",
"@storybook/addon-designs": "^9.0.0-0",
"@storybook/addon-essentials": "^9.0.0 || ^9.0.0-alpha.4",
"@storybook/addon-interactions": "^9.0.0 || ^9.0.0-alpha.4",
"@storybook/addon-mdx-gfm": "^9.0.0 || ^9.0.0-alpha.4",
"@storybook/blocks": "^9.0.0 || ^9.0.0-alpha.4",
"@storybook/addon-docs": "0.0.0-pr-30875-sha-5d0152e4",
"@storybook/addon-essentials": "0.0.0-pr-30875-sha-5d0152e4",
"@storybook/addon-mdx-gfm": "0.0.0-pr-30875-sha-5d0152e4",
"@storybook/blocks": "0.0.0-pr-30875-sha-5d0152e4",
"@storybook/icons": "^1.4.0",
"@storybook/react": "^9.0.0 || ^9.0.0-alpha.4",
"@storybook/react-vite": "^9.0.0 || ^9.0.0-alpha.4",
"@storybook/react": "0.0.0-pr-30875-sha-5d0152e4",
"@storybook/react-vite": "0.0.0-pr-30875-sha-5d0152e4",
"@types/jsonfile": "^6.1.1",
"@types/node": "^22.13.5",
"@types/pluralize": "^0.0.29",
Expand Down Expand Up @@ -109,7 +109,7 @@
"react-dom": "^18.3.1",
"react-joyride": "^2.7.2",
"rimraf": "^3.0.2",
"storybook": "^9.0.0 || ^9.0.0-alpha.4",
"storybook": "0.0.0-pr-30875-sha-5d0152e4",
"ts-dedent": "^2.2.0",
"tsup": "^6.6.3",
"typescript": "^5.7.3",
Expand All @@ -123,7 +123,7 @@
"zx": "^1.14.1"
},
"peerDependencies": {
"storybook": "^0.0.0-0 || ^9.0.0 || ^9.0.0-alpha.4"
"storybook": "^0.0.0-0 || 0.0.0-pr-30875-sha-5d0152e4"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
6 changes: 4 additions & 2 deletions src/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React, { useCallback, useEffect, useState } from 'react';
import type { API } from 'storybook/manager-api';
import { useChannel, useStorybookState } from 'storybook/manager-api';
import { experimental_getStatusStore, useChannel, useStorybookState } from 'storybook/manager-api';

Check warning on line 3 in src/Panel.tsx

View check run for this annotation

Codecov / codecov/patch

src/Panel.tsx#L3

Added line #L3 was not covered by tests

import { AuthProvider } from './AuthContext';
import { Spinner } from './components/design-system';
import {
ADDON_ID,
GIT_INFO,
GIT_INFO_ERROR,
IS_OFFLINE,
IS_OUTDATED,
LOCAL_BUILD_PROGRESS,
REMOVE_ADDON,
statusStore,
TELEMETRY,
} from './constants';
import { Authentication } from './screens/Authentication/Authentication';
Expand Down Expand Up @@ -40,6 +40,8 @@
api: API;
}

const statusStore = experimental_getStatusStore(ADDON_ID);

Check warning on line 43 in src/Panel.tsx

View check run for this annotation

Codecov / codecov/patch

src/Panel.tsx#L43

Added line #L43 was not covered by tests

export const Panel = ({ active, api }: PanelProps) => {
const [accessToken, updateAccessToken] = useAccessToken();
const setAccessToken = useCallback(
Expand Down
195 changes: 137 additions & 58 deletions src/TestingModuleDescription.tsx → src/TestingModule.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { FailedIcon } from '@storybook/icons';
import { PlayHollowIcon, StopAltIcon } from '@storybook/icons';

Check warning on line 2 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L2

Added line #L2 was not covered by tests
import pluralize from 'pluralize';
import React, { useCallback, useContext, useEffect, useRef } from 'react';
import { Link } from 'storybook/internal/components';
import { type Addon_TestProviderState } from 'storybook/internal/types';
import { Button, ProgressSpinner, TooltipNote, WithTooltip } from 'storybook/internal/components';

Check warning on line 6 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L6

Added line #L6 was not covered by tests
import {
type API,
experimental_getTestProviderStore,
experimental_useStatusStore,
useChannel,
experimental_useTestProviderStore,
useStorybookApi,
useStorybookState,
} from 'storybook/manager-api';
import { color } from 'storybook/theming';
import { styled } from 'storybook/theming';

Check warning on line 15 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L15

Added line #L15 was not covered by tests

import { BUILD_STEP_CONFIG } from './buildSteps';
import {
Expand All @@ -21,9 +24,6 @@
LOCAL_BUILD_PROGRESS,
PANEL_ID,
TEST_PROVIDER_ID,
TESTING_MODULE_CANCEL_TEST_RUN_REQUEST,
TESTING_MODULE_PROGRESS_REPORT,
TESTING_MODULE_RUN_ALL_REQUEST,
} from './constants';
import { ConfigInfoPayload, LocalBuildProgress } from './types';
import { useAccessToken } from './utils/graphQLClient';
Expand All @@ -32,10 +32,44 @@
import { useProjectId } from './utils/useProjectId';
import { useSharedState } from './utils/useSharedState';

type TestingModuleDescriptionProps = Addon_TestProviderState & { api: API };
const Container = styled.div({
display: 'flex',
justifyContent: 'space-between',
padding: '8px 0',
});

Check warning on line 39 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L35-L39

Added lines #L35 - L39 were not covered by tests

export const TestingModuleDescription = ({ api, running }: TestingModuleDescriptionProps) => {
const { addNotification, selectStory, setOptions, togglePanel } = api;
const Info = styled.div({
display: 'flex',
flexDirection: 'column',
marginLeft: 8,
});

Check warning on line 45 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L41-L45

Added lines #L41 - L45 were not covered by tests

const Actions = styled.div({
display: 'flex',
gap: 4,
});

Check warning on line 50 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L47-L50

Added lines #L47 - L50 were not covered by tests

const TitleWrapper = styled.div<{ crashed?: boolean }>(({ crashed, theme }) => ({
fontSize: theme.typography.size.s1,
fontWeight: crashed ? 'bold' : 'normal',
color: crashed ? theme.color.negativeText : theme.color.defaultText,
}));

Check warning on line 56 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L52-L56

Added lines #L52 - L56 were not covered by tests

const DescriptionWrapper = styled.div(({ theme }) => ({
fontSize: theme.typography.size.s1,
color: theme.textMutedColor,
}));

Check warning on line 61 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L58-L61

Added lines #L58 - L61 were not covered by tests

const Progress = styled(ProgressSpinner)({
margin: 4,
});

Check warning on line 65 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L63-L65

Added lines #L63 - L65 were not covered by tests

const StopIcon = styled(StopAltIcon)({
width: 10,
});

Check warning on line 69 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L67-L69

Added lines #L67 - L69 were not covered by tests

export const TestingModule = () => {
const { addNotification, selectStory, setOptions, togglePanel } = useStorybookApi();

Check warning on line 72 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L71-L72

Added lines #L71 - L72 were not covered by tests
const warningStatusCount = experimental_useStatusStore(
(allStatuses) =>
Object.values(allStatuses)
Expand All @@ -60,6 +94,20 @@
const lastStep = useRef(localBuildProgress?.currentStep);
const { index, storyId, viewMode } = useStorybookState();

const testProviderState = experimental_useTestProviderStore(
(state) => state[TEST_PROVIDER_ID] ?? 'test-provider-state:pending'
);

Check warning on line 99 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L97-L99

Added lines #L97 - L99 were not covered by tests

const { startBuild, stopBuild } = useBuildEvents({
localBuildProgress,
accessToken,
});

Check warning on line 104 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L101-L104

Added lines #L101 - L104 were not covered by tests

useEffect(
() => experimental_getTestProviderStore(TEST_PROVIDER_ID).onRunAll(startBuild),
[startBuild]
);

Check warning on line 109 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L106-L109

Added lines #L106 - L109 were not covered by tests

const openVisualTestsPanel = useCallback(
(warning?: string) => {
setOptions({ selectedPanel: PANEL_ID });
Expand Down Expand Up @@ -127,11 +175,6 @@
}
}, [addNotification, clickNotification, localBuildProgress?.currentStep]);

const { startBuild, stopBuild } = useBuildEvents({
localBuildProgress,
accessToken,
});

let warning: string | undefined;
if (!projectId) warning = 'Select a project';
if (!isLoggedIn) warning = 'Login required';
Expand All @@ -144,50 +187,86 @@
[openVisualTestsPanel, warning]
);

const emit = useChannel(
{
[TESTING_MODULE_RUN_ALL_REQUEST]: ({ providerId }) => {
if (providerId === TEST_PROVIDER_ID) startBuild();
},
[TESTING_MODULE_CANCEL_TEST_RUN_REQUEST]: ({ providerId }) => {
if (providerId === TEST_PROVIDER_ID) stopBuild();
},
},
[startBuild, stopBuild]
);
let description: string | React.ReactNode;
switch (true) {
case !!warning:
description = <Link onClick={clickWarning}>{warning}</Link>;
break;
case testProviderState === 'test-provider-state:running':
description = localBuildProgress
? BUILD_STEP_CONFIG[localBuildProgress.currentStep].renderProgress(localBuildProgress)
: 'Starting...';
break;
case !!isOutdated:
description = 'Test results outdated';
break;
case localBuildProgress?.currentStep === 'aborted':
description = 'Aborted by user';
break;
case localBuildProgress?.currentStep === 'complete':
description = localBuildProgress.errorCount
? `Encountered ${pluralize('component error', localBuildProgress.errorCount, true)}`
: warningStatusCount
? `Found ${pluralize('story', warningStatusCount, true)} with ${pluralize('change', warningStatusCount)}`
: 'No visual changes detected';
break;
default:
description = 'Not run';
}

Check warning on line 215 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L190-L215

Added lines #L190 - L215 were not covered by tests
Copy link
Contributor Author

@JReinhold JReinhold Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was essentially what the previous TestingModuleDescription component used to return. now we're setting description instead, and returning the JSX that LegacyRender would return - but simplified as it doesn't need to be generalized anymore.


useEffect(() => {
emit(TESTING_MODULE_PROGRESS_REPORT, { providerId: TEST_PROVIDER_ID, runnable: !warning });
}, [emit, warning]);
return (
<Container>
<Info>
<TitleWrapper crashed={testProviderState === 'test-provider-state:crashed'}>
{localBuildProgress?.currentStep === 'error' ||
localBuildProgress?.currentStep === 'limited'
? "Visual tests didn't complete"
: 'Visual tests'}
</TitleWrapper>
<DescriptionWrapper>{description}</DescriptionWrapper>
</Info>

Check warning on line 227 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L217-L227

Added lines #L217 - L227 were not covered by tests

if (warning) {
return <Link onClick={clickWarning}>{warning}</Link>;
}
if (running) {
if (localBuildProgress) {
const { renderProgress } = BUILD_STEP_CONFIG[localBuildProgress.currentStep];
return <>{renderProgress(localBuildProgress)}</>;
}
return <>Starting...</>;
}
if (isOutdated) {
return <>Test results outdated</>;
}
if (localBuildProgress?.currentStep === 'aborted') {
return <>Aborted by user</>;
}
if (localBuildProgress?.currentStep === 'complete') {
if (localBuildProgress.errorCount) {
return <>Encountered {pluralize('component error', localBuildProgress.errorCount, true)}</>;
}
return warningStatusCount ? (
<>
Found {pluralize('story', warningStatusCount, true)} with
{pluralize('change', warningStatusCount)}
</>
) : (
<>No visual changes detected</>
);
}
return <>Not run</>;
<Actions>
{warning ? null : testProviderState === 'test-provider-state:running' ? (
<WithTooltip
hasChrome={false}
trigger="hover"
tooltip={<TooltipNote note="Stop Visual tests" />}

Check warning on line 234 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L229-L234

Added lines #L229 - L234 were not covered by tests
>
<Button
aria-label="Stop Visual tests"
size="medium"
variant="ghost"
padding="none"
onClick={stopBuild}
disabled={
!['initialize', 'build', 'upload'].includes(localBuildProgress?.currentStep ?? '')

Check warning on line 243 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L236-L243

Added lines #L236 - L243 were not covered by tests
}
>
<Progress percentage={localBuildProgress?.buildProgressPercentage}>
<StopIcon />
</Progress>
</Button>
</WithTooltip>

Check warning on line 250 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L246-L250

Added lines #L246 - L250 were not covered by tests
) : (
<WithTooltip
hasChrome={false}
trigger="hover"
tooltip={<TooltipNote note="Start Visual tests" />}

Check warning on line 255 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L252-L255

Added lines #L252 - L255 were not covered by tests
>
<Button
aria-label="Start Visual tests"
size="medium"
variant="ghost"
padding="small"
onClick={startBuild}
disabled={testProviderState === 'test-provider-state:crashed'}

Check warning on line 263 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L257-L263

Added lines #L257 - L263 were not covered by tests
>
<PlayHollowIcon />
</Button>
</WithTooltip>

Check warning on line 267 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L265-L267

Added lines #L265 - L267 were not covered by tests
)}
</Actions>
</Container>

Check warning on line 270 in src/TestingModule.tsx

View check run for this annotation

Codecov / codecov/patch

src/TestingModule.tsx#L269-L270

Added lines #L269 - L270 were not covered by tests
);
};
13 changes: 12 additions & 1 deletion src/components/BuildProgressBarInline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import { LocalBuildProgress } from '../types';
import { BuildProgressLabel } from './BuildProgressLabel';
import { ProgressBar, ProgressTrack } from './SidebarTopButton';
import { Text } from './Text';

const ProgressTextWrapper = styled(Text)({
Expand All @@ -14,6 +13,18 @@
marginTop: 15,
});

const ProgressTrack = styled.div(({ theme }) => ({
height: 5,
background: theme.background.hoverable,
borderRadius: 5,
overflow: 'hidden',
}));

Check warning on line 21 in src/components/BuildProgressBarInline.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/BuildProgressBarInline.tsx#L16-L21

Added lines #L16 - L21 were not covered by tests

const ProgressBar = styled(ProgressTrack)(({ theme }) => ({
background: theme.color.secondary,
transition: 'width 3s ease-out',
}));

Check warning on line 26 in src/components/BuildProgressBarInline.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/BuildProgressBarInline.tsx#L23-L26

Added lines #L23 - L26 were not covered by tests

export function BuildProgressInline({
localBuildProgress,
}: {
Expand Down
Loading