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 178 lines 5.5 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/configurator/output", () => { 7 it("selected is null initially", async () => { 8 const result = await testWeb(async () => { 9 const mod = await import( 10 "~/components/configurator/output/element.js" 11 ); 12 const configurator = new mod.CLASS(); 13 document.body.append(configurator); 14 return configurator.selected(); 15 }); 16 17 expect(result).toBe(null); 18 }); 19 20 it("activated is empty initially", async () => { 21 const result = await testWeb(async () => { 22 const mod = await import( 23 "~/components/configurator/output/element.js" 24 ); 25 const configurator = new mod.CLASS(); 26 document.body.append(configurator); 27 return Array.from(configurator.activated()); 28 }); 29 30 expect(result).toEqual([]); 31 }); 32 33 it("hasSelected returns false when nothing is stored in localStorage", async () => { 34 const result = await testWeb(async () => { 35 const mod = await import( 36 "~/components/configurator/output/element.js" 37 ); 38 const configurator = new mod.CLASS(); 39 document.body.append(configurator); 40 return configurator.hasSelected(); 41 }); 42 43 expect(result).toBe(false); 44 }); 45 46 it("hasDefault returns false without a default attribute", async () => { 47 const result = await testWeb(async () => { 48 const mod = await import( 49 "~/components/configurator/output/element.js" 50 ); 51 const configurator = new mod.CLASS(); 52 document.body.append(configurator); 53 return configurator.hasDefault(); 54 }); 55 56 expect(result).toBe(false); 57 }); 58 59 it("hasDefault returns true when the default attribute is set", async () => { 60 const result = await testWeb(async () => { 61 const mod = await import( 62 "~/components/configurator/output/element.js" 63 ); 64 const configurator = new mod.CLASS(); 65 configurator.setAttribute("default", "my-output"); 66 document.body.append(configurator); 67 return configurator.hasDefault(); 68 }); 69 70 expect(result).toBe(true); 71 }); 72 73 it("select persists the id to localStorage", async () => { 74 const stored = await testWeb(async () => { 75 const mod = await import( 76 "~/components/configurator/output/element.js" 77 ); 78 const configurator = new mod.CLASS(); 79 document.body.append(configurator); 80 await configurator.select("my-output"); 81 return localStorage.getItem("diffuse/configurator/output/selected/id"); 82 }); 83 84 expect(stored).toBe("my-output"); 85 }); 86 87 it("hasSelected returns true after select", async () => { 88 const result = await testWeb(async () => { 89 const mod = await import( 90 "~/components/configurator/output/element.js" 91 ); 92 const configurator = new mod.CLASS(); 93 document.body.append(configurator); 94 await configurator.select("my-output"); 95 return configurator.hasSelected(); 96 }); 97 98 expect(result).toBe(true); 99 }); 100 101 it("activated includes id after select", async () => { 102 const result = await testWeb(async () => { 103 const mod = await import( 104 "~/components/configurator/output/element.js" 105 ); 106 const configurator = new mod.CLASS(); 107 document.body.append(configurator); 108 await configurator.select("my-output"); 109 return Array.from(configurator.activated()); 110 }); 111 112 expect(result).toContain("my-output"); 113 }); 114 115 it("deselect removes the id from localStorage", async () => { 116 const stored = await testWeb(async () => { 117 const mod = await import( 118 "~/components/configurator/output/element.js" 119 ); 120 const configurator = new mod.CLASS(); 121 document.body.append(configurator); 122 await configurator.select("my-output"); 123 await configurator.deselect(); 124 return localStorage.getItem("diffuse/configurator/output/selected/id"); 125 }); 126 127 expect(stored).toBe(null); 128 }); 129 130 it("hasSelected returns false after deselect", async () => { 131 const result = await testWeb(async () => { 132 const mod = await import( 133 "~/components/configurator/output/element.js" 134 ); 135 const configurator = new mod.CLASS(); 136 document.body.append(configurator); 137 await configurator.select("my-output"); 138 await configurator.deselect(); 139 return configurator.hasSelected(); 140 }); 141 142 expect(result).toBe(false); 143 }); 144 145 it("options lists child elements by id and label", async () => { 146 const result = await testWeb(async () => { 147 const mod = await import( 148 "~/components/configurator/output/element.js" 149 ); 150 const configurator = new mod.CLASS(); 151 152 const child = document.createElement("div"); 153 child.id = "output-a"; 154 child.setAttribute("label", "Output A"); 155 configurator.appendChild(child); 156 157 document.body.append(configurator); 158 159 const opts = await configurator.options(); 160 return opts.map((o) => ({ id: o.id, label: o.label })); 161 }); 162 163 expect(result).toEqual([{ id: "output-a", label: "Output A" }]); 164 }); 165 166 it("options returns an empty array when there are no children", async () => { 167 const result = await testWeb(async () => { 168 const mod = await import( 169 "~/components/configurator/output/element.js" 170 ); 171 const configurator = new mod.CLASS(); 172 document.body.append(configurator); 173 return configurator.options(); 174 }); 175 176 expect(result).toEqual([]); 177 }); 178});