-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcolumns.test.ts
More file actions
69 lines (58 loc) · 2.26 KB
/
Copy pathcolumns.test.ts
File metadata and controls
69 lines (58 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { describe, expect, it } from "vitest";
import {
clampColumnWidth,
COLUMN_BOUNDS,
formatColumnWidth,
nextColumnWidth,
parseColumnWidth,
} from "./columns";
describe("clampColumnWidth", () => {
it("clamps below the minimum for each side", () => {
expect(clampColumnWidth("left", 0)).toBe(COLUMN_BOUNDS.left.min);
expect(clampColumnWidth("right", 0)).toBe(COLUMN_BOUNDS.right.min);
});
it("clamps above the maximum for each side", () => {
expect(clampColumnWidth("left", 9999)).toBe(COLUMN_BOUNDS.left.max);
expect(clampColumnWidth("right", 9999)).toBe(COLUMN_BOUNDS.right.max);
});
it("rounds a value within range", () => {
const within = COLUMN_BOUNDS.left.min + 10.6;
expect(clampColumnWidth("left", within)).toBe(Math.round(within));
});
});
describe("nextColumnWidth", () => {
it("grows the left column as the pointer moves right", () => {
const start = COLUMN_BOUNDS.left.min + 40;
expect(nextColumnWidth("left", start, 30)).toBe(start + 30);
expect(nextColumnWidth("left", start, -30)).toBe(start - 30);
});
it("grows the right column as the pointer moves left", () => {
const start = COLUMN_BOUNDS.right.min + 40;
expect(nextColumnWidth("right", start, -30)).toBe(start + 30);
expect(nextColumnWidth("right", start, 30)).toBe(start - 30);
});
it("clamps the result to the side bounds", () => {
expect(nextColumnWidth("left", COLUMN_BOUNDS.left.max, 100)).toBe(COLUMN_BOUNDS.left.max);
expect(nextColumnWidth("right", COLUMN_BOUNDS.right.min, 100)).toBe(COLUMN_BOUNDS.right.min);
});
});
describe("parseColumnWidth", () => {
it("parses pixel and bare numeric strings", () => {
expect(parseColumnWidth("300px")).toBe(300);
expect(parseColumnWidth("300")).toBe(300);
});
it("returns null for non-positive or unparseable values", () => {
expect(parseColumnWidth("")).toBeNull();
expect(parseColumnWidth("abc")).toBeNull();
expect(parseColumnWidth("0px")).toBeNull();
expect(parseColumnWidth("-40px")).toBeNull();
});
});
describe("formatColumnWidth", () => {
it("appends the px unit", () => {
expect(formatColumnWidth(300)).toBe("300px");
});
it("round-trips with parseColumnWidth", () => {
expect(parseColumnWidth(formatColumnWidth(360))).toBe(360);
});
});