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

Core: Add experimental_TEST_PROVIDER addon type #29114

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion code/core/src/manager-api/lib/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
Addon_PageType,
Addon_SidebarBottomType,
Addon_SidebarTopType,
Addon_TestProviderType,
Addon_Type,
Addon_Types,
Addon_TypesMapping,
Expand Down Expand Up @@ -70,7 +71,8 @@ export class AddonStore {
| Addon_Types
| Addon_TypesEnum.experimental_PAGE
| Addon_TypesEnum.experimental_SIDEBAR_BOTTOM
| Addon_TypesEnum.experimental_SIDEBAR_TOP,
| Addon_TypesEnum.experimental_SIDEBAR_TOP
| Addon_TypesEnum.experimental_TEST_PROVIDER,
>(type: T): Addon_Collection<Addon_TypesMapping[T]> | any {
if (!this.elements[type]) {
this.elements[type] = {};
Expand All @@ -91,6 +93,7 @@ export class AddonStore {
| Addon_BaseType
| Omit<Addon_SidebarTopType, 'id'>
| Omit<Addon_SidebarBottomType, 'id'>
| Omit<Addon_TestProviderType, 'id'>
| Omit<Addon_PageType, 'id'>
| Omit<Addon_WrapperType, 'id'>
): void {
Expand Down
17 changes: 13 additions & 4 deletions code/core/src/manager-api/tests/addons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ const PANELS = {
},
};

const TEST_PROVIDERS = {
'storybook/test/test-provider': {
id: 'storybook/test/test-provider',
title: 'Component tests',
},
}

const provider = {
getElements(type) {
if (type === types.PANEL) {
return PANELS;
}
if (type === types.experimental_TEST_PROVIDER) {
return TEST_PROVIDERS;
}
return null;
},
};
Expand All @@ -38,14 +48,13 @@ const store = {
describe('Addons API', () => {
describe('#getElements', () => {
it('should return provider elements', () => {
// given
const { api } = initAddons({ provider, store });

// when
const panels = api.getElements(types.PANEL);

// then
expect(panels).toBe(PANELS);

const testProviders = api.getElements(types.experimental_TEST_PROVIDER);
expect(testProviders).toBe(TEST_PROVIDERS);
});
});

Expand Down
13 changes: 13 additions & 0 deletions code/core/src/types/modules/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,19 +461,30 @@ export interface Addon_SidebarTopType {
render: FC;
}

export interface Addon_TestProviderType {
type: Addon_TypesEnum.experimental_TEST_PROVIDER;
/** The unique id of the test provider. */
id: string;
icon: ReactNode;
title: string;
description: FC;
}

type Addon_TypeBaseNames = Exclude<
Addon_TypesEnum,
| Addon_TypesEnum.PREVIEW
| Addon_TypesEnum.experimental_PAGE
| Addon_TypesEnum.experimental_SIDEBAR_BOTTOM
| Addon_TypesEnum.experimental_SIDEBAR_TOP
| Addon_TypesEnum.experimental_TEST_PROVIDER
>;

export interface Addon_TypesMapping extends Record<Addon_TypeBaseNames, Addon_BaseType> {
[Addon_TypesEnum.PREVIEW]: Addon_WrapperType;
[Addon_TypesEnum.experimental_PAGE]: Addon_PageType;
[Addon_TypesEnum.experimental_SIDEBAR_BOTTOM]: Addon_SidebarBottomType;
[Addon_TypesEnum.experimental_SIDEBAR_TOP]: Addon_SidebarTopType;
[Addon_TypesEnum.experimental_TEST_PROVIDER]: Addon_TestProviderType;
}

export type Addon_Loader<API> = (api: API) => void;
Expand Down Expand Up @@ -537,4 +548,6 @@ export enum Addon_TypesEnum {
* @deprecated This will be removed in Storybook 9.0.
*/
experimental_SIDEBAR_TOP = 'sidebar-top',
/** This adds items to the Testing Module in the sidebar. */
experimental_TEST_PROVIDER = 'test-provider',
}