|
| 1 | +import type { Meta, StoryObj } from "@storybook/react-vite"; |
| 2 | +import { userEvent, within, expect } from "storybook/test"; |
| 3 | +import React from "react"; |
| 4 | +import { ChatInput } from "./index"; |
| 5 | +import { ModeProvider } from "@/browser/contexts/ModeContext"; |
| 6 | + |
| 7 | +const meta: Meta = { |
| 8 | + title: "Components/ChatInput", |
| 9 | + parameters: { |
| 10 | + layout: "padded", |
| 11 | + }, |
| 12 | + decorators: [ |
| 13 | + (Story) => ( |
| 14 | + <ModeProvider> |
| 15 | + <div className="w-[600px]"> |
| 16 | + <Story /> |
| 17 | + </div> |
| 18 | + </ModeProvider> |
| 19 | + ), |
| 20 | + ], |
| 21 | +}; |
| 22 | + |
| 23 | +export default meta; |
| 24 | +type Story = StoryObj; |
| 25 | + |
| 26 | +// eslint-disable-next-line @typescript-eslint/no-empty-function |
| 27 | +const noop = async () => {}; |
| 28 | + |
| 29 | +export const WorkspaceVariant: Story = { |
| 30 | + render: () => ( |
| 31 | + <ChatInput variant="workspace" workspaceId="test-workspace-id" onTruncateHistory={noop} /> |
| 32 | + ), |
| 33 | +}; |
| 34 | + |
| 35 | +/** |
| 36 | + * This story verifies the model favorites integration is working. |
| 37 | + * |
| 38 | + * When clicking the model selector, the dropdown should show star icons |
| 39 | + * next to each model for setting/viewing the default model. If the stars |
| 40 | + * are missing, the favorites integration has been broken. |
| 41 | + */ |
| 42 | +export const ModelFavoritesIntegration: Story = { |
| 43 | + render: () => ( |
| 44 | + <ChatInput |
| 45 | + variant="workspace" |
| 46 | + workspaceId="test-workspace-favorites" |
| 47 | + onTruncateHistory={noop} |
| 48 | + /> |
| 49 | + ), |
| 50 | + play: async ({ canvasElement }) => { |
| 51 | + const canvas = within(canvasElement); |
| 52 | + |
| 53 | + // Click the model selector to open dropdown |
| 54 | + const modelSelector = canvas.getByRole("button", { name: /claude|anthropic|model/i }); |
| 55 | + await userEvent.click(modelSelector); |
| 56 | + |
| 57 | + // The dropdown should show star icons for setting default model |
| 58 | + // Look for the star buttons in the dropdown |
| 59 | + const starButtons = canvasElement.querySelectorAll( |
| 60 | + '[data-component="ModelSelectorGroup"] button svg' |
| 61 | + ); |
| 62 | + |
| 63 | + // There should be star icons visible (at least one for each model in dropdown) |
| 64 | + // This will fail if defaultModel/onSetDefaultModel props are not passed |
| 65 | + await expect(starButtons.length).toBeGreaterThan(0); |
| 66 | + }, |
| 67 | +}; |
0 commit comments