mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
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.
38 lines
990 B
TypeScript
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"]);
|
|
});
|