73 lines
3.0 KiB
TypeScript
73 lines
3.0 KiB
TypeScript
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
|||
|
|
import { startTestServer, createBoard, join, type TestServer } from "./helpers.js";
|
||
|
|
|
||
|
|
let server: TestServer;
|
||
|
|
beforeAll(async () => {
|
||
|
|
server = await startTestServer();
|
||
|
|
});
|
||
|
|
afterAll(async () => {
|
||
|
|
await server.close();
|
||
|
|
});
|
||
|
|
|
||
|
|
describe("Columnas y color", () => {
|
||
|
|
it("recolorear cambia el color de TODAS mis notas", async () => {
|
||
|
|
const board = await createBoard(server.url);
|
||
|
|
const alice = await join(server.url, board.boardId, "alice", "Alice");
|
||
|
|
const colId = alice.last!.columns[0].id;
|
||
|
|
alice.emit("note:add", { columnId: colId, text: "a", color: "#ffe08a" });
|
||
|
|
alice.emit("note:add", { columnId: colId, text: "b", color: "#ffe08a" });
|
||
|
|
await alice.waitFor((s) => s.notes.length === 2);
|
||
|
|
|
||
|
|
alice.emit("note:recolorMine", { color: "#b9ddf5" });
|
||
|
|
const recolored = await alice.waitFor((s) => s.notes.every((n) => n.color === "#b9ddf5"));
|
||
|
|
expect(recolored.notes.map((n) => n.color)).toEqual(["#b9ddf5", "#b9ddf5"]);
|
||
|
|
|
||
|
|
alice.close();
|
||
|
|
});
|
||
|
|
|
||
|
|
it("añadir, renombrar, reordenar y eliminar columnas (moderador)", async () => {
|
||
|
|
const board = await createBoard(server.url); // mad-sad-glad => 3 columnas
|
||
|
|
const alice = await join(server.url, board.boardId, "alice", "Alice");
|
||
|
|
const tok = board.moderatorToken;
|
||
|
|
|
||
|
|
// añadir
|
||
|
|
alice.emit("column:add", { title: "Extra", moderatorToken: tok });
|
||
|
|
let st = await alice.waitFor((s) => s.columns.length === 4);
|
||
|
|
const extra = st.columns.find((c) => c.title === "Extra")!;
|
||
|
|
expect(extra).toBeTruthy();
|
||
|
|
|
||
|
|
// renombrar
|
||
|
|
alice.emit("column:rename", { columnId: extra.id, title: "Renombrada", moderatorToken: tok });
|
||
|
|
st = await alice.waitFor((s) => s.columns.some((c) => c.id === extra.id && c.title === "Renombrada"));
|
||
|
|
expect(st.columns.find((c) => c.id === extra.id)!.title).toBe("Renombrada");
|
||
|
|
|
||
|
|
// reordenar: poner la última primera
|
||
|
|
const ids = st.columns.map((c) => c.id);
|
||
|
|
const reordered = [ids[ids.length - 1], ...ids.slice(0, -1)];
|
||
|
|
alice.emit("column:reorder", { orderedIds: reordered, moderatorToken: tok });
|
||
|
|
st = await alice.waitFor((s) => s.columns[0].id === reordered[0]);
|
||
|
|
expect(st.columns.map((c) => c.id)).toEqual(reordered);
|
||
|
|
|
||
|
|
// eliminar
|
||
|
|
alice.emit("column:delete", { columnId: extra.id, moderatorToken: tok });
|
||
|
|
st = await alice.waitFor((s) => s.columns.length === 3);
|
||
|
|
expect(st.columns.some((c) => c.id === extra.id)).toBe(false);
|
||
|
|
|
||
|
|
alice.close();
|
||
|
|
});
|
||
|
|
|
||
|
|
it("la fase se comparte (board:phase)", async () => {
|
||
|
|
const board = await createBoard(server.url);
|
||
|
|
const alice = await join(server.url, board.boardId, "alice", "Alice");
|
||
|
|
const bob = await join(server.url, board.boardId, "bob", "Bob");
|
||
|
|
expect(alice.last!.phase).toBe("writing");
|
||
|
|
|
||
|
|
alice.emit("board:phase", { phase: "voting", moderatorToken: board.moderatorToken });
|
||
|
|
const bobState = await bob.waitFor((s) => s.phase === "voting");
|
||
|
|
expect(bobState.phase).toBe("voting");
|
||
|
|
|
||
|
|
alice.close();
|
||
|
|
bob.close();
|
||
|
|
});
|
||
|
|
});
|