|
| 1 | +import { FlaskConical } from "lucide-react"; |
| 2 | +import { expect, within } from "storybook/test"; |
| 3 | + |
| 4 | + |
| 5 | +import { EmptyState } from "./EmptyState"; |
| 6 | + |
| 7 | +import type { Meta, StoryObj } from "@storybook/react-vite"; |
| 8 | + |
| 9 | +import { Button } from "@/components/ui/button"; |
| 10 | + |
| 11 | +const meta: Meta<typeof EmptyState> = { |
| 12 | + title: "Design Patterns/EmptyState", |
| 13 | + component: EmptyState, |
| 14 | + parameters: { |
| 15 | + layout: "centered", |
| 16 | + }, |
| 17 | + tags: ["autodocs"], |
| 18 | + decorators: [ |
| 19 | + (Story) => ( |
| 20 | + <div className="w-96 rounded-lg border bg-card"> |
| 21 | + <Story /> |
| 22 | + </div> |
| 23 | + ), |
| 24 | + ], |
| 25 | +}; |
| 26 | + |
| 27 | +export default meta; |
| 28 | +type Story = StoryObj<typeof meta>; |
| 29 | + |
| 30 | +export const Default: Story = { |
| 31 | + parameters: { |
| 32 | + // Auto-generated by sync-storybook-zephyr - do not add manually |
| 33 | + zephyr: { testCaseId: "SW-T4912" }, |
| 34 | + }, |
| 35 | + play: async ({ canvasElement }) => { |
| 36 | + const canvas = within(canvasElement); |
| 37 | + expect(canvas.getByText("No records yet")).toBeInTheDocument(); |
| 38 | + expect( |
| 39 | + canvas.getByText( |
| 40 | + "Import a dataset or connect a data source to get started." |
| 41 | + ) |
| 42 | + ).toBeInTheDocument(); |
| 43 | + }, |
| 44 | +}; |
| 45 | + |
| 46 | +export const NoData: Story = { |
| 47 | + args: { |
| 48 | + variant: "no-data", |
| 49 | + action: <Button size="sm">Import data</Button>, |
| 50 | + }, |
| 51 | + parameters: { |
| 52 | + // Auto-generated by sync-storybook-zephyr - do not add manually |
| 53 | + zephyr: { testCaseId: "SW-T4913" }, |
| 54 | + }, |
| 55 | + play: async ({ canvasElement }) => { |
| 56 | + const canvas = within(canvasElement); |
| 57 | + expect(canvas.getByText("No records yet")).toBeInTheDocument(); |
| 58 | + expect( |
| 59 | + canvas.getByRole("button", { name: "Import data" }) |
| 60 | + ).toBeInTheDocument(); |
| 61 | + }, |
| 62 | +}; |
| 63 | + |
| 64 | +export const NoResults: Story = { |
| 65 | + args: { |
| 66 | + variant: "no-results", |
| 67 | + action: ( |
| 68 | + <Button variant="ghost" size="sm"> |
| 69 | + Clear filters |
| 70 | + </Button> |
| 71 | + ), |
| 72 | + }, |
| 73 | + parameters: { |
| 74 | + // Auto-generated by sync-storybook-zephyr - do not add manually |
| 75 | + zephyr: { testCaseId: "SW-T4914" }, |
| 76 | + }, |
| 77 | + play: async ({ canvasElement }) => { |
| 78 | + const canvas = within(canvasElement); |
| 79 | + expect(canvas.getByText("No results found")).toBeInTheDocument(); |
| 80 | + expect( |
| 81 | + canvas.getByRole("button", { name: "Clear filters" }) |
| 82 | + ).toBeInTheDocument(); |
| 83 | + }, |
| 84 | +}; |
| 85 | + |
| 86 | +export const NoAccess: Story = { |
| 87 | + args: { variant: "no-access" }, |
| 88 | + parameters: { |
| 89 | + // Auto-generated by sync-storybook-zephyr - do not add manually |
| 90 | + zephyr: { testCaseId: "SW-T4915" }, |
| 91 | + }, |
| 92 | + play: async ({ canvasElement }) => { |
| 93 | + const canvas = within(canvasElement); |
| 94 | + expect(canvas.getByText("Access restricted")).toBeInTheDocument(); |
| 95 | + expect( |
| 96 | + canvas.getByText( |
| 97 | + "You don't have permission to view this resource. Contact your admin." |
| 98 | + ) |
| 99 | + ).toBeInTheDocument(); |
| 100 | + }, |
| 101 | +}; |
| 102 | + |
| 103 | +export const EmptyFolder: Story = { |
| 104 | + args: { |
| 105 | + variant: "empty-folder", |
| 106 | + action: ( |
| 107 | + <Button size="sm" variant="outline"> |
| 108 | + Upload files |
| 109 | + </Button> |
| 110 | + ), |
| 111 | + }, |
| 112 | + parameters: { |
| 113 | + // Auto-generated by sync-storybook-zephyr - do not add manually |
| 114 | + zephyr: { testCaseId: "SW-T4916" }, |
| 115 | + }, |
| 116 | + play: async ({ canvasElement }) => { |
| 117 | + const canvas = within(canvasElement); |
| 118 | + expect(canvas.getByText("This folder is empty")).toBeInTheDocument(); |
| 119 | + expect( |
| 120 | + canvas.getByRole("button", { name: "Upload files" }) |
| 121 | + ).toBeInTheDocument(); |
| 122 | + }, |
| 123 | +}; |
| 124 | + |
| 125 | +export const ServerError: Story = { |
| 126 | + args: { |
| 127 | + variant: "server-error", |
| 128 | + action: ( |
| 129 | + <Button size="sm" variant="outline"> |
| 130 | + Retry |
| 131 | + </Button> |
| 132 | + ), |
| 133 | + }, |
| 134 | + parameters: { |
| 135 | + // Auto-generated by sync-storybook-zephyr - do not add manually |
| 136 | + zephyr: { testCaseId: "SW-T4917" }, |
| 137 | + }, |
| 138 | + play: async ({ canvasElement }) => { |
| 139 | + const canvas = within(canvasElement); |
| 140 | + expect(canvas.getByText("Something went wrong")).toBeInTheDocument(); |
| 141 | + expect(canvas.getByRole("button", { name: "Retry" })).toBeInTheDocument(); |
| 142 | + }, |
| 143 | +}; |
| 144 | + |
| 145 | +export const CustomContent: Story = { |
| 146 | + args: { |
| 147 | + icon: FlaskConical, |
| 148 | + title: "No experiments run yet", |
| 149 | + description: "Configure your protocol and run your first experiment.", |
| 150 | + action: <Button size="sm">Create experiment</Button>, |
| 151 | + }, |
| 152 | + parameters: { |
| 153 | + // Auto-generated by sync-storybook-zephyr - do not add manually |
| 154 | + zephyr: { testCaseId: "SW-T4918" }, |
| 155 | + }, |
| 156 | + play: async ({ canvasElement }) => { |
| 157 | + const canvas = within(canvasElement); |
| 158 | + expect(canvas.getByText("No experiments run yet")).toBeInTheDocument(); |
| 159 | + expect( |
| 160 | + canvas.getByText( |
| 161 | + "Configure your protocol and run your first experiment." |
| 162 | + ) |
| 163 | + ).toBeInTheDocument(); |
| 164 | + expect( |
| 165 | + canvas.getByRole("button", { name: "Create experiment" }) |
| 166 | + ).toBeInTheDocument(); |
| 167 | + }, |
| 168 | +}; |
| 169 | + |
| 170 | +export const OverrideTitle: Story = { |
| 171 | + name: "Variant with overridden title", |
| 172 | + args: { |
| 173 | + variant: "no-data", |
| 174 | + title: "No pipelines configured", |
| 175 | + description: "Create a pipeline to start processing your data.", |
| 176 | + }, |
| 177 | + parameters: { |
| 178 | + // Auto-generated by sync-storybook-zephyr - do not add manually |
| 179 | + zephyr: { testCaseId: "SW-T4919" }, |
| 180 | + }, |
| 181 | + play: async ({ canvasElement }) => { |
| 182 | + const canvas = within(canvasElement); |
| 183 | + expect(canvas.getByText("No pipelines configured")).toBeInTheDocument(); |
| 184 | + expect( |
| 185 | + canvas.getByText("Create a pipeline to start processing your data.") |
| 186 | + ).toBeInTheDocument(); |
| 187 | + expect(canvas.queryByText("No records yet")).not.toBeInTheDocument(); |
| 188 | + }, |
| 189 | +}; |
| 190 | + |
| 191 | +export const EmptyTitleAndDescription: Story = { |
| 192 | + name: "Empty strings hide title and description", |
| 193 | + args: { |
| 194 | + title: "", |
| 195 | + description: "", |
| 196 | + }, |
| 197 | + parameters: { |
| 198 | + // Auto-generated by sync-storybook-zephyr - do not add manually |
| 199 | + zephyr: { testCaseId: "SW-T4920" }, |
| 200 | + }, |
| 201 | + play: async ({ canvasElement }) => { |
| 202 | + const canvas = within(canvasElement); |
| 203 | + expect(canvas.queryByText("No records yet")).not.toBeInTheDocument(); |
| 204 | + const slot = canvasElement.querySelector('[data-slot="empty-state"]'); |
| 205 | + expect(slot).not.toBeNull(); |
| 206 | + expect(slot?.querySelector("p")).toBeNull(); |
| 207 | + }, |
| 208 | +}; |
0 commit comments