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 216 lines 7.0 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/engine/scope", () => { 7 it("has default sortBy of ['createdAt']", async () => { 8 const result = await testWeb(async () => { 9 const mod = await import("~/components/engine/scope/element.js"); 10 const engine = new mod.CLASS(); 11 document.body.append(engine); 12 return engine.sortBy(); 13 }); 14 15 expect(result).toEqual(["createdAt"]); 16 }); 17 18 it("has default sortDirection of 'desc'", async () => { 19 const result = await testWeb(async () => { 20 const mod = await import("~/components/engine/scope/element.js"); 21 const engine = new mod.CLASS(); 22 document.body.append(engine); 23 return engine.sortDirection(); 24 }); 25 26 expect(result).toBe("desc"); 27 }); 28 29 it("has default groupBy of undefined", async () => { 30 const result = await testWeb(async () => { 31 const mod = await import("~/components/engine/scope/element.js"); 32 const engine = new mod.CLASS(); 33 document.body.append(engine); 34 return engine.groupBy() ?? null; 35 }); 36 37 expect(result).toBe(null); 38 }); 39 40 it("has default playlist of undefined", async () => { 41 const result = await testWeb(async () => { 42 const mod = await import("~/components/engine/scope/element.js"); 43 const engine = new mod.CLASS(); 44 document.body.append(engine); 45 return engine.playlist() ?? null; 46 }); 47 48 expect(result).toBe(null); 49 }); 50 51 it("has default searchTerm of undefined", async () => { 52 const result = await testWeb(async () => { 53 const mod = await import("~/components/engine/scope/element.js"); 54 const engine = new mod.CLASS(); 55 document.body.append(engine); 56 return engine.searchTerm() ?? null; 57 }); 58 59 expect(result).toBe(null); 60 }); 61 62 it("setGroupBy updates groupBy", async () => { 63 const result = await testWeb(async () => { 64 const mod = await import("~/components/engine/scope/element.js"); 65 const engine = new mod.CLASS(); 66 document.body.append(engine); 67 await engine.setGroupBy("artist"); 68 return engine.groupBy(); 69 }); 70 71 expect(result).toBe("artist"); 72 }); 73 74 it("setGroupBy with undefined clears groupBy", async () => { 75 const result = await testWeb(async () => { 76 const mod = await import("~/components/engine/scope/element.js"); 77 const engine = new mod.CLASS(); 78 document.body.append(engine); 79 await engine.setGroupBy("artist"); 80 await engine.setGroupBy(undefined); 81 return engine.groupBy() ?? null; 82 }); 83 84 expect(result).toBe(null); 85 }); 86 87 it("setPlaylist updates playlist", async () => { 88 const result = await testWeb(async () => { 89 const mod = await import("~/components/engine/scope/element.js"); 90 const engine = new mod.CLASS(); 91 document.body.append(engine); 92 await engine.setPlaylist("playlist-123"); 93 return engine.playlist(); 94 }); 95 96 expect(result).toBe("playlist-123"); 97 }); 98 99 it("setSearchTerm updates searchTerm", async () => { 100 const result = await testWeb(async () => { 101 const mod = await import("~/components/engine/scope/element.js"); 102 const engine = new mod.CLASS(); 103 document.body.append(engine); 104 await engine.setSearchTerm("hello world"); 105 return engine.searchTerm(); 106 }); 107 108 expect(result).toBe("hello world"); 109 }); 110 111 it("setSortBy updates sortBy", async () => { 112 const result = await testWeb(async () => { 113 const mod = await import("~/components/engine/scope/element.js"); 114 const engine = new mod.CLASS(); 115 document.body.append(engine); 116 await engine.setSortBy(["title", "artist"]); 117 return engine.sortBy(); 118 }); 119 120 expect(result).toEqual(["title", "artist"]); 121 }); 122 123 it("setSortDirection updates sortDirection", async () => { 124 const result = await testWeb(async () => { 125 const mod = await import("~/components/engine/scope/element.js"); 126 const engine = new mod.CLASS(); 127 document.body.append(engine); 128 await engine.setSortDirection("asc"); 129 return engine.sortDirection(); 130 }); 131 132 expect(result).toBe("asc"); 133 }); 134 135 it("revertToDefaultSort resets sortBy and sortDirection", async () => { 136 const result = await testWeb(async () => { 137 const mod = await import("~/components/engine/scope/element.js"); 138 const engine = new mod.CLASS(); 139 document.body.append(engine); 140 await engine.setSortBy(["title"]); 141 await engine.setSortDirection("asc"); 142 await engine.revertToDefaultSort(); 143 return { sortBy: engine.sortBy(), sortDirection: engine.sortDirection() }; 144 }); 145 146 expect(result.sortBy).toEqual(["createdAt"]); 147 expect(result.sortDirection).toBe("desc"); 148 }); 149 150 it("persists groupBy to localStorage", async () => { 151 const stored = await testWeb(async () => { 152 const mod = await import("~/components/engine/scope/element.js"); 153 const engine = new mod.CLASS(); 154 document.body.append(engine); 155 await engine.setGroupBy("album"); 156 157 for (let i = 0; i < localStorage.length; i++) { 158 const key = localStorage.key(i)!; 159 if (key.includes("scope") && key.endsWith("/groupBy")) { 160 return localStorage.getItem(key); 161 } 162 } 163 return null; 164 }); 165 166 expect(stored).toBe("album"); 167 }); 168 169 it("persists sortBy to localStorage as JSON", async () => { 170 const stored = await testWeb(async () => { 171 const mod = await import("~/components/engine/scope/element.js"); 172 const engine = new mod.CLASS(); 173 document.body.append(engine); 174 await engine.setSortBy(["title", "artist"]); 175 176 for (let i = 0; i < localStorage.length; i++) { 177 const key = localStorage.key(i)!; 178 if (key.includes("scope") && key.endsWith("/sortBy")) { 179 return localStorage.getItem(key); 180 } 181 } 182 return null; 183 }); 184 185 expect(stored).toBe('["title","artist"]'); 186 }); 187 188 it("restores values from localStorage on connect", async () => { 189 const result = await testWeb(async () => { 190 const mod = await import("~/components/engine/scope/element.js"); 191 192 // Set state with first engine instance 193 const engine1 = new mod.CLASS(); 194 document.body.append(engine1); 195 await engine1.setGroupBy("artist"); 196 await engine1.setSearchTerm("test"); 197 await engine1.setSortBy(["title"]); 198 await engine1.setSortDirection("asc"); 199 200 // Second instance reads same localStorage keys 201 const engine2 = new mod.CLASS(); 202 document.body.append(engine2); 203 return { 204 groupBy: engine2.groupBy(), 205 searchTerm: engine2.searchTerm(), 206 sortBy: engine2.sortBy(), 207 sortDirection: engine2.sortDirection(), 208 }; 209 }); 210 211 expect(result.groupBy).toBe("artist"); 212 expect(result.searchTerm).toBe("test"); 213 expect(result.sortBy).toEqual(["title"]); 214 expect(result.sortDirection).toBe("asc"); 215 }); 216});