A spec was a promise; sixteen of them had become descriptions of code that already shipped, sitting beside four that describe work still outstanding, with nothing in the file telling the two apart. Half the statuses were also wrong — audio-equalizer read "Accepted" with the EQ live on both platforms, the native video spec said the flag stays off after the default was flipped on. The shipped designs move into docs/architecture, which is the maintained description of the build, and the spec files go. Git history keeps the originals; what a future change still needs is carried across: - 01-rust-backend: favourites rewritten (the old section named a file that no longer exists and called shipped buttons "planned"), domain vocabulary owned by Rust (SearchScope, exclusions, the bitrate ladder), background workers - 02-svelte-frontend: app shell and chrome, library mosaic, series/episode navigation, downloaded browse, safe-area insets, native-video store, logging - 03-data-flow: locally-indexed search - 05-platform-backends: audio settings on ExoPlayer, the equalizer's band vocabulary, native video compositing, the background-audio handoff - 06-downloads-and-offline: one storage model, offline catalog visibility - 09-security: path confinement and input binding docs/specs/README.md now says what the directory is for and where each shipped design went. Deferred work the specs recorded is kept beside the code it concerns rather than lost: season-bounded autoplay, the two dead search commands, why indexing is a full crawl. requirements.md had fourteen stale statuses — Android audio parity still read "Linux only", DR-150 still said the native-video default was off, DR-190 was Proposed after DR-196 implemented it, and five tooling requirements were Proposed after landing. Three unbuilt specs suggested requirement ids that have since been allocated to other work; each now carries a warning.
77 lines
2.5 KiB
TypeScript
77 lines
2.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { get } from "svelte/store";
|
|
|
|
// UT-069: `isConnected` must follow backend server reachability ALONE, never
|
|
// navigator.onLine. See docs/architecture/06-downloads-and-offline.md
|
|
// ("Offline Catalog Visibility", DR-079).
|
|
//
|
|
// The connectivity store registers a `connectivity:changed` listener at import
|
|
// time and mirrors its payload into `isServerReachable`. We capture that
|
|
// listener via the mocked `listen`, then drive reachability directly while
|
|
// pinning navigator.onLine to the *opposite* value to prove it is ignored.
|
|
|
|
const h = vi.hoisted(() => {
|
|
const listeners = new Map<string, (event: { payload: unknown }) => void>();
|
|
return { listeners };
|
|
});
|
|
|
|
vi.mock("@tauri-apps/api/event", () => ({
|
|
listen: vi.fn(async (name: string, cb: (event: { payload: unknown }) => void) => {
|
|
h.listeners.set(name, cb);
|
|
return () => h.listeners.delete(name);
|
|
}),
|
|
}));
|
|
|
|
vi.mock("$lib/api/bindings", () => ({
|
|
commands: {
|
|
connectivityCheckServer: vi.fn(async () => true),
|
|
connectivityGetStatus: vi.fn(async () => ({
|
|
isServerReachable: true,
|
|
lastChecked: null,
|
|
connectionError: null,
|
|
isChecking: false,
|
|
})),
|
|
connectivitySetServerUrl: vi.fn(async () => {}),
|
|
connectivityStartMonitoring: vi.fn(async () => {}),
|
|
connectivityStopMonitoring: vi.fn(async () => {}),
|
|
},
|
|
}));
|
|
|
|
vi.mock("$app/environment", () => ({ browser: true }));
|
|
|
|
function setNavigatorOnLine(value: boolean) {
|
|
Object.defineProperty(window.navigator, "onLine", {
|
|
configurable: true,
|
|
get: () => value,
|
|
});
|
|
}
|
|
|
|
function emitReachable(isReachable: boolean) {
|
|
const cb = h.listeners.get("connectivity:changed");
|
|
if (!cb) throw new Error("connectivity:changed listener was not registered");
|
|
cb({ payload: { isReachable } });
|
|
}
|
|
|
|
describe("isConnected follows server reachability alone (UT-069)", () => {
|
|
beforeEach(() => {
|
|
h.listeners.clear();
|
|
vi.resetModules(); // fresh connectivity module ⇒ re-registers its listener
|
|
});
|
|
|
|
it("is false when the server is unreachable even though navigator.onLine is true", async () => {
|
|
setNavigatorOnLine(true);
|
|
const { isConnected } = await import("./connectivity");
|
|
|
|
emitReachable(false);
|
|
expect(get(isConnected)).toBe(false);
|
|
});
|
|
|
|
it("is true when the server is reachable even though navigator.onLine is false", async () => {
|
|
setNavigatorOnLine(false);
|
|
const { isConnected } = await import("./connectivity");
|
|
|
|
emitReachable(true);
|
|
expect(get(isConnected)).toBe(true);
|
|
});
|
|
});
|