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

test: stories for dialogs #372

Merged
merged 9 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ interface DialogContextType {
setDialogWindow: React.Dispatch<React.SetStateAction<DialogTypes>>;
}

const DialogContext = createContext<DialogContextType | undefined>(undefined);
export const DialogContext = createContext<DialogContextType | undefined>(
undefined,
);

export const DialogProvider: React.FC<React.PropsWithChildren> = ({
children,
Expand Down
129 changes: 129 additions & 0 deletions apps/nextjs/src/components/DialogControl/DialogContents.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import type { Meta, StoryObj } from "@storybook/react";

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";

const meta: Meta<typeof DialogContents> = {
title: "Components/Dialogs/DialogContents",
component: DialogContents,
decorators: (Story, { parameters }) => {
return (
<DialogContext.Provider
value={{
dialogWindow: parameters.dialogWindow,
setDialogWindow: () => {},
}}
>
<Story />
</DialogContext.Provider>
);
},
};

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

export const ShareChat: Story = {
args: {
lesson: {},
chatId: "example-chat-id",
isShared: false,
},
parameters: {
dialogWindow: "share-chat",
},
};

export const ReportContent: Story = {
args: {},
parameters: {
dialogWindow: "report-content",
},
};

export const DemoShareLocked: Story = {
args: {},
parameters: {
dialogWindow: "demo-share-locked",
auth: "signedInDemo",
},
decorators: [
(Story) => (
<DemoProvider>
<Story />
</DemoProvider>
),
],
};

export const DemoInterstitial: Story = {
args: {},
parameters: {
dialogWindow: "demo-interstitial",
auth: "signedInDemo",
},
decorators: [
(Story) => (
<DemoProvider>
<Story />
</DemoProvider>
),
],
};

export const Feedback: Story = {
args: {},
parameters: {
dialogWindow: "feedback",
},
decorators: (Story) => {
return (
<analyticsContext.Provider
value={
{
track: () => {},
trackEvent: () => {},
identify: () => {},
reset: () => {},
page: () => {},
posthogAiBetaClient: {
capture: () => {},
getSurveys: (fn) => {
fn([
{
id: "01917ac7-e417-0000-0c86-99ef890e6807",
name: "End of Aila generation survey launch aug24",
type: "api",
questions: [
{
type: "rating",
question:
"How would you rate the structure and content of this lesson plan?",
},
{
type: "rating",
question:
"How would you rate the ease of creating this lesson with Aila?",
},
{
type: "open",
question:
"What suggestions do you have to improve the lesson planning experience with Aila?",
},
],
},
]);
},
},
} as unknown as AnalyticsContext
}
>
<Story />
</analyticsContext.Provider>
);
},
};
10 changes: 8 additions & 2 deletions apps/nextjs/src/components/DialogControl/DialogContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const dialogTitlesAndIcons: Record<
iconName: "warning",
},
"demo-interstitial": {
title: "Lesson limit reached",
title: "Demo lesson limits",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy change, as the previous title was inccorect a lot of the time

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikeritson-oak it might be worth checking this

iconName: "warning",
},
"demo-share-locked": {
Expand Down Expand Up @@ -67,7 +67,13 @@ const DialogContents = ({
<OakModalCenterBody
title={dialogTitlesAndIcons[dialogWindow].title}
iconName={dialogTitlesAndIcons[dialogWindow].iconName}
hideIcon={dialogWindow === "feedback" || dialogWindow === "share-chat"}
iconOverride={
dialogWindow === "feedback" || dialogWindow === "share-chat"
? {
$display: "none",
}
: {}
}
mantagen marked this conversation as resolved.
Show resolved Hide resolved
>
{children}
{dialogWindow === "share-chat" && chatId && (
Expand Down
5 changes: 4 additions & 1 deletion apps/nextjs/src/mocks/clerk/nextjsComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ const states: Record<ClerkProviderProps["state"], Context> = {
isSignedIn: true,
user: {
...mockUser,
publicMetadata: { ...mockUser.publicMetadata, isDemoUser: true },
publicMetadata: {
...mockUser.publicMetadata,
labs: { ...mockUser.publicMetadata.labs, isDemoUser: true },
},
},
},
};
Expand Down
Loading