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

Portable Stories: Add tags to composed story #27708

Merged
merged 2 commits into from
Jun 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('composeStory', () => {
label: 'Hello World',
primary: true,
},
tags: ['metaTag'],
};

it('should compose project annotations in all module formats', () => {
Expand All @@ -40,15 +41,16 @@ describe('composeStory', () => {
it('should return story with composed annotations from story, meta and project', () => {
const decoratorFromProjectAnnotations = vi.fn((StoryFn) => StoryFn());
const decoratorFromStoryAnnotations = vi.fn((StoryFn) => StoryFn());
setProjectAnnotations([
{
parameters: { injected: true },
globalTypes: {
locale: { defaultValue: 'en' },
},
decorators: [decoratorFromProjectAnnotations],
const projectAnnotations = {
parameters: { injected: true },
globalTypes: {
locale: { defaultValue: 'en' },
},
]);
decorators: [decoratorFromProjectAnnotations],
tags: ['projectTag'],
};

setProjectAnnotations(projectAnnotations);

const Story: Story = {
render: () => {},
Expand All @@ -57,13 +59,15 @@ describe('composeStory', () => {
secondAddon: true,
},
decorators: [decoratorFromStoryAnnotations],
tags: ['storyTag'],
};

const composedStory = composeStory(Story, meta);
expect(composedStory.args).toEqual({ ...Story.args, ...meta.args });
expect(composedStory.parameters).toEqual(
expect.objectContaining({ ...Story.parameters, ...meta.parameters })
);
expect(composedStory.tags).toEqual(['dev', 'test', 'projectTag', 'metaTag', 'storyTag']);

composedStory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export function composeStory<TRenderer extends Renderer = Renderer, TArgs extend
parameters: story.parameters as Parameters,
argTypes: story.argTypes as StrictArgTypes<TArgs>,
play: playFunction as ComposedStoryPlayFn<TRenderer, TArgs> | undefined,
tags: story.tags,
}
);

Expand Down
2 changes: 2 additions & 0 deletions code/lib/types/src/modules/composedStory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
Renderer,
StoryId,
StrictArgTypes,
Tag,
} from '@storybook/csf';

import type {
Expand Down Expand Up @@ -56,6 +57,7 @@ export type ComposedStoryFn<
storyName: string;
parameters: Parameters;
argTypes: StrictArgTypes<TArgs>;
tags: Tag[];
};
/**
* Based on a module of stories, it returns all stories within it, filtering non-stories
Expand Down