Files
radicle-explorer/desktop/tests/unit/latestOnly.test.ts
T
Rūdolfs Ošiņš 24eddead28 desktop: Sync the notification count
The backend now tells the frontend whenever the notifications database
changes, which covers notifications the node writes as it fetches as well
as clears by another instance of the app or the `rad` CLI, which have no
node event. The inbox reloads in place, keeping the rows in view where
they are.
2026-11-20 19:32:17 +01:00

38 lines
990 B
TypeScript

import { expect, test } from "vitest";
import { latestOnly } from "@app/lib/latestOnly";
function deferred<T>() {
let resolve!: (value: T) => void;
const promise = new Promise<T>(res => {
resolve = res;
});
return { promise, resolve };
}
test("a load that finishes after a later one is dropped", async () => {
const applied: string[] = [];
const load = latestOnly<string>(value => applied.push(value));
const older = deferred<string>();
const newer = deferred<string>();
const first = load(() => older.promise);
const second = load(() => newer.promise);
newer.resolve("newer");
await second;
older.resolve("older");
await first;
expect(applied).toEqual(["newer"]);
});
test("loads that finish in order all apply", async () => {
const applied: string[] = [];
const load = latestOnly<string>(value => applied.push(value));
await load(async () => "first");
await load(async () => "second");
expect(applied).toEqual(["first", "second"]);
});