Skip to content

Commit

Permalink
test: set up chromatic config and get storybook building (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
codeincontext authored Nov 7, 2024
1 parent 9af9b11 commit 7a34686
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 96 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "Chromatic"

on: push

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-chromatic
cancel-in-progress: true

jobs:
changed-files:
runs-on: ubuntu-latest
name: changed-files
outputs:
all_changed_files: ${{ steps.changed-files.outputs.all_changed_files }}
any_changed: ${{ steps.changed-files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
apps/nextjs/**
chromatic:
name: Run Chromatic
needs: [changed-files]
if: ${{ needs.changed-files.outputs.any_changed == 'true' }}

runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Inject Doppler env vars
uses: dopplerhq/[email protected]
id: doppler
with:
doppler-token: ${{ secrets.DOPPLER_TOKEN }}
inject-env-vars: true
- name: Run Chromatic
uses: chromaui/action@latest
with:
workingDir: apps/nextjs
exitZeroOnChanges: true
exitOnceUploaded: true
onlyChanged: true
3 changes: 2 additions & 1 deletion apps/nextjs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tests-e2e/.auth
.env.sentry-build-plugin

*storybook.log
.chromatic.log

# Playwright artifacts
playwright-report
playwright-report
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import { Theme } from "@radix-ui/themes";
import "@radix-ui/themes/styles.css";

export const ThemeDecorator = (Story: React.ComponentType) => (
export const RadixThemeDecorator = (Story: React.ComponentType) => (
<Theme>
<Story />
</Theme>
Expand Down
56 changes: 22 additions & 34 deletions apps/nextjs/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,10 @@ import "@fontsource/lexend/900.css";
import { OakThemeProvider, oakDefaultTheme } from "@oaknational/oak-components";
import type { Preview, Decorator } from "@storybook/react";

// ModerationProvider is coming in the main Chat.tsx refactor
//import { ModerationProvider } from "../src/components/AppComponents/Chat/Chat/ModerationProvider";
import { TooltipProvider } from "../src/components/AppComponents/Chat/ui/tooltip";
import { DialogProvider } from "../src/components/AppComponents/DialogContext";
import { CookieConsentProvider } from "../src/components/ContextProviders/CookieConsentProvider";
import { DemoProvider } from "../src/components/ContextProviders/Demo";
import LessonPlanTrackingProvider from "../src/lib/analytics/lessonPlanTrackingContext";
import { SidebarProvider } from "../src/lib/hooks/use-sidebar";
import { AnalyticsProvider } from "../src/mocks/analytics/provider";
import { TRPCReactProvider } from "../src/utils/trpc";
import { MockClerkProvider } from "./MockClerkProvider";
import { ThemeDecorator } from "./ThemeDecorator";
import { RadixThemeDecorator } from "./decorators/RadixThemeDecorator";
import "./preview.css";

const preview: Preview = {
Expand All @@ -35,33 +27,29 @@ const preview: Preview = {
tags: ["autodocs"],
};

// Providers not currently used
// - MockClerkProvider
// - CookieConsentProvider
// - DemoProvider
// - LessonPlanTrackingProvider
// - DialogProvider
// - OakThemeProvider
// - SidebarProvider
// - ChatModerationProvider

export const decorators: Decorator[] = [
ThemeDecorator,
RadixThemeDecorator,
(Story) => (
<MockClerkProvider>
<CookieConsentProvider>
{" "}
<TRPCReactProvider>
<DemoProvider>
<AnalyticsProvider>
<LessonPlanTrackingProvider chatId={"faked"}>
<DialogProvider>
<OakThemeProvider theme={oakDefaultTheme}>
<SidebarProvider>
<TooltipProvider>
{/* <ModerationProvider initialModerations={[]}> */}
<Story />
{/* </ModerationProvider> */}
</TooltipProvider>
</SidebarProvider>
</OakThemeProvider>
</DialogProvider>
</LessonPlanTrackingProvider>
</AnalyticsProvider>
</DemoProvider>{" "}
</TRPCReactProvider>
</CookieConsentProvider>
</MockClerkProvider>
<>
{/* TODO: Mock tRPC calls with MSW */}
<TRPCReactProvider>
<AnalyticsProvider>
<TooltipProvider>
<Story />
</TooltipProvider>
</AnalyticsProvider>
</TRPCReactProvider>
</>
),
];

Expand Down
6 changes: 6 additions & 0 deletions apps/nextjs/chromatic.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"onlyChanged": true,
"projectId": "Project:672908473f629875f0be294f",
"storybookBaseDir": "apps/nextjs",
"zip": true
}
3 changes: 2 additions & 1 deletion apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"with-env": "dotenv -e ../../.env --",
"aila": "tsx scripts/aila-cli.ts",
"storybook": "dotenv -e ../../.env -- storybook dev -p 6006 --no-open",
"build-storybook": "dotenv -e ../../.env -- storybook build"
"build-storybook": "dotenv -e ../../.env -- storybook build",
"chromatic": "pnpm with-env pnpm dlx chromatic"
},
"prettier": "@oakai/prettier-config",
"dependencies": {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Dialog from "@radix-ui/react-dialog";
import type { Meta, StoryObj } from "@storybook/react";

import { ChatHistory } from "./chat-history";
Expand All @@ -9,6 +10,13 @@ const meta: Meta<typeof ChatHistory> = {
layout: "centered",
},
tags: ["autodocs"],
decorators: [
(Story) => (
<Dialog.Root>
<Story />
</Dialog.Root>
),
],
};

export default meta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const Default: Story = {
},
};

// NOTE: The modal appears on a parent element which isn't captured by visual testing
// TODO: Test the modal directly
export const SharePending: Story = {
args: {
...Default.args,
Expand All @@ -38,6 +40,8 @@ export const SharePending: Story = {
},
};

// NOTE: The modal appears on a parent element which isn't captured by visual testing
// TODO: Test the modal directly
export const RemovePending: Story = {
args: {
...Default.args,
Expand Down

0 comments on commit 7a34686

Please sign in to comment.