Spaces:
Sleeping
Sleeping
Download dashboard/tests/studio_layout.test.js from JuanCS-Dev/twitch-byte-bot: direct link, hf CLI and curl.
- Browser
- Download file 2.41 kB
-
https://huggingface.co/spaces/JuanCS-Dev/twitch-byte-bot/resolve/main/dashboard/tests/studio_layout.test.js
- Command line
-
hf download hf://spaces/JuanCS-Dev/twitch-byte-bot/dashboard/tests/studio_layout.test.js
-
curl -L -o studio_layout.test.js https://huggingface.co/spaces/JuanCS-Dev/twitch-byte-bot/resolve/main/dashboard/tests/studio_layout.test.js
2.41 kB
| import assert from "node:assert/strict"; | |
| import test from "node:test"; | |
| import { | |
| DENSITIES, | |
| TILE_IDS, | |
| defaultLayout, | |
| moveTile, | |
| normalizeLayout, | |
| parseLayout, | |
| profileLayout, | |
| serializeLayout, | |
| toggleHidden, | |
| } from "../features/studio/layout.js"; | |
| test("defaultLayout lists all tiles, none hidden, comfortable", () => { | |
| const d = defaultLayout(); | |
| assert.deepEqual(d.order, TILE_IDS); | |
| assert.deepEqual(d.hidden, []); | |
| assert.equal(d.density, "comfortable"); | |
| }); | |
| test("normalizeLayout drops unknown ids and appends missing ones", () => { | |
| const norm = normalizeLayout({ | |
| order: ["tileHype", "ghost", "tilePause"], | |
| hidden: ["tileClips", "ghost"], | |
| density: "weird", | |
| }); | |
| // unknown dropped, kept order first, then the rest appended | |
| assert.equal(norm.order[0], "tileHype"); | |
| assert.equal(norm.order[1], "tilePause"); | |
| assert.equal(norm.order.length, TILE_IDS.length); | |
| assert.deepEqual(new Set(norm.order), new Set(TILE_IDS)); | |
| assert.deepEqual(norm.hidden, ["tileClips"]); | |
| assert.ok(DENSITIES.includes(norm.density)); | |
| }); | |
| test("serialize/parse round-trips and parse guards corrupt input", () => { | |
| const layout = toggleHidden(moveTile(defaultLayout(), "tileRecap", -1), "tileClips"); | |
| assert.deepEqual(parseLayout(serializeLayout(layout)), layout); | |
| assert.deepEqual(parseLayout("not json"), defaultLayout()); | |
| assert.deepEqual(parseLayout("{}"), defaultLayout()); | |
| }); | |
| test("moveTile swaps neighbors and is a no-op at the edges", () => { | |
| const d = defaultLayout(); | |
| const moved = moveTile(d, "tileSpeak", -1); // index 1 -> 0 | |
| assert.equal(moved.order[0], "tileSpeak"); | |
| assert.deepEqual(moveTile(d, TILE_IDS[0], -1).order, d.order); // top can't go up | |
| assert.deepEqual(moveTile(d, TILE_IDS[TILE_IDS.length - 1], 1).order, d.order); | |
| // immutability: source untouched | |
| assert.equal(d.order[0], TILE_IDS[0]); | |
| }); | |
| test("toggleHidden adds then removes", () => { | |
| const once = toggleHidden(defaultLayout(), "tileVision"); | |
| assert.deepEqual(once.hidden, ["tileVision"]); | |
| assert.deepEqual(toggleHidden(once, "tileVision").hidden, []); | |
| }); | |
| test("profiles are valid normalized layouts", () => { | |
| for (const name of ["full", "fps", "chatting"]) { | |
| const p = profileLayout(name); | |
| assert.deepEqual(new Set(p.order), new Set(TILE_IDS)); | |
| assert.ok(DENSITIES.includes(p.density)); | |
| } | |
| assert.deepEqual(profileLayout("nope"), defaultLayout()); | |
| }); | |