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/https", () => {
8 it("resolves HTTPS URI to same URL", async () => {
9 const resolved = await testWeb(async () => {
10 const HttpsInput = await import("~/components/input/https/element.js");
11 const input = new HttpsInput.CLASS();
12 document.body.append(input);
13
14 return await input.resolve({
15 uri: "https://example.com/audio.mp3",
16 });
17 });
18
19 if (resolved && "url" in resolved) {
20 expect(resolved.url).toBe("https://example.com/audio.mp3");
21 expect(resolved.expiresAt).toBeGreaterThan(Date.now() / 1000);
22 }
23 });
24
25 it("provides sources list from tracks", async () => {
26 const sources = await testWeb(async () => {
27 const HttpsInput = await import("~/components/input/https/element.js");
28 const input = new HttpsInput.CLASS();
29 document.body.append(input);
30
31 const tracks: Track[] = [
32 {
33 $type: "sh.diffuse.output.track",
34 id: "1",
35 uri: "https://example.com/a.mp3",
36 },
37 {
38 $type: "sh.diffuse.output.track",
39 id: "2",
40 uri: "https://cdn.example.com/b.mp3",
41 },
42 ];
43
44 return input.sources(tracks);
45 });
46
47 expect(sources.length).toBe(2);
48 expect(sources[0].label).toBeDefined();
49 expect(sources[0].uri).toContain("https://");
50 expect(sources[1].label).toBeDefined();
51 expect(sources[1].uri).toContain("https://");
52 });
53
54 it("consult returns undetermined for scheme only", async () => {
55 const result = await testWeb(async () => {
56 const HttpsInput = await import("~/components/input/https/element.js");
57 const input = new HttpsInput.CLASS();
58 document.body.append(input);
59
60 return await input.consult("https");
61 });
62
63 expect(result.supported).toBe(true);
64 if (result.supported) {
65 expect(result.consult).toBe("undetermined");
66 }
67 });
68
69 it("detaches all HTTPS tracks when given scheme", async () => {
70 const remaining = await testWeb(async () => {
71 const HttpsInput = await import("~/components/input/https/element.js");
72 const input = new HttpsInput.CLASS();
73 document.body.append(input);
74
75 const tracks: Track[] = [
76 {
77 $type: "sh.diffuse.output.track",
78 id: "1",
79 uri: "https://example.com/a.mp3",
80 },
81 {
82 $type: "sh.diffuse.output.track",
83 id: "2",
84 uri: "https://example.com/c.mp3",
85 },
86 ];
87
88 return await input.detach({
89 fileUriOrScheme: "https",
90 tracks,
91 });
92 });
93
94 expect(remaining.length).toBe(0);
95 });
96
97 it("detaches tracks from specific domain", async () => {
98 const remaining = await testWeb(async () => {
99 const HttpsInput = await import("~/components/input/https/element.js");
100 const input = new HttpsInput.CLASS();
101 document.body.append(input);
102
103 const tracks: Track[] = [
104 {
105 $type: "sh.diffuse.output.track",
106 id: "1",
107 uri: "https://example.com/a.mp3",
108 },
109 {
110 $type: "sh.diffuse.output.track",
111 id: "2",
112 uri: "https://cdn.example.com/b.mp3",
113 },
114 {
115 $type: "sh.diffuse.output.track",
116 id: "3",
117 uri: "https://example.com/c.mp3",
118 },
119 {
120 $type: "sh.diffuse.output.track",
121 id: "4",
122 uri: "https://cdn.example.com/d.mp3",
123 },
124 ];
125
126 return await input.detach({
127 fileUriOrScheme: "https://example.com",
128 tracks,
129 });
130 });
131
132 expect(remaining.length).toBe(2);
133 expect(remaining[0].id).toBe("2");
134 expect(remaining[1].id).toBe("4");
135 });
136
137 it("has correct SCHEME property", async () => {
138 const scheme = await testWeb(async () => {
139 const HttpsInput = await import("~/components/input/https/element.js");
140 const input = new HttpsInput.CLASS();
141 document.body.append(input);
142
143 return input.SCHEME;
144 });
145
146 expect(scheme).toBe("https");
147 });
148});