Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109<script module lang="ts"> import { defineMeta } from "@storybook/addon-svelte-csf"; import { expect, userEvent, waitFor, within } from "storybook/test"; import MessageSquarePlus from "$icon/message-square-plus"; import Pencil from "$icon/pencil"; import CommentEditor from "$lib/components/comment/CommentEditor.svelte"; import { sampleComments, sampleMarkup, sampleSubjectCid, sampleSubjectUri } from "$fixtures/comments";
const { mine } = sampleComments;
// edit-mode args reused by the Editing and Failed edit stories const editArgs = { rkey: mine.rkey, createdAt: mine.createdAt, body: mine.body, placeholder: "Edit your comment. Markdown is supported.", submitLabel: "Save", submitIcon: Pencil, oncancel: () => undefined };
const { Story } = defineMeta({ title: "Comment/CommentEditor", component: CommentEditor, tags: ["autodocs"], args: { subjectUri: sampleSubjectUri, subjectCid: sampleSubjectCid, authorDid: mine.authorDid, authorHandle: mine.authorHandle, markup: sampleMarkup, rows: 4, placeholder: "Add to the discussion. Markdown is supported.", submitLabel: "Comment", submitIcon: MessageSquarePlus } });</script>
<!-- composing a new comment: empty, "Comment" label, no cancel --><Story name="Compose" />
<!-- editing an existing comment: prefilled body, "Save" label, cancel available --><Story name="Editing" args={editArgs} />
<!-- editing then failing to save against a fake agent that rejects --><Story name="Failed edit" args={editArgs} parameters={{ auth: true }} play={async ({ canvasElement }) => { const canvas = within(canvasElement); await userEvent.click(canvas.getByRole("button", { name: "Save" })); await waitFor(() => expect(canvas.getByRole("alert")).toHaveTextContent(/network request failed/i) ); }}/>
<Story name="Composing with several accounts" parameters={{ auth: { accounts: 2 } }} play={async ({ canvasElement }) => { const canvas = within(canvasElement); await userEvent.click(canvas.getByRole("button", { name: /comment as alice/i })); await userEvent.click(await canvas.findByRole("menuitem", { name: /bob/i })); await waitFor(() => expect(canvas.getByRole("button", { name: /comment as bob/i })).toBeVisible() ); }}/>
<Story name="Editing with several accounts" args={editArgs} parameters={{ auth: { accounts: 2 } }} play={async ({ canvasElement }) => { const canvas = within(canvasElement); expect(canvas.queryByRole("button", { name: /comment as/i })).toBeNull(); await waitFor(() => expect(canvas.getByRole("button", { name: "Save" })).toBeVisible()); }}/>
<Story name="Expired session for the picked account" parameters={{ auth: { accounts: 3, expired: ["did:plc:bob"] } }} play={async ({ canvasElement }) => { const canvas = within(canvasElement); await userEvent.click(canvas.getByRole("button", { name: /comment as alice/i })); await userEvent.click(await canvas.findByRole("menuitem", { name: /bob/i })); await userEvent.type(canvas.getByPlaceholderText(/add to the discussion/i), "as bob"); await userEvent.click(canvas.getByRole("button", { name: "Comment" })); await waitFor(() => expect(canvas.getByRole("alert")).toHaveTextContent(/session expired/i) ); await waitFor(() => expect(canvas.getByRole("button", { name: /comment as alice/i })).toBeVisible() ); await userEvent.click(canvas.getByRole("button", { name: /comment as alice/i })); await waitFor(() => expect(canvas.getByRole("menuitem", { name: /carol/i })).toBeVisible()); expect(canvas.queryByRole("menuitem", { name: /bob/i })).toBeNull(); }}/>