mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +08:00
Share the list search
Issues, patches, commits and the peer selector each had their own debounce, and issues and patches the same search index. Vitest now resolves Svelte's browser build, as effects never run in the server one.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import { searchCobs } from "@app/lib/cobSearch";
|
||||
|
||||
import { author } from "./support/cobs";
|
||||
|
||||
function cob(
|
||||
id: string,
|
||||
props: Partial<Parameters<typeof searchCobs>[1][0]> = {},
|
||||
) {
|
||||
return {
|
||||
id,
|
||||
title: "Untitled",
|
||||
labels: [],
|
||||
assignees: [],
|
||||
author: author("nobody", null),
|
||||
...props,
|
||||
};
|
||||
}
|
||||
|
||||
const cobs = [
|
||||
cob("1", { title: "Crash on startup" }),
|
||||
cob("2", { labels: ["regression", "ui"] }),
|
||||
cob("3", { assignees: [author("a", null), author("b", "bob")] }),
|
||||
cob("4", { author: author("c", "carol") }),
|
||||
cob("deadbeef"),
|
||||
];
|
||||
|
||||
test("lists everything for an empty query", () => {
|
||||
expect(searchCobs("", cobs).map(c => c.id)).toEqual([
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"deadbeef",
|
||||
]);
|
||||
});
|
||||
|
||||
test.each([
|
||||
["startup", "1"],
|
||||
["regression", "2"],
|
||||
["bob", "3"],
|
||||
["carol", "4"],
|
||||
["deadbeef", "deadbeef"],
|
||||
])("finds %j in cob %j", (query, id) => {
|
||||
expect(searchCobs(query, cobs).map(c => c.id)).toEqual([id]);
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { flushSync } from "svelte";
|
||||
import { afterEach, beforeEach, expect, test, vi } from "vitest";
|
||||
|
||||
import { debounced } from "@app/lib/debounced.svelte";
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test("follows the source once it stops changing", () => {
|
||||
let source = $state("a");
|
||||
let search: { readonly current: string } | undefined;
|
||||
const cleanup = $effect.root(() => {
|
||||
search = debounced(() => source, 150);
|
||||
});
|
||||
flushSync();
|
||||
expect(search?.current).toBe("a");
|
||||
|
||||
source = "ab";
|
||||
flushSync();
|
||||
vi.advanceTimersByTime(100);
|
||||
source = "abc";
|
||||
flushSync();
|
||||
vi.advanceTimersByTime(149);
|
||||
expect(search?.current).toBe("a");
|
||||
|
||||
vi.advanceTimersByTime(1);
|
||||
expect(search?.current).toBe("abc");
|
||||
|
||||
cleanup();
|
||||
});
|
||||
Reference in New Issue
Block a user