-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof UserFeedback>; | ||
|
||
export default meta; | ||
|
||
let bannerStateMemo = BannerState.ShowRating; | ||
const nextBannerState = (bannerState: BannerState) => | ||
bannerState === BannerState.ShowRating | ||
? BannerState.ShowFeedback | ||
: BannerState.FeedbackGiven; | ||
|
||
export const Example: StoryObj<typeof meta> = { | ||
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 <RemixStub />; | ||
}, | ||
], | ||
}; |