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

fix(vr-tests-react-components): migrate to new StoryWright api to define Steps to resolve VR snapshoting issues #33860

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Prev Previous commit
fix(vr-tests-react-components): add proper type return annotation to …
…getStoryVariant
  • Loading branch information
Hotell committed Feb 27, 2025
commit 94202cabda6a879fb4e8d7a437e5eac764907031
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import type { Args, Decorator, StoryFn, StoryObj } from '@storybook/react';
import { FluentProvider } from '@fluentui/react-provider';
import { webLightTheme, webDarkTheme, teamsHighContrastTheme } from '@fluentui/react-theme';
import { webLightTheme, webDarkTheme, teamsHighContrastTheme, type Theme } from '@fluentui/react-theme';

export const DARK_MODE = 'Dark Mode';
export const HIGH_CONTRAST = 'High Contrast';
@@ -13,8 +13,13 @@ function isStoryFn(story: StoryFn | StoryObj): story is StoryFn {
return typeof story === 'function';
}

interface StoryObjVariant extends StoryObj {
storyName: string;
parameters: StoryObj['parameters'] & { dir: ReturnType<typeof getDir>; theme: Theme; mode: 'vr-test' };
}

/** Helper function that returns RTL, Dark Mode or High Contrast variant of an existing story. */
export function getStoryVariant(story: StoryFn | StoryObj, variant: StoryVariant): StoryObj {
export function getStoryVariant(story: StoryFn | StoryObj, variant: StoryVariant): StoryObjVariant {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

improved types that reflect the actual usage ( we support both CSF2 and CSF3 🥹 )

const theme = getTheme(variant);
const dir = getDir(variant);
const decorators = story.decorators ?? [];
@@ -30,7 +35,7 @@ export function getStoryVariant(story: StoryFn | StoryObj, variant: StoryVariant
theme,
},
decorators: [...(Array.isArray(decorators) ? decorators : [decorators]), StoryVariantDecorator],
} satisfies StoryObj;
} satisfies StoryObjVariant;
}

const StoryVariantDecorator: Decorator = (storyFn, context) => {