Skip to content

Commit

Permalink
test: add AnalyticsDecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
codeincontext committed Dec 11, 2024
1 parent 28e7dc7 commit 88116e0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 50 deletions.
34 changes: 34 additions & 0 deletions apps/nextjs/.storybook/decorators/AnalyticsDecorator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";

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

import {
analyticsContext,
type AnalyticsContext,
} from "../../src/components/ContextProviders/AnalyticsProvider";

declare module "@storybook/csf" {
interface Parameters {
analyticsContext?: Partial<AnalyticsContext>;
}
}

export const AnalyticsDecorator: Decorator = (Story, { parameters }) => {
return (
<analyticsContext.Provider
value={
{
track: () => {},
trackEvent: () => {},
identify: () => {},
reset: () => {},
page: () => {},
posthogAiBetaClient: {},
...parameters.analyticsContext,
} as unknown as AnalyticsContext
}
>
<Story />
</analyticsContext.Provider>
);
};
86 changes: 36 additions & 50 deletions apps/nextjs/src/components/DialogControl/DialogContents.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { Meta, StoryObj } from "@storybook/react";
import { http, HttpResponse } from "msw";
import { SurveyQuestionType, SurveyType } from "posthog-js";
import type { PostHog } from "posthog-js";

import type { AnalyticsContext } from "@/components/ContextProviders/AnalyticsProvider";
import { analyticsContext } from "@/components/ContextProviders/AnalyticsProvider";
import { AnalyticsDecorator } from "@/storybook/decorators/AnalyticsDecorator";
import { DialogContentDecorator } from "@/storybook/decorators/DialogContentDecorator";

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: [DialogContentDecorator]
},
decorators: [DialogContentDecorator],
};

export default meta;
Expand Down Expand Up @@ -101,53 +101,39 @@ export const DemoInterstitialLimited: Story = {

export const Feedback: Story = {
args: {},
decorators: [AnalyticsDecorator],
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?",
},
],
},
]);
},
analyticsContext: {
posthogAiBetaClient: {
capture: () => {},
getSurveys: (fn) => {
fn([
{
id: "01917ac7-e417-0000-0c86-99ef890e6807",
name: "End of Aila generation survey launch aug24",
type: SurveyType.API,
questions: [
{
type: SurveyQuestionType.Rating,
question:
"How would you rate the structure and content of this lesson plan?",
},
{
type: SurveyQuestionType.Rating,
question:
"How would you rate the ease of creating this lesson with Aila?",
},
{
type: SurveyQuestionType.Open,
question:
"What suggestions do you have to improve the lesson planning experience with Aila?",
},
],
},
} as unknown as AnalyticsContext
}
>
<Story />
</analyticsContext.Provider>
);
]);
},
} as unknown as PostHog,
},
},
};

0 comments on commit 88116e0

Please sign in to comment.