A music player that connects to your cloud/distributed storage.
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/opensubsonic", () => {
8 it("has correct SCHEME property", async () => {
9 const scheme = await testWeb(async () => {
10 const mod = await import("~/components/input/opensubsonic/element.js");
11 const input = new mod.CLASS();
12 document.body.append(input);
13 return input.SCHEME;
14 });
15
16 expect(scheme).toBe("opensubsonic");
17 });
18
19 it("consult returns undetermined for scheme only", async () => {
20 const result = await testWeb(async () => {
21 const mod = await import("~/components/input/opensubsonic/element.js");
22 const input = new mod.CLASS();
23 document.body.append(input);
24 return await input.consult("opensubsonic");
25 });
26
27 expect(result.supported).toBe(true);
28 if (result.supported) {
29 expect(result.consult).toBe("undetermined");
30 }
31 });
32
33 it("consult returns undetermined for a full URI (defers to network check)", async () => {
34 const result = await testWeb(async () => {
35 const mod = await import("~/components/input/opensubsonic/element.js");
36 const input = new mod.CLASS();
37 document.body.append(input);
38 return await input.consult(
39 "opensubsonic://user:pass@localhost:4040?tls=0",
40 );
41 });
42
43 // consultServerCached will fail to reach the server and return false
44 expect(result.supported).toBe(true);
45 });
46
47 it("detach with opensubsonic scheme removes all opensubsonic tracks", async () => {
48 const remaining = await testWeb(async () => {
49 const mod = await import("~/components/input/opensubsonic/element.js");
50 const input = new mod.CLASS();
51 document.body.append(input);
52
53 const tracks: Track[] = [
54 {
55 $type: "sh.diffuse.output.track",
56 id: "1",
57 uri: "opensubsonic://user:pass@subsonic.example.com?tls=t",
58 },
59 {
60 $type: "sh.diffuse.output.track",
61 id: "2",
62 uri: "opensubsonic://user:pass@other.example.com?tls=t",
63 },
64 ];
65
66 return await input.detach({ fileUriOrScheme: "opensubsonic", tracks });
67 });
68
69 expect(remaining.length).toBe(0);
70 });
71
72 it("detach with non-matching scheme returns all tracks", async () => {
73 const remaining = await testWeb(async () => {
74 const mod = await import("~/components/input/opensubsonic/element.js");
75 const input = new mod.CLASS();
76 document.body.append(input);
77
78 const tracks: Track[] = [
79 {
80 $type: "sh.diffuse.output.track",
81 id: "1",
82 uri: "opensubsonic://user:pass@subsonic.example.com?tls=t",
83 },
84 ];
85
86 return await input.detach({ fileUriOrScheme: "https", tracks });
87 });
88
89 expect(remaining.length).toBe(1);
90 });
91
92 it("artwork returns null", async () => {
93 const result = await testWeb(async () => {
94 const mod = await import("~/components/input/opensubsonic/element.js");
95 const input = new mod.CLASS();
96 document.body.append(input);
97 return await input.artwork(
98 "opensubsonic://user:pass@subsonic.example.com?songId=123&tls=t",
99 );
100 });
101
102 expect(result).toBe(null);
103 });
104
105 it("detach with specific server URI removes only matching tracks", async () => {
106 const remaining = await testWeb(async () => {
107 const mod = await import("~/components/input/opensubsonic/element.js");
108 const input = new mod.CLASS();
109 document.body.append(input);
110
111 const tracks: Track[] = [
112 {
113 $type: "sh.diffuse.output.track",
114 id: "1",
115 uri: "opensubsonic://user:pass@server-a.example.com?tls=t",
116 },
117 {
118 $type: "sh.diffuse.output.track",
119 id: "2",
120 uri: "opensubsonic://user:pass@server-b.example.com?tls=t",
121 },
122 ];
123
124 return await input.detach({
125 fileUriOrScheme:
126 "opensubsonic://user:pass@server-a.example.com?tls=t",
127 tracks,
128 });
129 });
130
131 expect(remaining.length).toBe(1);
132 expect(remaining[0].id).toBe("2");
133 });
134});