|
| 1 | +// altimate_change - new file |
| 2 | +// |
| 3 | +// The link pickers open on a listed workspace that already has the name a quick |
| 4 | +// create would use, instead of on "create", so a second workspace with the same name |
| 5 | +// takes a deliberate choice. |
| 6 | +import { describe, expect, test } from "bun:test" |
| 7 | +import { sameNamedWorkspace } from "../../../src/altimate/workspace/workspace-name" |
| 8 | + |
| 9 | +const ws = (id: number, name: string) => ({ id, name }) |
| 10 | + |
| 11 | +describe("sameNamedWorkspace", () => { |
| 12 | + test.each([ |
| 13 | + ["exact name", [ws(1, "analytics")], "analytics", 1], |
| 14 | + ["case differs", [ws(1, "Analytics")], "analytics", 1], |
| 15 | + ["surrounding and inner whitespace differ", [ws(1, " data platform ")], "data platform", 1], |
| 16 | + ["a control character in the listed name", [ws(1, "analy\u0007tics")], "analy tics", 1], |
| 17 | + ["no workspace has the name", [ws(1, "marketing"), ws(2, "finance")], "analytics", undefined], |
| 18 | + ["a longer name that only starts the same", [ws(1, "analytics-prod")], "analytics", undefined], |
| 19 | + ["the first of two namesakes wins", [ws(3, "analytics"), ws(4, "ANALYTICS")], "analytics", 3], |
| 20 | + ["an empty proposed name matches nothing", [ws(1, "")], " ", undefined], |
| 21 | + ["an empty list", [], "analytics", undefined], |
| 22 | + ] as const)("%s", (_label, list, proposed, expected) => { |
| 23 | + expect(sameNamedWorkspace(list, proposed)?.id).toBe(expected) |
| 24 | + }) |
| 25 | + |
| 26 | + test("returns the listed object itself, so callers keep its id and display name", () => { |
| 27 | + const listed = ws(7, "Analytics") |
| 28 | + expect(sameNamedWorkspace([ws(1, "other"), listed], "analytics")).toBe(listed) |
| 29 | + }) |
| 30 | +}) |
0 commit comments