Open History to see the last commit
1import { describe, expect, test } from "vite-plus/test";
2
3import { planToolbar, toolbarWidth } from "./toolbar-plan";
4
5describe("planToolbar", () => {
6 test("shows everything and a full search field when there's room", () => {
7 const plan = planToolbar(1000);
8 expect(plan.overflow).toEqual([]);
9 expect(plan.searchField).toBe(true);
10 });
11
12 test("shrinks search to an icon before hiding any item", () => {
13 const everything = planToolbar(1000).visible;
14 const justFits = toolbarWidth(everything, { searchField: false, overflowButton: false });
15 const plan = planToolbar(justFits);
16 expect(plan.searchField).toBe(false);
17 expect(plan.overflow).toEqual([]);
18 });
19
20 test("moves the trailing items into the overflow menu first", () => {
21 const plan = planToolbar(420);
22 expect(plan.overflow).toEqual(expect.arrayContaining(["share", "more"]));
23 expect(plan.visible.has("format")).toBe(true);
24 expect(plan.visible.has("checklist")).toBe(true);
25 });
26
27 test("keeps overflow in toolbar order", () => {
28 const plan = planToolbar(260);
29 const order = [
30 "format",
31 "checklist",
32 "table",
33 "attachment",
34 "markup",
35 "link",
36 "collaborate",
37 "share",
38 "more",
39 ];
40 expect(plan.overflow).toEqual(order.filter((id) => plan.overflow.includes(id as never)));
41 });
42
43 test("the plan always fits, down to a very narrow editor", () => {
44 for (let width = 200; width <= 1000; width += 10) {
45 const plan = planToolbar(width);
46 const needed = toolbarWidth(plan.visible, {
47 searchField: plan.searchField,
48 overflowButton: plan.overflow.length > 0,
49 });
50 if (plan.visible.size > 0) expect(needed).toBeLessThanOrEqual(width);
51 }
52 });
53});