1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
import type { WorkspaceEntry } from "@dispatch/wire";
import { render, screen } from "@testing-library/svelte";
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import TileActionBar from "./TileActionBar.svelte";
function ws(overrides: Partial<WorkspaceEntry> = {}): WorkspaceEntry {
return {
id: "my-ws",
title: "My Workspace",
defaultCwd: null,
defaultComputerId: null,
starred: false,
archived: false,
createdAt: 1,
lastActivityAt: 2,
conversationCount: 0,
...overrides,
};
}
function handlers() {
return {
onOpen: vi.fn(),
onRename: vi.fn(),
onResize: vi.fn(),
onToggleStar: vi.fn(),
onDetails: vi.fn(),
onPlugins: vi.fn(),
onArchive: vi.fn(),
onDelete: vi.fn(),
onClose: vi.fn(),
};
}
describe("TileActionBar", () => {
it("renders the Open · Rename · Resize · Star · Details · Delete actions", () => {
const h = handlers();
render(TileActionBar, { props: { ws: ws(), ...h } });
expect(screen.getByRole("button", { name: "Open" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Rename" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Resize" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Star" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Details" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Archive" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Delete" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Close actions" })).toBeInTheDocument();
});
it("omits Plugins when no plugins port is present, renders it when one is", () => {
const h = handlers();
const without = render(TileActionBar, { props: { ws: ws(), ...h } });
expect(without.queryByRole("button", { name: "Plugins" })).toBeNull();
without.unmount();
render(TileActionBar, { props: { ws: ws(), withPlugins: true, ...h } });
expect(screen.getByRole("button", { name: "Plugins" })).toBeInTheDocument();
});
it("labels the star action by the current state (Star ↔ Unstar)", () => {
const h = handlers();
const unstarred = render(TileActionBar, { props: { ws: ws({ starred: false }), ...h } });
expect(screen.getByRole("button", { name: "Star" })).toBeInTheDocument();
unstarred.unmount();
render(TileActionBar, { props: { ws: ws({ starred: true }), ...h } });
expect(screen.getByRole("button", { name: "Unstar" })).toBeInTheDocument();
});
it("dispatches each action", async () => {
const user = userEvent.setup();
const h = handlers();
render(TileActionBar, { props: { ws: ws(), ...h } });
await user.click(screen.getByRole("button", { name: "Open" }));
await user.click(screen.getByRole("button", { name: "Rename" }));
await user.click(screen.getByRole("button", { name: "Resize" }));
await user.click(screen.getByRole("button", { name: "Star" }));
await user.click(screen.getByRole("button", { name: "Details" }));
await user.click(screen.getByRole("button", { name: "Archive" }));
await user.click(screen.getByRole("button", { name: "Delete" }));
await user.click(screen.getByRole("button", { name: "Close actions" }));
expect(h.onOpen).toHaveBeenCalledTimes(1);
expect(h.onRename).toHaveBeenCalledTimes(1);
expect(h.onResize).toHaveBeenCalledTimes(1);
expect(h.onToggleStar).toHaveBeenCalledTimes(1);
expect(h.onDetails).toHaveBeenCalledTimes(1);
expect(h.onArchive).toHaveBeenCalledTimes(1);
expect(h.onDelete).toHaveBeenCalledTimes(1);
expect(h.onClose).toHaveBeenCalledTimes(1);
});
});
|