Skip to content

Commit

Permalink
Improve the test case to include autodocs with multiple overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman authored and tmeasday committed Jun 12, 2024
1 parent d51f444 commit 86ac28e
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions code/lib/preview-api/template/stories/globals.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { within, expect } from '@storybook/test';

export default {
component: globalThis.Components.Pre,
tags: ['autodocs'],
};

export const Inheritance = {
Expand Down Expand Up @@ -41,20 +42,38 @@ export const Events = {
},
};

export const Overrides = {
export const Overrides1 = {
// Compose all the globals into `object`, so the pre component only needs a single prop
decorators: [
(storyFn: PartialStoryFn, context: StoryContext) =>
storyFn({ args: { object: context.globals } }),
],
globalOverrides: {
foo: 'fooOverridden',
bar: 'barOverridden',
foo: 'fooOverridden1',
bar: 'barOverridden1',
},
play: async ({ canvasElement }: PlayFunctionContext<any>) => {
await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toMatchObject({
foo: 'fooOverridden',
bar: 'barOverridden',
foo: 'fooOverridden1',
bar: 'barOverridden1',
});
},
};

export const Overrides2 = {
// Compose all the globals into `object`, so the pre component only needs a single prop
decorators: [
(storyFn: PartialStoryFn, context: StoryContext) =>
storyFn({ args: { object: context.globals } }),
],
globalOverrides: {
foo: 'fooOverridden2',
bar: 'barOverridden2',
},
play: async ({ canvasElement }: PlayFunctionContext<any>) => {
await expect(JSON.parse(within(canvasElement).getByTestId('pre').innerText)).toMatchObject({
foo: 'fooOverridden2',
bar: 'barOverridden2',
});
},
};

0 comments on commit 86ac28e

Please sign in to comment.