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
Next Next commit
feat(vr-tests-rc): support both CSF2 and CSF3 for story variant creation
  • Loading branch information
Hotell committed Feb 27, 2025
commit 522c1f53d59d79f51f4fc6ae3f23cd6dbd5c78e1
Original file line number Diff line number Diff line change
@@ -9,15 +9,19 @@ export const RTL = 'RTL';

type StoryVariant = typeof DARK_MODE | typeof HIGH_CONTRAST | typeof RTL;

function isStoryFn(story: StoryFn | StoryObj): story is StoryFn {
return typeof story === 'function';
}

/** Helper function that returns RTL, Dark Mode or High Contrast variant of an existing story. */
export function getStoryVariant(story: StoryFn, variant: StoryVariant) {
export function getStoryVariant(story: StoryFn | StoryObj, variant: StoryVariant): StoryObj {
const theme = getTheme(variant);
const dir = getDir(variant);
const decorators = story.decorators ?? [];

return {
...story,
render: story,
render: isStoryFn(story) ? story : story.render,
storyName: `${getStoryName(story)} - ${variant}`,
parameters: {
...story.parameters,
@@ -52,6 +56,6 @@ function getDir(variant: StoryVariant) {
return variant === RTL ? 'rtl' : 'ltr';
}

function getStoryName<TArgs = Args>({ name, storyName }: StoryFn<TArgs>) {
function getStoryName<TArgs = Args>({ name, storyName }: StoryFn<TArgs> | StoryObj<TArgs>) {
return storyName ?? name?.replace(/([a-z])([A-Z])/g, '$1 $2');
}