mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
remove getCurrentStoryStatus
This commit is contained in:
parent
2d2b7b29c4
commit
3ffe047b9e
@ -10,10 +10,11 @@ import {
|
||||
type StoryFinishedPayload,
|
||||
} from 'storybook/internal/core-events';
|
||||
import * as api from 'storybook/internal/manager-api';
|
||||
import { StatusValue } from 'storybook/internal/types';
|
||||
|
||||
import type { AxeResults } from 'axe-core';
|
||||
|
||||
import { EVENTS, TEST_PROVIDER_ID } from '../constants';
|
||||
import { EVENTS } from '../constants';
|
||||
import { A11yContextProvider, useA11yContext } from './A11yContext';
|
||||
|
||||
vi.mock('storybook/internal/manager-api');
|
||||
@ -65,18 +66,15 @@ describe('A11yContext', () => {
|
||||
|
||||
const getCurrentStoryData = vi.fn();
|
||||
const getParameters = vi.fn();
|
||||
const getCurrentStoryStatus = vi.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
mockedApi.useAddonState.mockImplementation((_, defaultState) => React.useState(defaultState));
|
||||
mockedApi.useChannel.mockReturnValue(vi.fn());
|
||||
getCurrentStoryData.mockReturnValue({ id: storyId, type: 'story' });
|
||||
getParameters.mockReturnValue({});
|
||||
getCurrentStoryStatus.mockReturnValue({ [TEST_PROVIDER_ID]: { status: 'success' } });
|
||||
mockedApi.useStorybookApi.mockReturnValue({
|
||||
getCurrentStoryData,
|
||||
getParameters,
|
||||
getCurrentStoryStatus,
|
||||
} as any);
|
||||
mockedApi.useParameter.mockReturnValue({ manual: false });
|
||||
mockedApi.useStorybookState.mockReturnValue({ storyId } as any);
|
||||
@ -156,7 +154,7 @@ describe('A11yContext', () => {
|
||||
|
||||
it('should set discrepancy to cliFailedButModeManual when in manual mode', () => {
|
||||
mockedApi.useParameter.mockReturnValue({ manual: true });
|
||||
getCurrentStoryStatus.mockReturnValue({ [TEST_PROVIDER_ID]: { status: 'error' } });
|
||||
mockedApi.experimental_useStatusStore.mockReturnValue(StatusValue.ERROR);
|
||||
|
||||
const Component = () => {
|
||||
const { discrepancy } = useA11yContext();
|
||||
@ -174,7 +172,7 @@ describe('A11yContext', () => {
|
||||
|
||||
it('should set discrepancy to cliFailedButModeManual when in manual mode (set via globals', () => {
|
||||
mockedApi.useGlobals.mockReturnValue([{ a11y: { manual: true } }] as any);
|
||||
getCurrentStoryStatus.mockReturnValue({ [TEST_PROVIDER_ID]: { status: 'error' } });
|
||||
mockedApi.experimental_useStatusStore.mockReturnValue(StatusValue.ERROR);
|
||||
|
||||
const Component = () => {
|
||||
const { discrepancy } = useA11yContext();
|
||||
@ -192,7 +190,7 @@ describe('A11yContext', () => {
|
||||
|
||||
it('should set discrepancy to cliPassedBrowserFailed', () => {
|
||||
mockedApi.useParameter.mockReturnValue({ manual: true });
|
||||
getCurrentStoryStatus.mockReturnValue({ [TEST_PROVIDER_ID]: { status: 'success' } });
|
||||
mockedApi.experimental_useStatusStore.mockReturnValue(StatusValue.SUCCESS);
|
||||
|
||||
const Component = () => {
|
||||
const { discrepancy } = useA11yContext();
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
type StoryFinishedPayload,
|
||||
} from 'storybook/internal/core-events';
|
||||
import {
|
||||
experimental_useStatusStore,
|
||||
useAddonState,
|
||||
useChannel,
|
||||
useGlobals,
|
||||
@ -16,6 +17,7 @@ import {
|
||||
} from 'storybook/internal/manager-api';
|
||||
import type { Report } from 'storybook/internal/preview-api';
|
||||
import { convert, themes } from 'storybook/internal/theming';
|
||||
import { StatusValue } from 'storybook/internal/types';
|
||||
|
||||
import { HIGHLIGHT } from '@storybook/addon-highlight';
|
||||
|
||||
@ -100,7 +102,9 @@ export const A11yContextProvider: FC<PropsWithChildren> = (props) => {
|
||||
const [highlighted, setHighlighted] = useState<string[]>([]);
|
||||
|
||||
const { storyId } = useStorybookState();
|
||||
const storyStatus = api.getCurrentStoryStatus();
|
||||
const currentStoryA11yStatusValue = experimental_useStatusStore(
|
||||
(allStatuses) => allStatuses[storyId]?.[TEST_PROVIDER_ID]?.value
|
||||
);
|
||||
|
||||
const handleToggleHighlight = useCallback((target: string[], highlight: boolean) => {
|
||||
setHighlighted((prevHighlighted) =>
|
||||
@ -194,26 +198,24 @@ export const A11yContextProvider: FC<PropsWithChildren> = (props) => {
|
||||
}, [emit, highlighted, tab]);
|
||||
|
||||
const discrepancy: TestDiscrepancy = useMemo(() => {
|
||||
const storyStatusA11y = storyStatus?.[TEST_PROVIDER_ID]?.status;
|
||||
|
||||
if (storyStatusA11y) {
|
||||
if (storyStatusA11y === 'success' && results.violations.length > 0) {
|
||||
return 'cliPassedBrowserFailed';
|
||||
}
|
||||
|
||||
if (storyStatusA11y === 'error' && results.violations.length === 0) {
|
||||
if (status === 'ready' || status === 'ran') {
|
||||
return 'browserPassedCliFailed';
|
||||
}
|
||||
|
||||
if (status === 'manual') {
|
||||
return 'cliFailedButModeManual';
|
||||
}
|
||||
}
|
||||
if (!currentStoryA11yStatusValue) {
|
||||
return null;
|
||||
}
|
||||
if (currentStoryA11yStatusValue === StatusValue.SUCCESS && results.violations.length > 0) {
|
||||
return 'cliPassedBrowserFailed';
|
||||
}
|
||||
|
||||
if (currentStoryA11yStatusValue === StatusValue.ERROR && results.violations.length === 0) {
|
||||
if (status === 'ready' || status === 'ran') {
|
||||
return 'browserPassedCliFailed';
|
||||
}
|
||||
|
||||
if (status === 'manual') {
|
||||
return 'cliFailedButModeManual';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, [results.violations.length, status, storyStatus]);
|
||||
}, [results.violations.length, status, currentStoryA11yStatusValue]);
|
||||
|
||||
return (
|
||||
<A11yContext.Provider
|
||||
|
@ -267,12 +267,6 @@ export interface SubAPI {
|
||||
* @returns {Promise<void>} A promise that resolves when the preview has been set as initialized.
|
||||
*/
|
||||
setPreviewInitialized: (ref?: ComposedRef) => Promise<void>;
|
||||
/**
|
||||
* Returns the current statuses of the stories.
|
||||
*
|
||||
* @returns {StatusByTypeId} The current statuses of the story.
|
||||
*/
|
||||
getCurrentStoryStatus: () => StatusByTypeId;
|
||||
/**
|
||||
* Updates the filtering of the index.
|
||||
*
|
||||
@ -652,12 +646,6 @@ export const init: ModuleFn<SubAPI, SubState> = ({
|
||||
}
|
||||
},
|
||||
|
||||
getCurrentStoryStatus: () => {
|
||||
const { storyId } = store.getState();
|
||||
const allStatuses = fullStatusStore.get();
|
||||
return allStatuses[storyId];
|
||||
},
|
||||
|
||||
experimental_setFilter: async (id, filterFunction) => {
|
||||
await store.setState({ filters: { ...store.getState().filters, [id]: filterFunction } });
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user