Skip to content

Commit

Permalink
test: add DialogContentDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
codeincontext committed Dec 10, 2024
1 parent f7fd3fa commit f6cc408
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
29 changes: 29 additions & 0 deletions apps/nextjs/.storybook/decorators/DialogContentDecorator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";

import type { Decorator } from "@storybook/react";

import type { DialogTypes } from "../../src/components/AppComponents/Chat/Chat/types";
import { DialogContext } from "../../src/components/AppComponents/DialogContext";

declare module "@storybook/csf" {
interface Parameters {
dialogWindow?: DialogTypes;
}
}

export const DialogContentDecorator: Decorator = (Story, { parameters }) => {
return (
<DialogContext.Provider
value={{
dialogWindow: parameters.dialogWindow ?? "",
setDialogWindow: () => {},
dialogProps: {},
setDialogProps: () => {},
openSidebar: false,
setOpenSidebar: () => {},
}}
>
<Story />
</DialogContext.Provider>
);
};
8 changes: 1 addition & 7 deletions apps/nextjs/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,7 @@ const preview: Preview = {
loaders: [mswLoader],
};

// Providers not currently used
// - CookieConsentProvider
// - DemoProvider
// - LessonPlanTrackingProvider
// - DialogProvider
// - SidebarProvider
// - ChatModerationProvider
// NOTE: See ./decorators for more decorators available to use in stories

export const decorators: Decorator[] = [
RadixThemeDecorator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,14 @@ import { http, HttpResponse } from "msw";
import type { AnalyticsContext } from "@/components/ContextProviders/AnalyticsProvider";
import { analyticsContext } from "@/components/ContextProviders/AnalyticsProvider";

import { DialogContext } from "../AppComponents/DialogContext";
import { DemoProvider } from "../ContextProviders/Demo";
import DialogContents from "./DialogContents";
import { DialogContentDecorator } from "@/storybook/decorators/DialogContentDecorator";

const meta: Meta<typeof DialogContents> = {
title: "Components/Dialogs/DialogContents",
component: DialogContents,
decorators: (Story, { parameters }) => {
return (
<DialogContext.Provider
value={{
dialogWindow: parameters.dialogWindow,
setDialogWindow: () => {},
dialogProps: {},
setDialogProps: () => {},
openSidebar: false,
setOpenSidebar: () => {},
}}
>
<Story />
</DialogContext.Provider>
);
decorators: [DialogContentDecorator]
},
};

Expand Down
6 changes: 6 additions & 0 deletions apps/nextjs/src/mocks/clerk/ClerkDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import type { Decorator } from "@storybook/react";

import { ClerkProvider } from "./nextjsComponents";

declare module "@storybook/csf" {
interface Parameters {
auth?: "loading" | "signedIn" | "signedInDemo" | "signedOut";
}
}

export const ClerkDecorator: Decorator = (Story, { parameters }) => {
return (
<ClerkProvider state={parameters.auth ?? "signedIn"}>
Expand Down

0 comments on commit f6cc408

Please sign in to comment.