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: output components tests

+389
+128
tests/components/output/bytes/s3/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 + 6 + describe("components/output/bytes/s3", () => { 7 + it("ready returns false when no bucket is configured", async () => { 8 + const result = await testWeb(async () => { 9 + const mod = await import("~/components/output/bytes/s3/element.js"); 10 + const output = new mod.CLASS(); 11 + document.body.append(output); 12 + return output.ready(); 13 + }); 14 + 15 + expect(result).toBe(false); 16 + }); 17 + 18 + it("bucket returns undefined initially", async () => { 19 + const result = await testWeb(async () => { 20 + const mod = await import("~/components/output/bytes/s3/element.js"); 21 + const output = new mod.CLASS(); 22 + document.body.append(output); 23 + return output.bucket() ?? null; 24 + }); 25 + 26 + expect(result).toBe(null); 27 + }); 28 + 29 + it("getBucket returns undefined when no bucket is stored", async () => { 30 + const result = await testWeb(async () => { 31 + const mod = await import("~/components/output/bytes/s3/element.js"); 32 + const output = new mod.CLASS(); 33 + document.body.append(output); 34 + return (await output.getBucket()) ?? null; 35 + }); 36 + 37 + expect(result).toBe(null); 38 + }); 39 + 40 + it("setBucket updates the bucket signal", async () => { 41 + const result = await testWeb(async () => { 42 + const mod = await import("~/components/output/bytes/s3/element.js"); 43 + const output = new mod.CLASS(); 44 + document.body.append(output); 45 + 46 + await output.setBucket({ 47 + accessKey: "myKey", 48 + secretKey: "mySecret", 49 + host: "s3.amazonaws.com", 50 + bucketName: "my-bucket", 51 + path: "/", 52 + region: "us-east-1", 53 + }); 54 + 55 + return output.bucket(); 56 + }); 57 + 58 + expect(result?.bucketName).toBe("my-bucket"); 59 + expect(result?.accessKey).toBe("myKey"); 60 + }); 61 + 62 + it("ready returns true after setBucket when online", async () => { 63 + const result = await testWeb(async () => { 64 + const mod = await import("~/components/output/bytes/s3/element.js"); 65 + const output = new mod.CLASS(); 66 + document.body.append(output); 67 + 68 + await output.setBucket({ 69 + accessKey: "myKey", 70 + secretKey: "mySecret", 71 + host: "s3.amazonaws.com", 72 + bucketName: "my-bucket", 73 + path: "/", 74 + region: "us-east-1", 75 + }); 76 + 77 + // ready = bucket !== undefined && isOnline 78 + // isOnline follows navigator.onLine which is true in headless Chromium 79 + return output.ready(); 80 + }); 81 + 82 + expect(result).toBe(true); 83 + }); 84 + 85 + it("unsetBucket clears the bucket signal", async () => { 86 + const result = await testWeb(async () => { 87 + const mod = await import("~/components/output/bytes/s3/element.js"); 88 + const output = new mod.CLASS(); 89 + document.body.append(output); 90 + 91 + await output.setBucket({ 92 + accessKey: "myKey", 93 + secretKey: "mySecret", 94 + host: "s3.amazonaws.com", 95 + bucketName: "my-bucket", 96 + path: "/", 97 + region: "us-east-1", 98 + }); 99 + 100 + await output.unsetBucket(); 101 + return output.bucket() ?? null; 102 + }); 103 + 104 + expect(result).toBe(null); 105 + }); 106 + 107 + it("ready returns false after unsetBucket", async () => { 108 + const result = await testWeb(async () => { 109 + const mod = await import("~/components/output/bytes/s3/element.js"); 110 + const output = new mod.CLASS(); 111 + document.body.append(output); 112 + 113 + await output.setBucket({ 114 + accessKey: "myKey", 115 + secretKey: "mySecret", 116 + host: "s3.amazonaws.com", 117 + bucketName: "my-bucket", 118 + path: "/", 119 + region: "us-east-1", 120 + }); 121 + 122 + await output.unsetBucket(); 123 + return output.ready(); 124 + }); 125 + 126 + expect(result).toBe(false); 127 + }); 128 + });
+176
tests/components/output/polymorphic/indexed-db/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 type { Facet, Track } from "~/definitions/types.d.ts"; 6 + 7 + describe("components/output/polymorphic/indexed-db", () => { 8 + it("ready returns true immediately", async () => { 9 + const result = await testWeb(async () => { 10 + const mod = await import( 11 + "~/components/output/polymorphic/indexed-db/element.js" 12 + ); 13 + const output = new mod.CLASS(); 14 + document.body.append(output); 15 + return output.ready(); 16 + }); 17 + 18 + expect(result).toBe(true); 19 + }); 20 + 21 + it("tracks.collection is loading before any save", async () => { 22 + const result = await testWeb(async () => { 23 + const mod = await import( 24 + "~/components/output/polymorphic/indexed-db/element.js" 25 + ); 26 + const output = new mod.CLASS(); 27 + document.body.append(output); 28 + return output.tracks.collection().state; 29 + }); 30 + 31 + expect(result).toBe("loading"); 32 + }); 33 + 34 + it("tracks.collection returns loaded state after save", async () => { 35 + const result = await testWeb(async () => { 36 + const mod = await import( 37 + "~/components/output/polymorphic/indexed-db/element.js" 38 + ); 39 + const output = new mod.CLASS(); 40 + document.body.append(output); 41 + 42 + const tracks: Track[] = [ 43 + { 44 + $type: "sh.diffuse.output.track", 45 + id: "t1", 46 + uri: "https://example.com/track1.mp3", 47 + }, 48 + ]; 49 + 50 + await output.tracks.save(tracks); 51 + return output.tracks.collection(); 52 + }); 53 + 54 + expect(result.state).toBe("loaded"); 55 + if (result.state === "loaded") { 56 + expect(result.data).toHaveLength(1); 57 + } 58 + }); 59 + 60 + it("tracks.save persists data and collection returns it", async () => { 61 + const result = await testWeb(async () => { 62 + const mod = await import( 63 + "~/components/output/polymorphic/indexed-db/element.js" 64 + ); 65 + const output = new mod.CLASS(); 66 + document.body.append(output); 67 + 68 + const tracks: Track[] = [ 69 + { 70 + $type: "sh.diffuse.output.track", 71 + id: "track-a", 72 + uri: "https://example.com/a.mp3", 73 + }, 74 + { 75 + $type: "sh.diffuse.output.track", 76 + id: "track-b", 77 + uri: "https://example.com/b.mp3", 78 + }, 79 + ]; 80 + 81 + await output.tracks.save(tracks); 82 + const col = output.tracks.collection(); 83 + if (col.state !== "loaded") return []; 84 + return (col.data as Track[]).map((t: Track) => t.id); 85 + }); 86 + 87 + expect(result).toEqual(["track-a", "track-b"]); 88 + }); 89 + 90 + it("facets.collection returns loaded state after save", async () => { 91 + const result = await testWeb(async () => { 92 + const mod = await import( 93 + "~/components/output/polymorphic/indexed-db/element.js" 94 + ); 95 + const output = new mod.CLASS(); 96 + document.body.append(output); 97 + 98 + const facets: Facet[] = [ 99 + { 100 + $type: "sh.diffuse.output.facet", 101 + id: "f1", 102 + name: "Favourites", 103 + }, 104 + ]; 105 + 106 + await output.facets.save(facets); 107 + return output.facets.collection(); 108 + }); 109 + 110 + expect(result.state).toBe("loaded"); 111 + }); 112 + 113 + it("playlistItems.collection returns loaded state after save", async () => { 114 + const result = await testWeb(async () => { 115 + const mod = await import( 116 + "~/components/output/polymorphic/indexed-db/element.js" 117 + ); 118 + const output = new mod.CLASS(); 119 + document.body.append(output); 120 + 121 + await output.playlistItems.save([]); 122 + return output.playlistItems.collection(); 123 + }); 124 + 125 + expect(result.state).toBe("loaded"); 126 + }); 127 + 128 + it("saving empty tracks array results in empty loaded collection", async () => { 129 + const result = await testWeb(async () => { 130 + const mod = await import( 131 + "~/components/output/polymorphic/indexed-db/element.js" 132 + ); 133 + const output = new mod.CLASS(); 134 + document.body.append(output); 135 + 136 + await output.tracks.save([]); 137 + const col = output.tracks.collection(); 138 + if (col.state !== "loaded") return null; 139 + return (col.data as Track[]).length; 140 + }); 141 + 142 + expect(result).toBe(0); 143 + }); 144 + 145 + it("save overwrites previous data", async () => { 146 + const result = await testWeb(async () => { 147 + const mod = await import( 148 + "~/components/output/polymorphic/indexed-db/element.js" 149 + ); 150 + const output = new mod.CLASS(); 151 + document.body.append(output); 152 + 153 + await output.tracks.save([ 154 + { 155 + $type: "sh.diffuse.output.track" as const, 156 + id: "first", 157 + uri: "https://example.com/first.mp3", 158 + }, 159 + ]); 160 + 161 + await output.tracks.save([ 162 + { 163 + $type: "sh.diffuse.output.track" as const, 164 + id: "second", 165 + uri: "https://example.com/second.mp3", 166 + }, 167 + ]); 168 + 169 + const col = output.tracks.collection(); 170 + if (col.state !== "loaded") return []; 171 + return (col.data as Track[]).map((t: Track) => t.id); 172 + }); 173 + 174 + expect(result).toEqual(["second"]); 175 + }); 176 + });
+85
tests/components/output/raw/atproto/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 + 6 + describe("components/output/raw/atproto", () => { 7 + it("did returns null when not authenticated", async () => { 8 + const result = await testWeb(async () => { 9 + const mod = await import("~/components/output/raw/atproto/element.js"); 10 + const output = new mod.CLASS(); 11 + document.body.append(output); 12 + return output.did() ?? null; 13 + }); 14 + 15 + expect(result).toBe(null); 16 + }); 17 + 18 + it("rev returns null when not authenticated", async () => { 19 + const result = await testWeb(async () => { 20 + const mod = await import("~/components/output/raw/atproto/element.js"); 21 + const output = new mod.CLASS(); 22 + document.body.append(output); 23 + return output.rev() ?? null; 24 + }); 25 + 26 + expect(result).toBe(null); 27 + }); 28 + 29 + it("ready returns false when not authenticated", async () => { 30 + const result = await testWeb(async () => { 31 + const mod = await import("~/components/output/raw/atproto/element.js"); 32 + const output = new mod.CLASS(); 33 + document.body.append(output); 34 + return output.ready(); 35 + }); 36 + 37 + expect(result).toBe(false); 38 + }); 39 + 40 + it("listRecords returns empty array when not authenticated", async () => { 41 + const result = await testWeb(async () => { 42 + const mod = await import("~/components/output/raw/atproto/element.js"); 43 + const output = new mod.CLASS(); 44 + document.body.append(output); 45 + return output.listRecords("sh.diffuse.output.facet"); 46 + }); 47 + 48 + expect(result).toEqual([]); 49 + }); 50 + 51 + it("getLatestCommit returns null when not authenticated", async () => { 52 + const result = await testWeb(async () => { 53 + const mod = await import("~/components/output/raw/atproto/element.js"); 54 + const output = new mod.CLASS(); 55 + document.body.append(output); 56 + return output.getLatestCommit(); 57 + }); 58 + 59 + expect(result).toBe(null); 60 + }); 61 + 62 + it("putRecords resolves without throwing when not authenticated", async () => { 63 + const result = await testWeb(async () => { 64 + const mod = await import("~/components/output/raw/atproto/element.js"); 65 + const output = new mod.CLASS(); 66 + document.body.append(output); 67 + 68 + await output.putRecords("sh.diffuse.output.facet", []); 69 + return true; 70 + }); 71 + 72 + expect(result).toBe(true); 73 + }); 74 + 75 + it("tracks.collection is loading initially", async () => { 76 + const result = await testWeb(async () => { 77 + const mod = await import("~/components/output/raw/atproto/element.js"); 78 + const output = new mod.CLASS(); 79 + document.body.append(output); 80 + return output.tracks.collection().state; 81 + }); 82 + 83 + expect(result).toBe("loading"); 84 + }); 85 + });