Skip to content

Commit

Permalink
Fix play functions and base theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jun 20, 2023
1 parent 35dd8c3 commit 328c9e7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/components/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { background, styled } from "@storybook/theming";
import { styled } from "@storybook/theming";

export const Container = styled.div({
background: background.app,
export const Container = styled.div(({ theme }) => ({
background: theme.background.app,
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
height: "100%",
});
}));
17 changes: 7 additions & 10 deletions src/screens/Onboarding/Onboarding.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { rest } from "msw";

import { storyWrapper } from "../../utils/graphQLClient";
import { Onboarding } from "./Onboarding";
import { playAll } from "../../utils/playAll";

const meta = {
component: Onboarding,
Expand Down Expand Up @@ -47,32 +48,28 @@ type Story = StoryObj<typeof meta>;
export const Welcome: Story = {};

export const SignIn: Story = {
play: async ({ canvasElement }) => {
play: playAll(async ({ canvasElement }) => {
const button = await findByRole(canvasElement, "button", {
name: "Enable",
});
await userEvent.click(button);
},
}),
};

export const SSO: Story = {
play: async (context) => {
await SignIn.play(context);

play: playAll(SignIn, async (context) => {
const button = await findByRole(context.canvasElement, "button", {
name: "Sign into Chromatic with SSO",
});
await userEvent.click(button);
},
}),
};

export const Verify: Story = {
play: async (context) => {
await SignIn.play(context);

play: playAll(SignIn, async (context) => {
const button = await findByRole(context.canvasElement, "button", {
name: "Sign in with Chromatic",
});
await userEvent.click(button);
},
}),
};
18 changes: 18 additions & 0 deletions src/utils/playAll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { StoryObj } from "@storybook/react";

export function playAll<Story extends StoryObj>(
...sequence: (Story | Story["play"])[]
): Story["play"] {
return async (context) => {
const canvasNodes = context.canvasElement.querySelectorAll<HTMLElement>("[data-canvas]");
const canvasElements = canvasNodes.length ? Array.from(canvasNodes) : [context.canvasElement];

await Promise.all(
sequence.flatMap((storyOrPlay) =>
typeof storyOrPlay === "function"
? canvasElements.map((canvasElement) => storyOrPlay({ ...context, canvasElement }))
: storyOrPlay?.play?.(context)
)
);
};
}

0 comments on commit 328c9e7

Please sign in to comment.