Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { player } from "../player";import { peekThemeMode, setThemeMode } from "../theme/mode";import { clearConnection, connection, saveConnection } from "../connection";import { lyrics } from "../lyrics";import { LrclibClient, resetLrclib } from "../lyrics/lrclib";import { beginLadder, clearLadderAudits, endLadder, ladderAuditEnabled, ladderAuditModal, ladderAudits, recordRung, recordUnasked, setLadderAuditEnabled, showLadderAudit,} from "../lyrics/audit";import { foundRecord, lrclibFetch } from "../../test/lrclib";import { mediaFiles, navidromeFetch } from "../../test/navidrome";import { library } from "../harvest";import { COMMANDS, describe as describeLine, findCommand, runCommand, splitCommand, type CommandOutcome,} from "./commands";
/** * The verbs the command line knows. * * The parser and the readout are the parts with opinions — what `:vol +5` means, what * a word that is not a verb says, which words mean the same verb — and all of it is * answerable without a page, a track, or a sound card: every command here runs against * the real store, and the store's volume/repeat/queue face works with no AudioContext * because the engine only builds a graph when something asks it to play. */
/** * A verb that answers in the press, which is every verb but `:scan`. The narrowing is * the point: a verb that grew a round-trip would fail here loudly instead of handing * a Promise to an `expect(...).text` and failing somewhere far away. */function syncRun(raw: string): { outcome: CommandOutcome; ran: boolean } { const { outcome, ran } = runCommand(raw); if (outcome instanceof Promise) throw new Error(`${raw} answered asynchronously`); return { outcome, ran };}
afterEach(() => { // The store is the page's one instance, so a verb that moved it has to be undone by // the test that moved it rather than by the next file's luck. player().setVolume(0.8); player().setRepeat("none"); // ...and so is the deck's octave: persisted, in-memory as the truth, and one press of `]` // from a verb test away from playing every later test an octave high. player().setSpeed(1); player().setKey(0); player().setLock(false); // The theme mode is the same kind of persisted global the volume and repeat are. setThemeMode("system");});
it("splits a line into the word and its arguments", () => { expect(splitCommand(" vol 40 ")).toEqual({ word: "vol", args: ["40"] }); expect(splitCommand("seek")).toEqual({ word: "seek", args: [] }); expect(splitCommand(" ")).toEqual({ word: "", args: [] });});
it("knows a verb by its aliases as well", () => { expect(findCommand("v")).toBe(findCommand("vol")); expect(findCommand("VOLUME")).toBe(findCommand("vol")); expect(findCommand("?")).toBe(findCommand("help")); expect(findCommand("previous")).toBe(findCommand("prev")); expect(findCommand("nonsense")).toBeNull(); expect(findCommand("")).toBeNull();});
it("reads every verb's usage back off the table", () => { // One table, two readers: the readout and `:help` print what the dispatcher runs, so // a verb cannot be listed and unrunnable — or runnable and unlistable. const names = COMMANDS.map((c) => c.name); expect(new Set(names).size).toBe(names.length); const { outcome } = syncRun("help"); for (const n of names) expect(outcome.text).toContain(n);});
it("says what a word means while it is being typed", () => { expect(describeLine("vol 40")?.text).toBe("the master gain"); // a verb that needs an argument says so until one arrives, and stops saying it after expect(describeLine("seek")?.text).toBe("jump to a place in the track · seek <m:ss|s> [+/-n]"); expect(describeLine("seek 1:20")?.text).toBe("jump to a place in the track"); // an optional argument is never nagged for expect(describeLine("vol")?.text).toBe("the master gain"); expect(describeLine("nonsense")?.bad).toBe(true); expect(describeLine("")).toBeNull();});
it("refuses a word that is not a verb, and says which word it did not recognise", () => { const { outcome, ran } = syncRun("vloume 40"); expect(ran).toBe(false); expect(outcome.bad).toBe(true); expect(outcome.text).toContain("vloume"); expect(outcome.text).toContain(":help");});
it("sets the level, moved or placed, and says the level it landed on", () => { expect(syncRun("vol 40").outcome.text).toBe("40%"); expect(player().peekVolume()).toBeCloseTo(0.4, 5);
// a bare number is a place on the slider, and only a sign or a word is a move expect(syncRun("vol +10").outcome.text).toBe("50%"); expect(syncRun("vol -20").outcome.text).toBe("30%"); expect(syncRun("vol up").outcome.text).toBe("35%"); expect(syncRun("vol down").outcome.text).toBe("30%");
expect(syncRun("vol mute").outcome.text).toBe("mute"); expect(player().peekVolume()).toBe(0); // with nothing typed it reports where the slider sits rather than doing nothing expect(syncRun("vol").outcome.text).toContain("0%");});
it("takes a level written either way round, and refuses one written neither", () => { expect(syncRun("vol 0.5").outcome.text).toBe("50%"); expect(syncRun("vol 75%").outcome.text).toBe("75%"); const refusal = syncRun("vol loud"); expect(refusal.outcome.bad).toBe(true); expect(refusal.outcome.text).toContain("loud");});
it("names a repeat mode by the word the reader knows", () => { expect(syncRun("repeat album").outcome.text).toBe("repeat album"); expect(player().peekRepeat()).toBe("album"); expect(syncRun("repeat off").outcome.text).toBe("repeat none"); expect(syncRun("repeat one").outcome.text).toBe("repeat single"); // a bare `repeat` is the cycle, which is what the `l` key and the button do — and // the cycle runs off the end of the order, so from `single` (which `one` just set) // the next mode is `none` again expect(syncRun("repeat").outcome.text).toBe("repeat none"); expect(syncRun("repeat").outcome.text).toBe("repeat album"); const refusal = syncRun("repeat sideways"); expect(refusal.outcome.bad).toBe(true); expect(refusal.outcome.text).toContain("album, artist, single");});
it("wears a theme the listener asked for, and follows the machine by default", () => { // The three states, by the words that name them. The line reports the mode *and* the // theme it paints, because with `system` they can differ and the difference is the point. expect(syncRun("theme light").outcome.text).toBe("theme light · painting light"); expect(peekThemeMode()).toBe("light"); expect(syncRun("theme dark").outcome.text).toBe("theme dark · painting dark"); expect(peekThemeMode()).toBe("dark"); // `system` here resolves to dark: the test runner has no `matchMedia`, and the app keeps // its own identity with no machine to ask. expect(syncRun("theme system").outcome.text).toBe("theme system · painting dark"); expect(peekThemeMode()).toBe("system"); // the words a listener reaches for that are not the token still mean the same state expect(syncRun("theme auto").outcome.text).toBe("theme system · painting dark"); expect(syncRun("theme light").outcome.text).toContain("painting light");
// a bare `theme` is the cycle, so all three states are reachable (and `system` is // re-enterable) without knowing the words: dark -> system -> light, wrapping. setThemeMode("dark"); expect(syncRun("theme").outcome.text).toBe("theme system · painting dark"); expect(syncRun("theme").outcome.text).toBe("theme light · painting light"); expect(syncRun("theme").outcome.text).toBe("theme dark · painting dark");
const refusal = syncRun("theme sepia"); expect(refusal.outcome.bad).toBe(true); expect(refusal.outcome.text).toContain("sepia"); expect(refusal.outcome.text).toContain("system, light, dark");});
it("answers about the queue without a queue, and refuses to invent a row", () => { // Nothing is loaded in this file — no connection, no library — which is exactly the // state where a command line either tells the truth about being empty or lies. expect(syncRun("queue").outcome.text).toBe("the queue is empty"); expect(syncRun("next").outcome.bad).toBe(true); expect(syncRun("prev").outcome.bad).toBe(true); expect(syncRun("seek 1:20").outcome.bad).toBe(true); expect(syncRun("queue 3").outcome.bad).toBe(true); expect(syncRun("queue zero").outcome.bad).toBe(true); expect(syncRun("stop").outcome.text).toBe("stopped");});
it("clears the A–B region it is not given two times to set", () => { // No bytes are decoded in this file, so every region is refused — and the refusal is // the store's own, told in the bar's words rather than as a parse error. expect(syncRun("loop 1:00-2:00").outcome.bad).toBe(true); expect(player().peekLoop()).toBeNull(); expect(syncRun("loop").outcome.text).toBe("no A–B"); expect(syncRun("loop off").outcome.text).toBe("no A–B"); expect(syncRun("loop 1:00").outcome.bad).toBe(true); // one time is not a span});
describe(":scan", () => { afterEach(() => { vi.unstubAllGlobals(); clearConnection(); });
it("is a verb, with an alias", () => { expect(findCommand("rescan")).toBe(findCommand("scan")); expect(describeLine("scan")?.text).toBe( "ask the server to look for new files, and re-harvest when it is done", ); });
it("refuses before the server when nobody is connected", () => { clearConnection(); const { outcome } = syncRun("scan"); expect(outcome).toEqual({ text: "not connected", bad: true }); });
it("refuses a kind of scan that is not a kind, in the press itself", () => { saveConnection({ host: "nav.example.com", username: "admin", password: "pw" }); const { outcome } = syncRun("scan sideways"); expect(outcome.bad).toBe(true); expect(outcome.text).toContain("not a kind of scan"); });
it("asks the server for a quick scan and reports where the rows went", async () => { saveConnection({ host: "nav.example.com", username: "admin", password: "pw" }); const fetchMock = navidromeFetch([]); vi.stubGlobal("fetch", fetchMock);
const { outcome, ran } = runCommand("scan"); expect(ran).toBe(true); expect(outcome).toBeInstanceOf(Promise); // the answer is a round-trip const line = await outcome; expect(line).toEqual({ text: "scan done · rows on the way", bad: false });
const asked = (fetchMock.mock.calls as unknown as unknown[][]) .map((c) => String(c[0])) .find((u) => u.includes("/rest/startScan")); expect(asked).toBeDefined(); expect(asked).toContain("fullScan=false"); });
it("takes full when every file should be reprocessed", async () => { saveConnection({ host: "nav.example.com", username: "admin", password: "pw" }); const fetchMock = navidromeFetch([]); vi.stubGlobal("fetch", fetchMock);
const outcome = runCommand("scan full").outcome; expect(outcome).toBeInstanceOf(Promise); await outcome;
const asked = (fetchMock.mock.calls as unknown as unknown[][]) .map((c) => String(c[0])) .find((u) => u.includes("/rest/startScan")); expect(asked).toContain("fullScan=true"); });
it("reports the server's own refusal — a non-admin is not a silent success", async () => { saveConnection({ host: "nav.example.com", username: "admin", password: "pw" }); vi.stubGlobal("fetch", navidromeFetch([], { scanFailure: "User is not admin" }));
const outcome = runCommand("scan").outcome; expect(outcome).toBeInstanceOf(Promise); const line = await outcome; expect(line.bad).toBe(true); // the client's SubsonicError words, server message included expect(line.text).toContain("scan refused"); expect(line.text).toContain("User is not admin"); });});
/** * The library verbs. * * `:harvest` reads the ledger the store kept of its own crawls, so these run the *page's* store — * the same singleton the toolbar renders — rather than a factory instance. Which is the point of the * verb: the numbers a reader can ask for are the ones the screen in front of them was built from. */describe(":harvest", () => { afterEach(() => { vi.unstubAllGlobals(); clearConnection(); library().reset(); });
const connect = () => saveConnection({ host: "https://nav.example.com", username: "admin", password: "pw" });
/** `n` tracks under one record, in the shape the native API answers with. */ const shelf = (n: number) => mediaFiles({ album: "Album", albumArtist: "Artist", albumId: "al-1", artistId: "ar-1" }, n);
/** Crawl through the singleton, the way the app root does. */ async function crawl(): Promise<void> { await library().load(connection()!); }
it("is a verb, with aliases", () => { expect(findCommand("index")).toBe(findCommand("harvest")); expect(findCommand("lib")).toBe(findCommand("harvest")); expect(describeLine("harvest")?.text).toContain("whether anything was deleted"); });
it("says there is nothing to read, rather than pretending the app is broken", () => { const { outcome } = syncRun("harvest"); expect(outcome.bad).toBe(true); expect(outcome.text).toContain("no crawl written down yet"); });
it("reads back what the last crawl fetched, what was counted, and that the delete ran", async () => { connect(); vi.stubGlobal("fetch", navidromeFetch(shelf(3))); await crawl();
const { outcome } = syncRun("harvest"); expect(outcome.bad).toBe(false); expect(outcome.text).toContain("harvest believed"); expect(outcome.text).toContain("3 tracks, 1 record fetched"); expect(outcome.text).toContain("counted 3"); // The question the line exists to answer, spelled out rather than left to the verdict word. expect(outcome.text).toContain("· pruned ·"); expect(outcome.text).toContain("navidrome"); });
it("walks back over the crawls this session wrote down", async () => { connect(); vi.stubGlobal("fetch", navidromeFetch(shelf(3))); await crawl(); expect(syncRun("harvest 2").outcome.bad).toBe(true); // one crawl, and the verb says so
// A second crawl, of a library the server has since counted larger: the newest line is the one a // bare `:harvest` says, and the crawl behind it is still there to compare it against. vi.stubGlobal("fetch", navidromeFetch(shelf(5))); await crawl(); expect(library().peekReceipts()).toHaveLength(2); expect(syncRun("harvest").outcome.text).toContain("5 tracks"); expect(syncRun("harvest 2").outcome.text).toContain("3 tracks"); });
it("refuses an argument that is neither a crawl nor the rebuild", () => { connect(); vi.stubGlobal("fetch", navidromeFetch(shelf(1))); return crawl().then(() => { expect(syncRun("harvest sideways").outcome.text).toContain("not a crawl"); expect(syncRun("harvest 0").outcome.bad).toBe(true); }); });
it("will not rebuild what it cannot reach", () => { clearConnection(); expect(syncRun("harvest rebuild").outcome).toEqual({ text: "not connected", bad: true }); });
it("rebuilds the index from cold, and says what the cold crawl made of itself", async () => { connect(); const fetchMock = navidromeFetch(shelf(2)); vi.stubGlobal("fetch", fetchMock); await crawl(); const before = (fetchMock.mock.calls as unknown as unknown[][]).length;
const outcome = await runCommand("harvest rebuild").outcome; expect(outcome.bad).toBe(false); expect(outcome.text).toContain("index rebuilt from cold"); expect(outcome.text).toContain("harvest believed"); // a real re-crawl, not a warm boot off the disk it just deleted expect((fetchMock.mock.calls as unknown as unknown[][]).length).toBeGreaterThan(before); expect(library().status()).toBe("ready"); expect(library().songs()).toHaveLength(2); });});
/** * The pitch verbs. One table row each, and one thing between them: the line reports the state as the * deck holds it rather than as the word that was typed, because the interesting part of a pitch * setting is what it means next to the speed — `:lock` on a ×½ record is a sentence about both. */it("moves the key, in semitones, and says the key the record is being heard in", () => { expect(syncRun("key").outcome.text).toBe("the record's own key"); expect(syncRun("key 3").outcome.text).toBe("key +3st"); expect(player().peekKey()).toBe(3); expect(syncRun("key -5").outcome.text).toBe("key \u22125st"); expect(player().peekKey()).toBe(-5);
// A word for a step moves from where we stand; a number or a word for an interval names the place // itself — `:key octave` is "an octave up from where the record was written", not "one more octave // from wherever the last verb left the deck", which is the reading that lets a script say the same // thing twice and land in the same key. expect(syncRun("key up").outcome.text).toBe("key \u22124st"); expect(syncRun("key octave").outcome.text).toBe("key +12st"); expect(player().peekKey()).toBe(12);
// The ends of the travel are the shifter's, and the line says the number that is in force rather // than the one that was asked for: a verb that reported +40 while holding +24 would be a line // that lies about what somebody is about to hear. expect(syncRun("key 40").outcome.text).toBe("key +24st"); expect(syncRun("key off").outcome.text).toBe("the record's own key"); expect(syncRun("key nonsense").outcome.bad).toBe(true); expect(syncRun("key nonsense").outcome.text).toContain(":key");});
it("takes the lock, and says what the lock is holding", () => { // A bare verb decides rather than reports: on a two-state thing the word is the decision, and the // answer is the state the decision left behind. Off is where the deck starts, so the first press // takes the lock rather than releasing it. expect(syncRun("lock").outcome.text).toContain("lock on"); expect(player().peekLocked()).toBe(true); expect(syncRun("lock").outcome.text).toContain("lock off"); expect(player().peekLocked()).toBe(false); expect(syncRun("lock on").outcome.text).toContain("lock on"); expect(syncRun("lock off").outcome.text).toContain("lock off"); expect(syncRun("lock nonsense").outcome.bad).toBe(true);
// With a speed on the deck the answer becomes a sentence about both, which is the only way to tell // somebody what the lock is actually doing for them right now — and at ×1 it says so plainly, which // is the same honesty the readout in the bar keeps. player().setSpeed(0.5); expect(syncRun("lock on").outcome.text).toContain("\u00d70.5"); // A whole octave is the friendly case. The one that proves the arithmetic is 80 %, where the // correction is 12·log₂(1.25) semitones and the line has to state it rather than round it away. expect(syncRun("lock on").outcome.text).toContain("+12st of correction"); player().setSpeed(0.8); expect(syncRun("lock on").outcome.text).toContain("+3.9st of correction"); player().setSpeed(1); expect(syncRun("lock on").outcome.text).toContain("nothing to hold yet");});
it("chooses how the pitch is moved, and puts it back", () => { expect(syncRun("shift").outcome.text).toContain("balanced"); expect(syncRun("shift smooth").outcome.text).toBe("shift smooth"); expect(player().peekShiftQuality()).toBe("smooth"); expect(syncRun("shift crisp").outcome.text).toBe("shift crisp"); expect(syncRun("shift ethereal").outcome.bad).toBe(true); expect(syncRun("shift ethereal").outcome.text).toContain("crisp, balanced, smooth");
// `off` is not a tuning; it is the pitch put back where the record was written — the whole state, // because the state is one decision and the listener who types it has finished with the experiment. player().setKey(7); player().setLock(true); player().setSpeed(2); expect(syncRun("shift off").outcome.text).toBe("the record as written"); expect(player().peekKey()).toBe(0); expect(player().peekLocked()).toBe(false); expect(player().peekSpeed()).toBe(1);});
it("keeps the speed and the pitch two verbs, and gives each its own words", () => { // The alias `:pitch` used to mean the octave, because there was nothing else. Now there is, and // the two verbs cannot both answer to it: `:pitch` is the one a listener means for the key. expect(findCommand("pitch")).toBe(findCommand("key")); expect(findCommand("varispeed")).toBe(findCommand("speed")); expect(findCommand("tempo")).toBe(findCommand("speed")); expect(findCommand("transpose")).toBe(findCommand("key")); expect(syncRun("pitch 2").outcome.text).toBe("key +2st"); expect(player().peekKey()).toBe(2);
// The speed answers to a percent, a multiple, a step and a bare report — all four because all four // are what a person types when they want a record a bit slower. expect(syncRun("speed 80").outcome.text).toContain("\u00d70.8"); expect(player().peekSpeed()).toBe(0.8); expect(syncRun("speed 0.8").outcome.text).toContain("\u00d70.8"); expect(player().peekSpeed()).toBe(0.8); expect(syncRun("speed down").outcome.text).toContain("\u00d70.7"); expect(syncRun("speed").outcome.text).toContain("\u00d70.7"); expect(syncRun("speed nonsense").outcome.bad).toBe(true); // ...and none of it touched the pitch: two verbs, two things, still — the key the line above set is // the key that is still in force after five presses at the speed. expect(player().peekKey()).toBe(2);
// `:octave` is the snap it always was, now that it is not also the whole speed control: from 70 % // "an octave up" lands on the record at its own speed, because that is the next named speed up. expect(syncRun("octave up").outcome.text).toContain("octave off"); expect(player().peekSpeed()).toBe(1); expect(syncRun("octave down").outcome.text).toContain("\u00d70.5"); expect(syncRun("octave nonsense").outcome.bad).toBe(true);});
describe(":lyricsaudit", () => { /** * The verb that raises the ladder's account of itself. * * What is checked is the line it answers with and the table it raises — the two halves of the same * promise: the command line says the verdict, the modal is the argument for it. */ const tags = { trackName: "Partners For Life ft. Pharrell Williams & Jamie Foxx", artistName: "The Neptunes", albumName: "The Other Side Of The Planet (Disc 12)", duration: 272, };
beforeEach(() => { setLadderAuditEnabled(true); clearLadderAudits(); });
afterEach(() => { setLadderAuditEnabled(true); clearLadderAudits(); });
it("refuses politely before anything has been asked", () => { const said = syncRun("lyricsaudit"); expect(said.outcome.bad).toBe(true); expect(said.outcome.text).toContain("nothing asked of lrclib yet"); });
it("raises the table for the track on the bar and says the verdict in a line", () => { const audit = beginLadder("tr-1", tags, 0)!; recordRung(audit, { n: 1, name: "the signature", endpoint: "/api/get", asked: { track_name: tags.trackName }, at: 0, ms: 40, status: "none", hits: 0, timed: 0, vetoed: [], }); recordRung(audit, { n: 3, name: "the title without its credit", endpoint: "/api/search", asked: { track_name: "Partners For Life", duration: "272" }, at: 45, ms: 30, status: "records", hits: 2, timed: 2, ceiling: 3, vetoed: [ { id: 9212306, trackName: "Partners For Life", artistName: "Jeff Beal", offSeconds: 112, timed: true, why: "length", }, ], }); endLadder(audit, 80, "none", { says: "2 timed records, none within 3s" });
const said = syncRun("lyricsaudit"); expect(said.outcome.bad).toBe(false); expect(said.outcome.text).toContain("2 questions in 80ms"); expect(said.outcome.text).toContain("none within 3s"); // ...and the table is up, showing the same attempt the line summarised. expect(ladderAuditModal()?.subject).toBe("tr-1"); });
it("addresses an attempt by number, newest first, and refuses one that is not there", () => { // Oldest first, because the list is newest-first and the verb counts from the front of it: `2` // is the attempt before the one the bar is about. recordUnasked("tr-old", tags, "none", 0); recordUnasked("tr-new", tags, "none", 0); expect(syncRun("lyricsaudit 2").outcome.bad).toBe(false); expect(ladderAuditModal()?.subject).toBe("tr-old"); expect(syncRun("lyricsaudit 3").outcome.bad).toBe(true); expect(syncRun("lyricsaudit nine").outcome.bad).toBe(true); });
it("switches the recording off without losing what it already saw", () => { recordUnasked("tr-1", tags, "none", 0); expect(syncRun("lyricsaudit off").outcome.text).toContain("stopped writing it down"); expect(ladderAuditEnabled()).toBe(false); // The table can still be raised over what was already recorded — a switch that wiped the // evidence would make the tool useless for the thing it is opened for. expect(syncRun("lyricsaudit").outcome.bad).toBe(false); expect(syncRun("lyricsaudit on").outcome.text).toContain("again"); });
it("forgets everything when it is told to", () => { recordUnasked("tr-1", tags, "none", 0); showLadderAudit(); expect(syncRun("lyricsaudit clear").outcome.text).toContain("forgot"); expect(ladderAudits()).toHaveLength(0); expect(ladderAuditModal()).toBeNull(); });});
describe(":lyrics", () => { afterEach(() => { // Persisted, in-memory as the truth, and one verb away from making every later test in the file // listen without a lyric — the same care the theme mode above gets. lyrics().setEnabled(true); lyrics().reset(); resetLrclib(null); });
it("reports the setting and what the host said, and takes neither on faith", () => { // A bare verb *reports* here, where `:lock` and `:theme` decide: the column on screen is the // readout of the setting, so a press that flipped it would answer the wrong question — the one // a person is asking when they type the word at all. expect(syncRun("lyrics").outcome.text).toContain("lyrics on"); expect(syncRun("lyrics off").outcome.text).toContain("lyrics off"); expect(lyrics().peekEnabled()).toBe(false); expect(syncRun("lyrics").outcome.text).toContain("nothing is asked of lrclib"); expect(syncRun("lyrics on").outcome.text).toContain("lyrics on"); expect(lyrics().peekEnabled()).toBe(true); expect(syncRun("lyrics sideways").outcome.bad).toBe(true); expect(syncRun("lyrics sideways").outcome.text).toContain("sideways"); });
it("says how many lines it has, and says so in the words the bar has room for", async () => { resetLrclib( new LrclibClient({ fetch: lrclibFetch({ get: () => foundRecord({ id: 1, trackName: "Drowned", artistName: "Madonna", syncedLyrics: "[00:04.00] Drowned, drowned, drowned", }), }).fetch as (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>, gapMs: 0, wait: async () => {}, }), ); lyrics().lookUp({ id: "tr-1", title: "Drowned", artist: "Madonna", duration: 263, source: "navidrome", }); await vi.waitFor(() => expect(lyrics().peekCurrent()?.status).toBe("found")); // Singular, because the line is read aloud in the head and "1 synced lines" is not. expect(syncRun("lyrics").outcome.text).toBe("lyrics on \u00b7 1 synced line \u00b7 lrclib"); });
it("says so when there is nothing to say, and does not blame the host for it", () => { // The distinction the whole feature turns on: a track LRCLIB has never heard of and a host that // did not answer are different facts, and only one of them is worth asking about again. lyrics().lookUp(null); expect(syncRun("lyrics").outcome.text).toContain("nothing on the bar to ask about"); });});