import { moveItem, wrapSelection } from "./cvBuilder"; describe("moveItem", () => { test("moves an item forward", () => { expect(moveItem(["a", "b", "c"], 0, 2)).toEqual(["b", "c", "a"]); }); test("moves an item backward", () => { expect(moveItem(["a", "b", "c"], 2, 0)).toEqual(["c", "a", "b"]); }); test("no-op for equal or out-of-range indices", () => { const a = ["a", "b"]; expect(moveItem(a, 1, 1)).toBe(a); expect(moveItem(a, 5, 0)).toBe(a); expect(moveItem(a, 0, -1)).toBe(a); }); test("does not mutate the input", () => { const a = ["a", "b", "c"]; moveItem(a, 0, 2); expect(a).toEqual(["a", "b", "c"]); }); }); describe("wrapSelection", () => { test("wraps a selection and keeps the selection over the inner text", () => { const r = wrapSelection("hello world", 6, 11, "**", "**"); expect(r.text).toBe("hello **world**"); expect(r.text.slice(r.selStart, r.selEnd)).toBe("world"); }); test("inserts a placeholder when nothing is selected", () => { const r = wrapSelection("", 0, 0, "**", "**", "bold text"); expect(r.text).toBe("**bold text**"); expect(r.text.slice(r.selStart, r.selEnd)).toBe("bold text"); }); test("wraps a link with a url suffix", () => { const r = wrapSelection("see docs", 4, 8, "[", "](https://)"); expect(r.text).toBe("see [docs](https://)"); expect(r.text.slice(r.selStart, r.selEnd)).toBe("docs"); }); });