28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { addRecent, MAX_RECENTS, mergeRecents } from "./recents";
|
|
|
|
describe("addRecent", () => {
|
|
it("puts the path first", () => {
|
|
expect(addRecent(["/a", "/b"], "/c")).toEqual(["/c", "/a", "/b"]);
|
|
});
|
|
it("moves a path that is already there to the front instead of repeating it", () => {
|
|
expect(addRecent(["/a", "/b", "/c"], "/b")).toEqual(["/b", "/a", "/c"]);
|
|
});
|
|
it("keeps the list short", () => {
|
|
const many = Array.from({ length: MAX_RECENTS }, (_, i) => `/r${i}`);
|
|
const out = addRecent(many, "/new");
|
|
expect(out).toHaveLength(MAX_RECENTS);
|
|
expect(out[0]).toBe("/new");
|
|
expect(out).not.toContain(`/r${MAX_RECENTS - 1}`);
|
|
});
|
|
});
|
|
|
|
describe("mergeRecents", () => {
|
|
it("keeps the saved order", () => {
|
|
expect(mergeRecents([], ["/a", "/b", "/c"])).toEqual(["/a", "/b", "/c"]);
|
|
});
|
|
it("puts a path opened before the settings arrived first, once", () => {
|
|
expect(mergeRecents(["/b"], ["/a", "/b", "/c"])).toEqual(["/b", "/a", "/c"]);
|
|
});
|
|
});
|