-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetPsuedoEditableEssentialStyles.test.ts
More file actions
118 lines (101 loc) · 3.63 KB
/
getPsuedoEditableEssentialStyles.test.ts
File metadata and controls
118 lines (101 loc) · 3.63 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { getPsuedoEditableEssentialStyles } from "../getPsuedoEditableEssentialStyles";
describe("getPsuedoEditableEssentialStyles", () => {
const mockRect: DOMRect = {
top: 50,
left: 30,
width: 200,
height: 100,
bottom: 150,
right: 230,
x: 30,
y: 50,
toJSON: () => ({}),
};
const mockScrollX = 100;
const mockScrollY = 200;
beforeEach(() => {
// Mock window.scrollX and window.scrollY using vitest spies
vi.spyOn(window, "scrollX", "get").mockReturnValue(mockScrollX);
vi.spyOn(window, "scrollY", "get").mockReturnValue(mockScrollY);
});
afterEach(() => {
vi.restoreAllMocks();
});
test("returns styles with kebab-case properties when camelCase is false", () => {
const result = getPsuedoEditableEssentialStyles({
rect: mockRect,
camelCase: false,
});
expect(result).toEqual({
position: "absolute",
top: `${mockRect.top + mockScrollY}px`,
left: `${mockRect.left + mockScrollX}px`,
height: "auto",
"min-height": `${Math.abs(mockRect.height)}px`,
"white-space": "normal",
"text-transform": "none",
"text-wrap-mode": "wrap",
"text-overflow": "visible",
});
});
test("returns styles with kebab-case properties when camelCase is undefined", () => {
const result = getPsuedoEditableEssentialStyles({
rect: mockRect,
camelCase: undefined,
});
expect(result).toEqual({
position: "absolute",
top: `${mockRect.top + mockScrollY}px`,
left: `${mockRect.left + mockScrollX}px`,
height: "auto",
"min-height": `${Math.abs(mockRect.height)}px`,
"white-space": "normal",
"text-transform": "none",
"text-wrap-mode": "wrap",
"text-overflow": "visible",
});
});
test("returns styles with camelCase properties when camelCase is true", () => {
const result = getPsuedoEditableEssentialStyles({
rect: mockRect,
camelCase: true,
});
expect(result).toEqual({
position: "absolute",
top: `${mockRect.top + mockScrollY}px`,
left: `${mockRect.left + mockScrollX}px`,
height: "auto",
minHeight: `${Math.abs(mockRect.height)}px`,
whiteSpace: "normal",
textTransform: "none",
textWrapMode: "wrap",
textOverflow: "visible",
});
});
test("calculates correct positioning with scroll offset", () => {
const customScrollX = 50;
const customScrollY = 150;
// Override the default mock values for this test
vi.spyOn(window, "scrollX", "get").mockReturnValue(customScrollX);
vi.spyOn(window, "scrollY", "get").mockReturnValue(customScrollY);
const result = getPsuedoEditableEssentialStyles({
rect: mockRect,
camelCase: false,
});
expect(result.top).toBe(`${mockRect.top + customScrollY}px`);
expect(result.left).toBe(`${mockRect.left + customScrollX}px`);
});
test("handles negative rect heights correctly", () => {
const negativeHeightRect: DOMRect = {
...mockRect,
height: -50,
};
const result = getPsuedoEditableEssentialStyles({
rect: negativeHeightRect,
camelCase: false,
});
expect(result["min-height"]).toBe(
`${Math.abs(negativeHeightRect.height)}px`
);
});
});