feat(linear): simplify member settings and cache workspace profiles
This commit is contained in:
1 parent
a6da05164d
commit
a9412aedd0
24 files changed
+526
-93
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { cleanup, fireEvent, render } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { LinearAvatar } from "../../../nanobot/channels/linear/webui/LinearAvatar";
|
||||
|
||||
afterEach(cleanup);
|
||||
describe("Linear workspace logo", () => {
|
||||
it("loads a real CDN logo in a fixed-size square and recovers to the workspace icon", () => {
|
||||
const view = render(<LinearAvatar workspace name="nanobot" url="https://public.linear.app/org/logo" />);
|
||||
const image = view.container.querySelector("img")!;
|
||||
expect(image).toHaveAttribute("width", "36");
|
||||
expect(image).toHaveAttribute("height", "36");
|
||||
expect(image).toHaveAttribute("referrerpolicy", "no-referrer");
|
||||
expect(image.parentElement).toHaveClass("h-9", "w-9", "rounded-control");
|
||||
fireEvent.error(image);
|
||||
expect(view.container.querySelector("img")).toBeNull();
|
||||
expect(view.container.querySelector("svg")).not.toBeNull();
|
||||
view.rerender(<LinearAvatar workspace name="nanobot" url="https://uploads.linear.app/org/new-logo" />);
|
||||
expect(view.container.querySelector("img")).toHaveAttribute("src", "https://uploads.linear.app/org/new-logo");
|
||||
});
|
||||
|
||||
it.each([null, "https://untrusted.example/logo", "http://public.linear.app/logo"])(
|
||||
"uses an icon for missing or untrusted logo %s", url => {
|
||||
const view = render(<LinearAvatar workspace name="nanobot" url={url} />);
|
||||
expect(view.container.querySelector("img")).toBeNull();
|
||||
expect(view.container.querySelector("svg")).not.toBeNull();
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -88,11 +88,14 @@ describe("Linear member access", () => {
|
||||
await openMembers();
|
||||
expect(yongru()).not.toBeChecked();
|
||||
expect(xubin()).toBeChecked();
|
||||
expect(header()).toHaveTextContent("1 of 2 enabled");
|
||||
expect(header()).not.toHaveTextContent("1 enabled");
|
||||
fireEvent.click(header());
|
||||
expect(header()).toHaveTextContent("1 enabled");
|
||||
fireEvent.click(header());
|
||||
expect(requestMutation).toHaveBeenCalledWith("settings.channel.connect.start", {
|
||||
channel: "linear", operation: "members", organization_id: "org-1",
|
||||
}, 150_000);
|
||||
expect(screen.getByText(/No pairing codes needed/)).toBeVisible();
|
||||
expect(screen.queryByText(/No pairing codes needed/)).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("tooltip")).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "About member access" }));
|
||||
expect(await screen.findByRole("tooltip")).toHaveTextContent("does not grant access");
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { WebUIMutationTransport } from "@/lib/api";
|
||||
|
||||
import { linearWorkspaceStore } from "../../../nanobot/channels/linear/webui/workspace-store";
|
||||
|
||||
const installation = { organization_id: "org-1", organization_name: "nanobot" };
|
||||
const logo = "https://public.linear.app/org-1/logo";
|
||||
function fixture() {
|
||||
const requestMutation = vi.fn<WebUIMutationTransport["requestMutation"]>(async (_action, params) =>
|
||||
params?.operation === "inspect"
|
||||
? { installations: [installation] }
|
||||
: { organization_id: "org-1", logo_url: logo });
|
||||
const client = { requestMutation };
|
||||
const store = linearWorkspaceStore(client, "session", "app");
|
||||
return { requestMutation, client, store };
|
||||
}
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
describe("Linear workspace display cache", () => {
|
||||
it("publishes the workspace before the logo arrives and caches both on reopen", async () => {
|
||||
const { requestMutation, client, store } = fixture();
|
||||
let finish!: (value: unknown) => void;
|
||||
requestMutation.mockImplementation(async (_action, params) => params?.operation === "inspect"
|
||||
? { installations: [installation] } : new Promise(resolve => { finish = resolve; }));
|
||||
await store.load();
|
||||
expect(store.getSnapshot().installations).toEqual([installation]);
|
||||
expect(store.getSnapshot().loading).toBe(false);
|
||||
expect(store.getSnapshot().logos).toEqual({});
|
||||
finish({ organization_id: "org-1", logo_url: logo });
|
||||
await vi.waitFor(() => expect(store.getSnapshot().logos["org-1"]).toBe(logo));
|
||||
const reopened = linearWorkspaceStore(client, "session", "app");
|
||||
expect(reopened).toBe(store);
|
||||
await reopened.load();
|
||||
expect(requestMutation).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("keeps stale workspaces visible while refreshing and after a failed refresh", async () => {
|
||||
const { requestMutation, store } = fixture();
|
||||
await store.load();
|
||||
await vi.waitFor(() => expect(store.getSnapshot().logos["org-1"]).toBe(logo));
|
||||
vi.spyOn(Date, "now").mockReturnValue(Date.now() + 61_000);
|
||||
let fail!: (error: Error) => void;
|
||||
requestMutation.mockImplementationOnce(() => new Promise((_resolve, reject) => { fail = reject; }));
|
||||
const refresh = store.load();
|
||||
expect(store.getSnapshot().installations).toEqual([installation]);
|
||||
expect(store.getSnapshot().logos["org-1"]).toBe(logo);
|
||||
expect(store.getSnapshot().loading).toBe(true);
|
||||
fail(new Error("Offline"));
|
||||
await refresh;
|
||||
expect(store.getSnapshot().installations).toEqual([installation]);
|
||||
expect(store.getSnapshot().error).toBe("Offline");
|
||||
});
|
||||
|
||||
it("does not let an old read resurrect a disconnected workspace", async () => {
|
||||
const { requestMutation, store } = fixture();
|
||||
let finish!: (value: unknown) => void;
|
||||
requestMutation.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));
|
||||
const load = store.load();
|
||||
store.replace([]);
|
||||
finish({ installations: [installation] });
|
||||
await load;
|
||||
expect(store.getSnapshot().installations).toEqual([]);
|
||||
expect(requestMutation).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("ignores a late logo after disconnect and treats a removed logo as empty", async () => {
|
||||
const { requestMutation, store } = fixture();
|
||||
let finish!: (value: unknown) => void;
|
||||
requestMutation.mockImplementation(async (_action, params) => params?.operation === "inspect"
|
||||
? { installations: [installation] } : new Promise(resolve => { finish = resolve; }));
|
||||
await store.load();
|
||||
store.replace([]);
|
||||
finish({ organization_id: "org-1", logo_url: logo });
|
||||
await Promise.resolve();
|
||||
expect(store.getSnapshot().logos).toEqual({});
|
||||
requestMutation.mockImplementation(async (_action, params) => params?.operation === "inspect"
|
||||
? { installations: [installation] } : { organization_id: "org-1", logo_url: null });
|
||||
await store.load(true);
|
||||
await vi.waitFor(() => expect(store.getSnapshot().logos).toEqual({ "org-1": null }));
|
||||
});
|
||||
|
||||
it("keeps usable workspaces when their optional profile fails", async () => {
|
||||
const { requestMutation, store } = fixture();
|
||||
requestMutation.mockImplementation(async (_action, params) => {
|
||||
if (params?.operation === "inspect") return { installations: [installation] };
|
||||
throw new Error("Profile unavailable");
|
||||
});
|
||||
await store.load();
|
||||
await Promise.resolve();
|
||||
expect(store.getSnapshot().installations).toEqual([installation]);
|
||||
expect(store.getSnapshot().error).toBeNull();
|
||||
expect(store.getSnapshot().logos).toEqual({});
|
||||
});
|
||||
|
||||
it("isolates gateways, admin sessions, and app configurations", async () => {
|
||||
const { client, store } = fixture();
|
||||
await store.load();
|
||||
expect(linearWorkspaceStore({ requestMutation: client.requestMutation }, "session", "app").getSnapshot().installations).toBeNull();
|
||||
expect(linearWorkspaceStore(client, "session", "other-app").getSnapshot().installations).toBeNull();
|
||||
expect(linearWorkspaceStore(client, "other-session", "app").getSnapshot().installations).toBeNull();
|
||||
});
|
||||
|
||||
it("deduplicates pending inspections and notifies subscribers", async () => {
|
||||
const { requestMutation, store } = fixture();
|
||||
let finish!: (value: unknown) => void;
|
||||
requestMutation.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));
|
||||
const listener = vi.fn();
|
||||
const unsubscribe = store.subscribe(listener);
|
||||
const pending = store.load();
|
||||
await store.load();
|
||||
expect(requestMutation).toHaveBeenCalledTimes(1);
|
||||
expect(listener).toHaveBeenCalledOnce();
|
||||
finish({ installations: [] });
|
||||
await pending;
|
||||
expect(listener).toHaveBeenCalledTimes(2);
|
||||
unsubscribe();
|
||||
store.replace([]);
|
||||
expect(listener).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user