A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: some scoped-tracks tests re search

+211
+211
tests/components/orchestrator/scoped-tracks/test.ts
··· 1 + import { describe, it } from "@std/testing/bdd"; 2 + import { expect } from "@std/expect"; 3 + 4 + import { testWeb } from "@tests/common/index.ts"; 5 + import { trackA, trackB, tracks } from "~/testing/sample/tracks.js"; 6 + 7 + describe("components/orchestrator/scoped-tracks", () => { 8 + it("finds tracks by album", async () => { 9 + const results = await testWeb(async () => { 10 + const { supply, search } = await import( 11 + "~/components/orchestrator/scoped-tracks/worker.js" 12 + ); 13 + const { tracks } = await import("~/testing/sample/tracks.js"); 14 + 15 + await supply({ tracks }); 16 + return search({ term: tracks[1]?.tags?.album }); 17 + }); 18 + 19 + expect(results[0]?.id).toBe(trackB.id); 20 + }); 21 + 22 + it("finds tracks by artist", async () => { 23 + const results = await testWeb(async () => { 24 + const { supply, search } = await import( 25 + "~/components/orchestrator/scoped-tracks/worker.js" 26 + ); 27 + const { tracks } = await import("~/testing/sample/tracks.js"); 28 + 29 + await supply({ tracks }); 30 + return search({ term: tracks[0]?.tags?.artist }); 31 + }); 32 + 33 + expect(results[0]?.id).toBe(trackA.id); 34 + }); 35 + 36 + it("finds tracks by title", async () => { 37 + const results = await testWeb(async () => { 38 + const { supply, search } = await import( 39 + "~/components/orchestrator/scoped-tracks/worker.js" 40 + ); 41 + const { tracks } = await import("~/testing/sample/tracks.js"); 42 + 43 + await supply({ tracks }); 44 + return search({ term: tracks[1]?.tags?.title }); 45 + }); 46 + 47 + expect(results[0]?.id).toBe(trackB.id); 48 + }); 49 + 50 + it("returns empty array when no tracks match the search term", async () => { 51 + const results = await testWeb(async () => { 52 + const { supply, search } = await import( 53 + "~/components/orchestrator/scoped-tracks/worker.js" 54 + ); 55 + const { tracks } = await import("~/testing/sample/tracks.js"); 56 + 57 + await supply({ tracks }); 58 + return search({ term: "zzz-no-match-zzz" }); 59 + }); 60 + 61 + expect(results).toEqual([]); 62 + }); 63 + 64 + it("supplyFingerprint is undefined before first supply", async () => { 65 + const fp = await testWeb(async () => { 66 + const { $supplyFingerprint } = await import( 67 + "~/components/orchestrator/scoped-tracks/worker.js" 68 + ); 69 + 70 + return $supplyFingerprint.value ?? null; 71 + }); 72 + 73 + expect(fp).toBe(null); 74 + }); 75 + 76 + it("supplyFingerprint is set after supply", async () => { 77 + const fp = await testWeb(async () => { 78 + const { supply, $supplyFingerprint } = await import( 79 + "~/components/orchestrator/scoped-tracks/worker.js" 80 + ); 81 + const { tracks } = await import("~/testing/sample/tracks.js"); 82 + 83 + await supply({ tracks }); 84 + return $supplyFingerprint.value ?? null; 85 + }); 86 + 87 + expect(fp).not.toBe(null); 88 + expect(typeof fp).toBe("string"); 89 + }); 90 + 91 + it("supply with same tracks does not change the fingerprint", async () => { 92 + const [fp1, fp2] = await testWeb(async () => { 93 + const { supply, $supplyFingerprint } = await import( 94 + "~/components/orchestrator/scoped-tracks/worker.js" 95 + ); 96 + const { tracks } = await import("~/testing/sample/tracks.js"); 97 + 98 + await supply({ tracks }); 99 + const fp1 = $supplyFingerprint.value; 100 + 101 + await supply({ tracks }); 102 + const fp2 = $supplyFingerprint.value; 103 + 104 + return [fp1, fp2]; 105 + }); 106 + 107 + expect(fp1).toBe(fp2); 108 + }); 109 + 110 + it("supply removes tracks no longer in the list", async () => { 111 + const results = await testWeb(async () => { 112 + const { supply, search } = await import( 113 + "~/components/orchestrator/scoped-tracks/worker.js" 114 + ); 115 + const { trackA, trackB } = await import("~/testing/sample/tracks.js"); 116 + 117 + await supply({ tracks: [trackA, trackB] }); 118 + await supply({ tracks: [trackB] }); 119 + 120 + return search({ term: "Artist" }); 121 + }); 122 + 123 + expect(results).toEqual([]); 124 + }); 125 + 126 + it("supply with empty list clears all tracks from the index", async () => { 127 + const results = await testWeb(async () => { 128 + const { supply, search } = await import( 129 + "~/components/orchestrator/scoped-tracks/worker.js" 130 + ); 131 + const { tracks } = await import("~/testing/sample/tracks.js"); 132 + 133 + await supply({ tracks }); 134 + await supply({ tracks: [] }); 135 + 136 + return search({ term: "Sample" }); 137 + }); 138 + 139 + expect(results).toEqual([]); 140 + }); 141 + 142 + it("sorts results by artist alphabetically", async () => { 143 + const ids = await testWeb(async () => { 144 + const { supply, search } = await import( 145 + "~/components/orchestrator/scoped-tracks/worker.js" 146 + ); 147 + 148 + const testTracks = [ 149 + { 150 + $type: "sh.diffuse.output.track" as const, 151 + id: "sort-zebra", 152 + uri: "diffuse://sort-zebra", 153 + tags: { artist: "Zebra", title: "Sort Test" }, 154 + }, 155 + { 156 + $type: "sh.diffuse.output.track" as const, 157 + id: "sort-apple", 158 + uri: "diffuse://sort-apple", 159 + tags: { artist: "Apple", title: "Sort Test" }, 160 + }, 161 + { 162 + $type: "sh.diffuse.output.track" as const, 163 + id: "sort-mango", 164 + uri: "diffuse://sort-mango", 165 + tags: { artist: "Mango", title: "Sort Test" }, 166 + }, 167 + ]; 168 + 169 + await supply({ tracks: testTracks }); 170 + const results = await search({ term: "Sort Test" }); 171 + return results.map((t) => t.id); 172 + }); 173 + 174 + expect(ids).toEqual(["sort-apple", "sort-mango", "sort-zebra"]); 175 + }); 176 + 177 + it("sorts results by track number within the same album", async () => { 178 + const ids = await testWeb(async () => { 179 + const { supply, search } = await import( 180 + "~/components/orchestrator/scoped-tracks/worker.js" 181 + ); 182 + 183 + const testTracks = [ 184 + { 185 + $type: "sh.diffuse.output.track" as const, 186 + id: "track-03", 187 + uri: "diffuse://track-03", 188 + tags: { artist: "Band", album: "Album", track: { no: 3 }, title: "C" }, 189 + }, 190 + { 191 + $type: "sh.diffuse.output.track" as const, 192 + id: "track-01", 193 + uri: "diffuse://track-01", 194 + tags: { artist: "Band", album: "Album", track: { no: 1 }, title: "A" }, 195 + }, 196 + { 197 + $type: "sh.diffuse.output.track" as const, 198 + id: "track-02", 199 + uri: "diffuse://track-02", 200 + tags: { artist: "Band", album: "Album", track: { no: 2 }, title: "B" }, 201 + }, 202 + ]; 203 + 204 + await supply({ tracks: testTracks }); 205 + const results = await search({ term: "Band" }); 206 + return results.map((t) => t.id); 207 + }); 208 + 209 + expect(ids).toEqual(["track-01", "track-02", "track-03"]); 210 + }); 211 + });