Skip to content

Commit

Permalink
test: make chromatic use named viewports
Browse files Browse the repository at this point in the history
  • Loading branch information
codeincontext committed Dec 9, 2024
1 parent 895cd8e commit bc8c4e2
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 4 deletions.
6 changes: 3 additions & 3 deletions apps/nextjs/.storybook/chromatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export function chromaticParams(modes: ChromaticModes[]) {
chromatic: {
modes: {
...(modes.includes("mobile") && {
mobile: { viewport: 375 },
mobile: { viewport: "mobile" },
}),
...(modes.includes("desktop") && {
desktop: { viewport: 1200 },
desktop: { viewport: "desktop" },
}),
...(modes.includes("desktop-wide") && {
"desktop-wide": { viewport: 1400 },
"desktop-wide": { viewport: "desktopWide" },
}),
// NOTE: Before we used modes, all snapshots were by default in the 1200px mode.
// This option allows us to reuse the existing desktop snapshot until we're ready to migrate
Expand Down
20 changes: 20 additions & 0 deletions apps/nextjs/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ const preview: Preview = {
date: /Date$/i,
},
},
viewport: {
viewports: {
mobile: {
name: "Mobile",
styles: { width: "375px", height: "800px" },
},
mobileWide: {
name: "Mobile Wide",
styles: { width: "430px", height: "930px" },
},
desktop: {
name: "Desktop",
styles: { width: "1200px", height: "1000px" },
},
desktopWide: {
name: "Desktop Wide",
styles: { width: "1400px", height: "1000px" },
},
},
},
},
loaders: [mswLoader],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const meta: Meta<typeof ExportButtons> = {
documentContainerRef: { current: null },
},
parameters: {
...chromaticParams(["compat"]),
...chromaticParams(["legacy"]),
},
};

Expand Down
64 changes: 64 additions & 0 deletions apps/nextjs/src/components/AppComponents/Chat/header.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { Meta, StoryObj } from "@storybook/react";

import { DemoContext } from "@/components/ContextProviders/Demo";

import { chromaticParams } from "../../../../.storybook/chromatic";
import { Header } from "./header";

const DemoDecorator: Story["decorators"] = (Story, { parameters }) => (
<DemoContext.Provider
value={{
isDemoUser: false,
isSharingEnabled: true,
...parameters.demoContext,
}}
>
<Story />
</DemoContext.Provider>
);

const meta: Meta<typeof Header> = {
title: "Components/Layout/ChatHeader",
component: Header,
tags: ["autodocs"],
decorators: [DemoDecorator],
parameters: {
layout: "fullscreen",
...chromaticParams(["legacy"]),
docs: {
story: {
height: "150px",
},
},
},
};

export default meta;
type Story = StoryObj<typeof Header>;

export const Default: Story = {
args: {},
};

export const DemoUser: Story = {
args: {},
parameters: {
demoContext: {
isDemoUser: true,
appSessionsPerMonth: 3,
appSessionsRemaining: 2,
},
...chromaticParams(["legacy", "desktop-wide"]),
},
};

export const DemoLoading: Story = {
args: {},
parameters: {
demoContext: {
isDemoUser: true,
appSessionsPerMonth: 3,
appSessionsRemaining: undefined,
},
},
};

0 comments on commit bc8c4e2

Please sign in to comment.