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.

at v4 152 lines 4.7 kB view raw
1import { describe, it } from "@std/testing/bdd"; 2import { expect } from "@std/expect"; 3 4import { testWeb } from "@tests/common/index.ts"; 5import type { Track } from "~/definitions/types.d.ts"; 6 7describe("components/input/local", () => { 8 it("has correct SCHEME property", async () => { 9 const scheme = await testWeb(async () => { 10 const mod = await import("~/components/input/local/element.js"); 11 const input = new mod.CLASS(); 12 document.body.append(input); 13 return input.SCHEME; 14 }); 15 16 expect(scheme).toBe("local"); 17 }); 18 19 it("consult returns unsupported for an unknown TID URI", async () => { 20 const result = await testWeb(async () => { 21 const mod = await import("~/components/input/local/element.js"); 22 const input = new mod.CLASS(); 23 document.body.append(input); 24 return await input.consult("local://unknown-tid-abc123/"); 25 }); 26 27 // Either no browser support or unknown handle — both return supported: false 28 expect(result.supported).toBe(false); 29 }); 30 31 it("listCached returns empty array initially", async () => { 32 const result = await testWeb(async () => { 33 const mod = await import("~/components/input/local/element.js"); 34 const input = new mod.CLASS(); 35 document.body.append(input); 36 return await input.list([]); 37 }); 38 39 expect(result).toEqual([]); 40 }); 41 42 it("detach with local scheme removes all local tracks", async () => { 43 const remaining = await testWeb(async () => { 44 const mod = await import("~/components/input/local/element.js"); 45 const input = new mod.CLASS(); 46 document.body.append(input); 47 48 const tracks: Track[] = [ 49 { 50 $type: "sh.diffuse.output.track", 51 id: "1", 52 uri: "local://tid-aaa/track1.mp3", 53 }, 54 { 55 $type: "sh.diffuse.output.track", 56 id: "2", 57 uri: "local://tid-bbb/track2.mp3", 58 }, 59 ]; 60 61 return await input.detach({ fileUriOrScheme: "local", tracks }); 62 }); 63 64 expect(remaining.length).toBe(0); 65 }); 66 67 it("detach with non-matching scheme returns all tracks", async () => { 68 const remaining = await testWeb(async () => { 69 const mod = await import("~/components/input/local/element.js"); 70 const input = new mod.CLASS(); 71 document.body.append(input); 72 73 const tracks: Track[] = [ 74 { 75 $type: "sh.diffuse.output.track", 76 id: "1", 77 uri: "local://tid-aaa/track1.mp3", 78 }, 79 ]; 80 81 return await input.detach({ fileUriOrScheme: "https", tracks }); 82 }); 83 84 expect(remaining.length).toBe(1); 85 }); 86 87 it("detach with a non-local URI returns all tracks unchanged", async () => { 88 const remaining = await testWeb(async () => { 89 const mod = await import("~/components/input/local/element.js"); 90 const input = new mod.CLASS(); 91 document.body.append(input); 92 93 const tracks: Track[] = [ 94 { 95 $type: "sh.diffuse.output.track", 96 id: "1", 97 uri: "local://tid-aaa/track1.mp3", 98 }, 99 { 100 $type: "sh.diffuse.output.track", 101 id: "2", 102 uri: "local://tid-bbb/track2.mp3", 103 }, 104 ]; 105 106 return await input.detach({ 107 fileUriOrScheme: "icecast://some-host/stream", 108 tracks, 109 }); 110 }); 111 112 // fileUriOrScheme has "://" but scheme doesn't match "local" → tracks unchanged 113 expect(remaining.length).toBe(2); 114 }); 115 116 it("resolve returns undefined for an unknown TID", async () => { 117 const result = await testWeb(async () => { 118 const mod = await import("~/components/input/local/element.js"); 119 const input = new mod.CLASS(); 120 document.body.append(input); 121 const r = await input.resolve({ uri: "local://unknown-tid/track.mp3" }); 122 return r ?? null; 123 }); 124 125 expect(result).toBe(null); 126 }); 127 128 it("artwork returns null", async () => { 129 const result = await testWeb(async () => { 130 const mod = await import("~/components/input/local/element.js"); 131 const input = new mod.CLASS(); 132 document.body.append(input); 133 return await input.artwork("local://tid-aaa/track.mp3"); 134 }); 135 136 expect(result).toBe(null); 137 }); 138 139 it("groupConsult returns empty object for unknown TIDs", async () => { 140 const result = await testWeb(async () => { 141 const mod = await import("~/components/input/local/element.js"); 142 const input = new mod.CLASS(); 143 document.body.append(input); 144 return await input.groupConsult([ 145 "local://tid-unknown-1/track.mp3", 146 "local://tid-unknown-2/song.flac", 147 ]); 148 }); 149 150 expect(Object.keys(result).length).toBe(0); 151 }); 152});