From 98f5a6ca1a558c3a868f1933c7fd6fad1aa20a1e Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 6 Aug 2024 15:56:07 +0200 Subject: [PATCH] fix(UserFeedback): fix storybook --- app/services/env/web.ts | 10 ++++--- stories/UserFeedback.stories.tsx | 45 ++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/app/services/env/web.ts b/app/services/env/web.ts index 833373451..4599b4d22 100644 --- a/app/services/env/web.ts +++ b/app/services/env/web.ts @@ -1,11 +1,13 @@ -const getNodeOrWebEnv = () => +const envFromBrowser = () => typeof window === "object" && "ENV" in window ? (window?.ENV as Record) - : process.env; + : undefined; -export function config() { - const env = getNodeOrWebEnv(); +const envFromNode = () => + typeof process === "object" && "env" in process ? process?.env : undefined; +export function config() { + const env = envFromBrowser() ?? envFromNode() ?? {}; return { POSTHOG_API_HOST: env.POSTHOG_API_HOST?.trim() ?? "https://eu.i.posthog.com", diff --git a/stories/UserFeedback.stories.tsx b/stories/UserFeedback.stories.tsx index 274696337..1f2bd17f3 100644 --- a/stories/UserFeedback.stories.tsx +++ b/stories/UserFeedback.stories.tsx @@ -1,23 +1,52 @@ import type { Meta, StoryObj } from "@storybook/react"; import UserFeedback, { BannerState } from "../app/components/UserFeedback"; -import { remixContext } from "../.storybook/remixContext"; +import { createRemixStub } from "@remix-run/testing"; +import { redirect, redirectDocument } from "@remix-run/node"; const meta = { title: "Content/UserFeedback", component: UserFeedback, - parameters: { - layout: "fullscreen", - }, tags: ["autodocs"], } satisfies Meta; export default meta; +let bannerStateMemo = BannerState.ShowRating; +const nextBannerState = (bannerState: BannerState) => + bannerState === BannerState.ShowRating + ? BannerState.ShowFeedback + : BannerState.FeedbackGiven; + export const Example: StoryObj = { args: { - rating: { - heading: "Hat Ihnen der Vorab-Check geholfen?", - }, + rating: { heading: "Hat Ihnen der Vorab-Check geholfen?" }, }, - decorators: [(Story) => remixContext(Story)], + decorators: [ + (Story) => { + const RemixStub = createRemixStub([ + { + id: "root", + loader: () => { + const bannerState = bannerStateMemo; + bannerStateMemo = nextBannerState(bannerStateMemo); + return { bannerState }; + }, + children: [ + { path: "/", Component: Story }, + { + path: "/action/send-rating", + action: () => ({ success: true }), + }, + { + Component: Story, // This is a workaround for FeedbackFormBox redirecting to /action/send-feedback + path: "/action/send-feedback", + action: () => ({ success: true }), + }, + ], + }, + ]); + + return ; + }, + ], };