Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
3.0 kB · 85 lines
TypeScript
at sv-fe
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import { describe, expect, it } from "vitest";import { render } from "svelte/server";import type { OAuthUserAgent } from "@atcute/oauth-browser-client";import NotificationItem from "$lib/components/notifications/NotificationItem.svelte";import { notifications } from "$lib/components/notifications/mock";import type { NotificationSummary } from "$lib/components/notifications/types";import { AUTH_KEY, type Auth } from "$lib/auth.svelte";import oauthMetadata from "$lib/oauth-client-metadata";
const rowOf = (type: NotificationSummary["type"]): NotificationSummary => { const found = notifications.find((notification) => notification.type === type); if (!found) throw new Error(`no ${type} fixture to render`); return found;};
const signedIn = (scope: string): Map<unknown, Auth> => new Map([ [ AUTH_KEY, { agent: { session: { token: { scope } } } as unknown as OAuthUserAgent, currentDid: "did:plc:limpet" } as unknown as Auth ] ]);
const markup = (notification: NotificationSummary, context?: Map<unknown, Auth>): string => render(NotificationItem, { props: { notification, onToggleRead: () => {} }, context }).body;
const insideTheLink = (html: string): string => { const open = html.indexOf("<a "); const close = html.indexOf("</a>", open); if (open < 0 || close < 0) throw new Error("the row rendered no link"); return html.slice(open, close);};
describe("a notification row", () => { it("no control sits inside the link, since anchors can't wrap buttons", () => { const html = markup(rowOf("collaborator_invited"), signedIn(oauthMetadata.scope));
expect(insideTheLink(html)).not.toContain("<button"); expect(html.split("<a ")).toHaveLength(2); });
it("one link stretches across the row instead of wrapping it", () => { expect(insideTheLink(markup(rowOf("user_mentioned")))).toContain("after:inset-0"); });
it("an invite gets an accept button", () => { expect(markup(rowOf("collaborator_invited"), signedIn(oauthMetadata.scope))).toContain( "Accept" ); });
it("a session minted before the scopes goes back through authorization", () => { const html = markup( rowOf("collaborator_invited"), signedIn("atproto repo:sh.tangled.repo") );
expect(html).toContain("Sign in again to accept"); expect(html).not.toContain(">Accept<"); });
it("no session, no auth context, no accept button", () => { const signedOut = markup( rowOf("collaborator_invited"), new Map([[AUTH_KEY, { agent: null, currentDid: null } as unknown as Auth]]) );
expect(signedOut).not.toContain("Accept"); expect(signedOut.split("<button")).toHaveLength(2); expect(markup(rowOf("collaborator_invited"))).not.toContain("Accept"); });
it("a row with no offer keeps just its read toggle", () => { const html = markup(rowOf("pull_merged"), signedIn(oauthMetadata.scope));
expect(html).not.toContain("Accept"); expect(html.split("<button")).toHaveLength(2); });});