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 165 lines 4.8 kB view raw
1import { describe, it } from "@std/testing/bdd"; 2import { expect } from "@std/expect"; 3 4import { testWeb } from "@tests/common/index.ts"; 5 6describe("components/transformer/output/bytes/json", () => { 7 it("ready returns false when no output is connected", async () => { 8 const result = await testWeb(async () => { 9 const mod = await import( 10 "~/components/transformer/output/bytes/json/element.js" 11 ); 12 const t = new mod.CLASS(); 13 return t.ready(); 14 }); 15 16 expect(result).toBe(false); 17 }); 18 19 it("tracks.collection is loading when no output is connected", async () => { 20 const result = await testWeb(async () => { 21 const mod = await import( 22 "~/components/transformer/output/bytes/json/element.js" 23 ); 24 const t = new mod.CLASS(); 25 return t.tracks.collection().state; 26 }); 27 28 expect(result).toBe("loading"); 29 }); 30 31 it("tracks save and collection round-trip", async () => { 32 const result = await testWeb(async () => { 33 const idbMod = await import( 34 "~/components/output/polymorphic/indexed-db/element.js" 35 ); 36 const mod = await import( 37 "~/components/transformer/output/bytes/json/element.js" 38 ); 39 40 const output = new idbMod.CLASS(); 41 output.id = "test-idb"; 42 document.body.append(output); 43 44 const t = new mod.CLASS(); 45 t.setAttribute("output-selector", "#test-idb"); 46 document.body.append(t); 47 48 await t.tracks.save([ 49 { 50 $type: "sh.diffuse.output.track", 51 id: "track-1", 52 uri: "https://example.com/track1.mp3", 53 }, 54 { 55 $type: "sh.diffuse.output.track", 56 id: "track-2", 57 uri: "https://example.com/track2.mp3", 58 }, 59 ]); 60 61 const col = t.tracks.collection(); 62 if (col.state !== "loaded") return null; 63 return (col.data as Array<{ id: string }>).map((tr) => tr.id); 64 }); 65 66 expect(result).toEqual(["track-1", "track-2"]); 67 }); 68 69 it("facets save and collection round-trip", async () => { 70 const result = await testWeb(async () => { 71 const idbMod = await import( 72 "~/components/output/polymorphic/indexed-db/element.js" 73 ); 74 const mod = await import( 75 "~/components/transformer/output/bytes/json/element.js" 76 ); 77 78 const output = new idbMod.CLASS(); 79 output.id = "test-idb-facets"; 80 document.body.append(output); 81 82 const t = new mod.CLASS(); 83 t.setAttribute("output-selector", "#test-idb-facets"); 84 document.body.append(t); 85 86 await t.facets.save([ 87 { 88 $type: "sh.diffuse.output.facet", 89 id: "f1", 90 name: "Favourites", 91 }, 92 ]); 93 94 const col = t.facets.collection(); 95 if (col.state !== "loaded") return null; 96 return (col.data as Array<{ id: string; name: string }>).map((f) => ({ 97 id: f.id, 98 name: f.name, 99 })); 100 }); 101 102 expect(result).toEqual([{ id: "f1", name: "Favourites" }]); 103 }); 104 105 it("settings save and collection round-trip", async () => { 106 const result = await testWeb(async () => { 107 const idbMod = await import( 108 "~/components/output/polymorphic/indexed-db/element.js" 109 ); 110 const mod = await import( 111 "~/components/transformer/output/bytes/json/element.js" 112 ); 113 114 const output = new idbMod.CLASS(); 115 output.id = "test-idb-settings"; 116 document.body.append(output); 117 118 const t = new mod.CLASS(); 119 t.setAttribute("output-selector", "#test-idb-settings"); 120 document.body.append(t); 121 122 await t.settings.save([ 123 { 124 $type: "sh.diffuse.output.setting", 125 id: "s1", 126 key: "sh.diffuse.input.disabled.uris", 127 value: "", 128 }, 129 ]); 130 131 const col = t.settings.collection(); 132 if (col.state !== "loaded") return null; 133 return (col.data as Array<{ id: string }>).map((s) => s.id); 134 }); 135 136 expect(result).toEqual(["s1"]); 137 }); 138 139 it("saving empty array results in empty loaded collection", async () => { 140 const result = await testWeb(async () => { 141 const idbMod = await import( 142 "~/components/output/polymorphic/indexed-db/element.js" 143 ); 144 const mod = await import( 145 "~/components/transformer/output/bytes/json/element.js" 146 ); 147 148 const output = new idbMod.CLASS(); 149 output.id = "test-idb-empty"; 150 document.body.append(output); 151 152 const t = new mod.CLASS(); 153 t.setAttribute("output-selector", "#test-idb-empty"); 154 document.body.append(t); 155 156 await t.tracks.save([]); 157 158 const col = t.tracks.collection(); 159 if (col.state !== "loaded") return null; 160 return (col.data as unknown[]).length; 161 }); 162 163 expect(result).toBe(0); 164 }); 165});