@olenbetong/synergi-react 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/Checkbox/index.js +1 -9
- package/es/components/CodeEditor/CodeEditor.css +6 -6
- package/es/components/FilePond.js +3 -12
- package/es/components/ImageEditor/plugins/redactPlugin/useRedactTool.js +18 -14
- package/es/components/ImageEditor/useImageHistory.js +13 -1
- package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +1 -1
- package/es/components/MergeProgressDialog/useMergeJob.js +5 -4
- package/es/components/Portal/index.js +20 -20
- package/es/components/SplitContainer/index.js +3 -1
- package/es/components/Toolbar/Toolbar.css +137 -137
- package/es/components/Toolbar/index.js +6 -1
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +8 -0
- package/es/elements/ElementLookupDialog/HIDScanner/useHIDScanner.js +3 -1
- package/es/elements-ds/DescriptionInput.d.ts +16 -0
- package/es/elements-ds/DescriptionInput.js +41 -0
- package/es/elements-ds/DuplicateElementDamage.d.ts +40 -0
- package/es/elements-ds/DuplicateElementDamage.js +57 -0
- package/es/elements-ds/ElementLookup.d.ts +23 -0
- package/es/elements-ds/ElementLookup.js +35 -0
- package/es/elements-ds/ElementLookupDialog.d.ts +7 -0
- package/es/elements-ds/ElementLookupDialog.js +84 -0
- package/es/elements-ds/FormFields.d.ts +43 -0
- package/es/elements-ds/FormFields.js +67 -0
- package/es/elements-ds/HIDScanner.d.ts +7 -0
- package/es/elements-ds/HIDScanner.js +36 -0
- package/es/elements-ds/ManualForm.d.ts +7 -0
- package/es/elements-ds/ManualForm.js +70 -0
- package/es/elements-ds/ProjectSelect.d.ts +28 -0
- package/es/elements-ds/ProjectSelect.js +45 -0
- package/es/elements-ds/elements-ds.css +157 -0
- package/es/elements-ds/index.d.ts +12 -0
- package/es/elements-ds/index.js +14 -0
- package/es/useTranslation/index.js +5 -3
- package/package.json +15 -3
- package/src/chrome/AppShell/AppShell.test.tsx +48 -0
- package/src/chrome/AppShell/index.tsx +29 -29
- package/src/chrome/openReport.test.ts +50 -0
- package/src/chrome/openReport.ts +34 -34
- package/src/colorScheme.test.ts +188 -0
- package/src/colorScheme.ts +125 -125
- package/src/components/Checkbox/Checkbox.browser.test.tsx +116 -0
- package/src/components/Checkbox/index.tsx +1 -10
- package/src/components/CodeEditor/CodeEditor.css +6 -6
- package/src/components/CodeEditor/CodeEditor.tsx +173 -173
- package/src/components/CodeEditor/index.ts +1 -1
- package/src/components/ColorCard/ColorCard.test.tsx +34 -0
- package/src/components/DateNavigator/DateNavigator.test.tsx +175 -0
- package/src/components/DateNavigator/index.tsx +186 -186
- package/src/components/FilePond.browser.test.tsx +389 -0
- package/src/components/FilePond.tsx +303 -312
- package/src/components/ImageEditor/ImageEditor.browser.test.tsx +286 -0
- package/src/components/ImageEditor/ImageEditor.test.tsx +299 -0
- package/src/components/ImageEditor/ImageEditor.tsx +348 -348
- package/src/components/ImageEditor/index.ts +9 -9
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.test.ts +225 -0
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
- package/src/components/ImageEditor/plugins/plugins.browser.test.ts +252 -0
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
- package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.test.ts +89 -0
- package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.ts +16 -13
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
- package/src/components/ImageEditor/plugins/zoomPlugin/useZoomPan.test.ts +154 -0
- package/src/components/ImageEditor/useActiveTool.ts +21 -21
- package/src/components/ImageEditor/useEdgeDetection.test.ts +96 -0
- package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
- package/src/components/ImageEditor/useImageHistory.test.ts +409 -0
- package/src/components/ImageEditor/useImageHistory.ts +206 -197
- package/src/components/ImageEditor/useOpenCV.test.ts +208 -0
- package/src/components/ImageEditor/useOpenCV.ts +184 -184
- package/src/components/LinkedCardList/index.scss +95 -95
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.browser.test.tsx +156 -0
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +1 -0
- package/src/components/MergeProgressDialog/useMergeJob.test.ts +326 -0
- package/src/components/MergeProgressDialog/useMergeJob.ts +4 -3
- package/src/components/PageBanner/index.tsx +80 -80
- package/src/components/PdfViewer/PdfViewer.browser.test.tsx +78 -0
- package/src/components/PdfViewer/PdfViewer.tsx +158 -158
- package/src/components/Portal/Portal.test.tsx +106 -0
- package/src/components/Portal/index.tsx +22 -25
- package/src/components/Sidebar/Sidebar.browser.test.tsx +57 -0
- package/src/components/Sidebar/Sidebar.test.tsx +123 -0
- package/src/components/SplitContainer/SplitContainer.browser.test.tsx +304 -0
- package/src/components/SplitContainer/index.tsx +335 -333
- package/src/components/Toolbar/Toolbar.css +137 -137
- package/src/components/Toolbar/Toolbar.test.tsx +216 -0
- package/src/components/Toolbar/ToolbarBreadcrumbs.browser.test.tsx +137 -0
- package/src/components/Toolbar/index.tsx +270 -265
- package/src/components/ValueToggleGroup/ValueToggleGroup.test.tsx +112 -0
- package/src/designsystemet-web-types.d.ts +24 -24
- package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
- package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
- package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
- package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
- package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
- package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
- package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
- package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
- package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
- package/src/elements/ElementLookup.tsx +123 -123
- package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.browser.test.tsx +175 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +8 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/engines.browser.test.ts +225 -0
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.test.ts +124 -0
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.ts +2 -1
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
- package/src/elements/ElementLookupDialog/getElement.test.ts +133 -0
- package/src/elements/ElementLookupDialog/index.tsx +226 -226
- package/src/elements/ElementLookupDialog/utils/Giai.test.ts +53 -0
- package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
- package/src/elements/ProjectSelect.tsx +130 -130
- package/src/elements/index.ts +15 -15
- package/src/elements-ds/DamageForm.browser.test.tsx +530 -0
- package/src/elements-ds/DescriptionInput.tsx +114 -0
- package/src/elements-ds/DuplicateElementDamage.tsx +185 -0
- package/src/elements-ds/ElementLookup.tsx +114 -0
- package/src/elements-ds/ElementLookupDialog.browser.test.tsx +207 -0
- package/src/elements-ds/ElementLookupDialog.tsx +196 -0
- package/src/elements-ds/FormFields.tsx +176 -0
- package/src/elements-ds/HIDScanner.tsx +53 -0
- package/src/elements-ds/ManualForm.tsx +129 -0
- package/src/elements-ds/ProjectSelect.tsx +120 -0
- package/src/elements-ds/elements-ds.css +157 -0
- package/src/elements-ds/index.ts +16 -0
- package/src/filter/index.ts +34 -34
- package/src/i18n.test.ts +31 -0
- package/src/i18n.ts +13 -13
- package/src/mui/MuiThemeProvider.tsx +135 -135
- package/src/test/fakeCamera.ts +98 -0
- package/src/test/fakeDataApi.ts +90 -0
- package/src/test/setup.browser.ts +21 -0
- package/src/test/setup.ts +23 -23
- package/src/useTranslation/index.ts +5 -3
- package/src/useTranslation/useTranslation.test.ts +128 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts +0 -1
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +0 -103
- package/es/test/setup.d.ts +0 -6
- package/es/test/setup.js +0 -6
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { userEvent } from "@testing-library/user-event";
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { Sidebar, type SidebarProps } from "./index";
|
|
6
|
+
|
|
7
|
+
function Page(props: SidebarProps) {
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
<button type="button">Edit customer</button>
|
|
11
|
+
<Sidebar {...props}>
|
|
12
|
+
<h2>Customer</h2>
|
|
13
|
+
<input aria-label="Name" />
|
|
14
|
+
<button type="button">Save</button>
|
|
15
|
+
</Sidebar>
|
|
16
|
+
</>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function sidebarRoot() {
|
|
21
|
+
return document.querySelector<HTMLElement>(".ObSidebar-root")!;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function overlay() {
|
|
25
|
+
return document.querySelector<HTMLElement>(".ObSidebar-overlay")!;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
vi.restoreAllMocks();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("Sidebar", () => {
|
|
33
|
+
it("keeps its content out of the page while closed", () => {
|
|
34
|
+
render(<Page />);
|
|
35
|
+
|
|
36
|
+
expect(screen.queryByRole("heading", { name: "Customer" })).toBeNull();
|
|
37
|
+
expect(sidebarRoot()).not.toHaveClass("Ob-open");
|
|
38
|
+
expect(overlay()).not.toHaveClass("Ob-open");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("shows its content and moves focus into it when opened", () => {
|
|
42
|
+
let { rerender } = render(<Page />);
|
|
43
|
+
screen.getByRole("button", { name: "Edit customer" }).focus();
|
|
44
|
+
|
|
45
|
+
rerender(<Page open />);
|
|
46
|
+
|
|
47
|
+
expect(screen.getByRole("heading", { name: "Customer" })).toBeInTheDocument();
|
|
48
|
+
expect(sidebarRoot()).toHaveClass("Ob-open");
|
|
49
|
+
expect(overlay()).toHaveClass("Ob-open");
|
|
50
|
+
expect(screen.getByRole("textbox", { name: "Name" })).toHaveFocus();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("closes on Escape", async () => {
|
|
54
|
+
let onClose = vi.fn();
|
|
55
|
+
render(<Page open onClose={onClose} />);
|
|
56
|
+
|
|
57
|
+
await userEvent.keyboard("{Escape}");
|
|
58
|
+
|
|
59
|
+
expect(onClose).toHaveBeenCalledOnce();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("does not report Escape while it is closed", async () => {
|
|
63
|
+
let onClose = vi.fn();
|
|
64
|
+
render(<Page onClose={onClose} />);
|
|
65
|
+
|
|
66
|
+
await userEvent.keyboard("{Escape}");
|
|
67
|
+
|
|
68
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("closes when the user clicks the overlay beside it", async () => {
|
|
72
|
+
let onClose = vi.fn();
|
|
73
|
+
render(<Page open onClose={onClose} />);
|
|
74
|
+
|
|
75
|
+
await userEvent.click(overlay());
|
|
76
|
+
|
|
77
|
+
expect(onClose).toHaveBeenCalledOnce();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("keeps its content while sliding out and drops it once the transition ends", () => {
|
|
81
|
+
let { rerender } = render(<Page open />);
|
|
82
|
+
|
|
83
|
+
rerender(<Page open={false} />);
|
|
84
|
+
expect(screen.getByRole("heading", { name: "Customer" })).toBeInTheDocument();
|
|
85
|
+
expect(sidebarRoot()).not.toHaveClass("Ob-open");
|
|
86
|
+
|
|
87
|
+
act(() => {
|
|
88
|
+
fireEvent.transitionEnd(sidebarRoot());
|
|
89
|
+
});
|
|
90
|
+
expect(screen.queryByRole("heading", { name: "Customer" })).toBeNull();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("gives focus back to where it was when it closes", () => {
|
|
94
|
+
let { rerender } = render(<Page />);
|
|
95
|
+
let opener = screen.getByRole("button", { name: "Edit customer" });
|
|
96
|
+
opener.focus();
|
|
97
|
+
|
|
98
|
+
rerender(<Page open />);
|
|
99
|
+
expect(opener).not.toHaveFocus();
|
|
100
|
+
|
|
101
|
+
rerender(<Page open={false} />);
|
|
102
|
+
expect(opener).toHaveFocus();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("passes props on to the panel and the overlay", () => {
|
|
106
|
+
render(
|
|
107
|
+
<Page
|
|
108
|
+
open
|
|
109
|
+
pullRight
|
|
110
|
+
shadow={false}
|
|
111
|
+
className="customer-panel"
|
|
112
|
+
aria-label="Customer details"
|
|
113
|
+
overlayProps={{ className: "dimmed", style: { opacity: 0.5 } }}
|
|
114
|
+
/>,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(sidebarRoot()).toHaveClass("customer-panel", "Ob-right");
|
|
118
|
+
expect(sidebarRoot()).not.toHaveClass("ObSidebar-shadow");
|
|
119
|
+
expect(sidebarRoot()).toHaveAttribute("aria-label", "Customer details");
|
|
120
|
+
expect(overlay()).toHaveClass("ObSidebar-overlay", "dimmed");
|
|
121
|
+
expect(overlay()).toHaveStyle({ opacity: "0.5" });
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { userEvent } from "vitest/browser";
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { SplitContainer, type SplitContainerProps } from "./index";
|
|
6
|
+
|
|
7
|
+
const WIDTH = 800;
|
|
8
|
+
const HEIGHT = 600;
|
|
9
|
+
|
|
10
|
+
function renderSplit(props: Partial<SplitContainerProps> = {}) {
|
|
11
|
+
let result = render(
|
|
12
|
+
<div style={{ width: WIDTH, height: HEIGHT }}>
|
|
13
|
+
<SplitContainer {...props}>
|
|
14
|
+
<div data-testid="first">Grid</div>
|
|
15
|
+
<div data-testid="second">Form</div>
|
|
16
|
+
</SplitContainer>
|
|
17
|
+
</div>,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
...result,
|
|
22
|
+
divider: screen.getByRole("separator"),
|
|
23
|
+
first: screen.getByTestId("first").parentElement!,
|
|
24
|
+
second: screen.getByTestId("second").parentElement!,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function height(element: HTMLElement) {
|
|
29
|
+
return element.getBoundingClientRect().height;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function width(element: HTMLElement) {
|
|
33
|
+
return element.getBoundingClientRect().width;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Drags the divider by the given distance, the way a mouse or finger does. */
|
|
37
|
+
function drag(divider: HTMLElement, dx: number, dy: number) {
|
|
38
|
+
let box = divider.getBoundingClientRect();
|
|
39
|
+
let x = box.left + box.width / 2;
|
|
40
|
+
let y = box.top + box.height / 2;
|
|
41
|
+
let init = { bubbles: true, pointerId: 1, isPrimary: true };
|
|
42
|
+
|
|
43
|
+
divider.dispatchEvent(new PointerEvent("pointerdown", { ...init, clientX: x, clientY: y }));
|
|
44
|
+
window.dispatchEvent(new PointerEvent("pointermove", { ...init, clientX: x + dx / 2, clientY: y + dy / 2 }));
|
|
45
|
+
window.dispatchEvent(new PointerEvent("pointermove", { ...init, clientX: x + dx, clientY: y + dy }));
|
|
46
|
+
window.dispatchEvent(new PointerEvent("pointerup", { ...init, clientX: x + dx, clientY: y + dy }));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Waits until the container has measured itself, which the size limits depend on. */
|
|
50
|
+
async function measured(divider: HTMLElement, size: number) {
|
|
51
|
+
await expect.poll(() => divider.getAttribute("aria-valuemax")).toBe(String(size));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Waits for the container's first measurement when `max` hides it from `aria-valuemax`. */
|
|
55
|
+
async function nextFrames() {
|
|
56
|
+
for (let i = 0; i < 3; i++) await new Promise(requestAnimationFrame);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let nextId = 0;
|
|
60
|
+
function uniqueId() {
|
|
61
|
+
return `SplitTest${nextId++}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
vi.restoreAllMocks();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("SplitContainer", () => {
|
|
69
|
+
it("gives the fixed panel its default size and the other panel the rest", async () => {
|
|
70
|
+
let { divider, first, second } = renderSplit({ defaultFixedSize: 400 });
|
|
71
|
+
await measured(divider, HEIGHT);
|
|
72
|
+
|
|
73
|
+
expect(height(first)).toBe(400);
|
|
74
|
+
expect(height(first) + height(divider) + height(second)).toBe(HEIGHT);
|
|
75
|
+
expect(divider).toHaveAttribute("aria-orientation", "vertical");
|
|
76
|
+
expect(divider).toHaveAttribute("aria-valuenow", "400");
|
|
77
|
+
expect(divider).toHaveAttribute("aria-valuemin", "0");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("can fix the second panel instead", async () => {
|
|
81
|
+
let { divider, second } = renderSplit({ fixedPanel: 2, defaultFixedSize: 250 });
|
|
82
|
+
await measured(divider, HEIGHT);
|
|
83
|
+
|
|
84
|
+
expect(height(second)).toBe(250);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("lays the panels side by side when horizontal", async () => {
|
|
88
|
+
let { divider, first, second } = renderSplit({ direction: "horizontal", defaultFixedSize: 300 });
|
|
89
|
+
await measured(divider, WIDTH);
|
|
90
|
+
|
|
91
|
+
expect(width(first)).toBe(300);
|
|
92
|
+
expect(first.getBoundingClientRect().top).toBe(second.getBoundingClientRect().top);
|
|
93
|
+
expect(divider).toHaveAttribute("aria-orientation", "horizontal");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("requires exactly two children", () => {
|
|
97
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
98
|
+
|
|
99
|
+
expect(() =>
|
|
100
|
+
render(
|
|
101
|
+
// @ts-expect-error -- the types already ask for two; this is the JavaScript caller's case.
|
|
102
|
+
<SplitContainer>
|
|
103
|
+
<div>Only one</div>
|
|
104
|
+
</SplitContainer>,
|
|
105
|
+
),
|
|
106
|
+
).toThrow("SplitContainer requires exactly 2 children");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("dragging the divider", () => {
|
|
110
|
+
it("grows the first panel when dragged down", async () => {
|
|
111
|
+
let { divider, first } = renderSplit({ defaultFixedSize: 300 });
|
|
112
|
+
await measured(divider, HEIGHT);
|
|
113
|
+
|
|
114
|
+
drag(divider, 0, 100);
|
|
115
|
+
|
|
116
|
+
await expect.poll(() => height(first)).toBe(400);
|
|
117
|
+
expect(divider).toHaveAttribute("aria-valuenow", "400");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("shrinks a fixed second panel when dragged down", async () => {
|
|
121
|
+
let { divider, second } = renderSplit({ fixedPanel: 2, defaultFixedSize: 300 });
|
|
122
|
+
await measured(divider, HEIGHT);
|
|
123
|
+
|
|
124
|
+
drag(divider, 0, 100);
|
|
125
|
+
|
|
126
|
+
await expect.poll(() => height(second)).toBe(200);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("follows the pointer sideways when horizontal", async () => {
|
|
130
|
+
let { divider, first } = renderSplit({ direction: "horizontal", defaultFixedSize: 300 });
|
|
131
|
+
await measured(divider, WIDTH);
|
|
132
|
+
|
|
133
|
+
drag(divider, -120, 0);
|
|
134
|
+
|
|
135
|
+
await expect.poll(() => width(first)).toBe(180);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("resizes while the pointer moves, before it is released", async () => {
|
|
139
|
+
let { divider, first } = renderSplit({ defaultFixedSize: 300 });
|
|
140
|
+
await measured(divider, HEIGHT);
|
|
141
|
+
let box = divider.getBoundingClientRect();
|
|
142
|
+
let y = box.top + box.height / 2;
|
|
143
|
+
|
|
144
|
+
divider.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, clientX: 10, clientY: y }));
|
|
145
|
+
window.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, clientX: 10, clientY: y + 50 }));
|
|
146
|
+
|
|
147
|
+
expect(height(first)).toBe(350);
|
|
148
|
+
expect(divider).toHaveAttribute("aria-valuenow", "350");
|
|
149
|
+
// The panels ignore the pointer while dragging, so a grid or iframe in them cannot steal it.
|
|
150
|
+
await expect.poll(() => first.classList.contains("dragging")).toBe(true);
|
|
151
|
+
|
|
152
|
+
window.dispatchEvent(new PointerEvent("pointerup", { bubbles: true, clientX: 10, clientY: y + 50 }));
|
|
153
|
+
await expect.poll(() => first.classList.contains("dragging")).toBe(false);
|
|
154
|
+
expect(height(first)).toBe(350);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("stops at the minimum size", async () => {
|
|
158
|
+
let { divider, first } = renderSplit({ defaultFixedSize: 300, min: 200 });
|
|
159
|
+
await measured(divider, HEIGHT);
|
|
160
|
+
|
|
161
|
+
drag(divider, 0, -250);
|
|
162
|
+
|
|
163
|
+
await expect.poll(() => height(first)).toBe(200);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("stops at the maximum size", async () => {
|
|
167
|
+
let { divider, first } = renderSplit({ defaultFixedSize: 300, max: 450 });
|
|
168
|
+
expect(divider).toHaveAttribute("aria-valuemax", "450");
|
|
169
|
+
await nextFrames();
|
|
170
|
+
|
|
171
|
+
drag(divider, 0, 400);
|
|
172
|
+
|
|
173
|
+
await expect.poll(() => height(first)).toBe(450);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it.each(["vertical", "horizontal"] as const)(
|
|
177
|
+
"never pushes the divider out of the container (%s)",
|
|
178
|
+
async (direction) => {
|
|
179
|
+
let { divider, first } = renderSplit({ direction, defaultFixedSize: 300 });
|
|
180
|
+
let size = direction === "vertical" ? HEIGHT : WIDTH;
|
|
181
|
+
await measured(divider, size);
|
|
182
|
+
|
|
183
|
+
drag(divider, direction === "horizontal" ? 2000 : 0, direction === "vertical" ? 2000 : 0);
|
|
184
|
+
|
|
185
|
+
let container = first.parentElement!.getBoundingClientRect();
|
|
186
|
+
await expect.poll(() => (direction === "vertical" ? height(first) : width(first))).toBeGreaterThan(size - 20);
|
|
187
|
+
let box = divider.getBoundingClientRect();
|
|
188
|
+
expect(box.bottom).toBeLessThanOrEqual(container.bottom);
|
|
189
|
+
expect(box.right).toBeLessThanOrEqual(container.right);
|
|
190
|
+
},
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("keyboard", () => {
|
|
195
|
+
it("moves the divider with the arrow keys, further with Shift", async () => {
|
|
196
|
+
let { divider, first } = renderSplit({ defaultFixedSize: 300 });
|
|
197
|
+
await measured(divider, HEIGHT);
|
|
198
|
+
divider.focus();
|
|
199
|
+
|
|
200
|
+
await userEvent.keyboard("{ArrowDown}");
|
|
201
|
+
await expect.poll(() => height(first)).toBe(305);
|
|
202
|
+
|
|
203
|
+
await userEvent.keyboard("{Shift>}{ArrowDown}{/Shift}");
|
|
204
|
+
await expect.poll(() => height(first)).toBe(330);
|
|
205
|
+
|
|
206
|
+
await userEvent.keyboard("{ArrowUp}");
|
|
207
|
+
await expect.poll(() => height(first)).toBe(325);
|
|
208
|
+
expect(divider).toHaveAttribute("aria-valuenow", "325");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("moves toward the arrow when the second panel is fixed and horizontal", async () => {
|
|
212
|
+
let { divider, second } = renderSplit({ direction: "horizontal", fixedPanel: 2, defaultFixedSize: 300 });
|
|
213
|
+
await measured(divider, WIDTH);
|
|
214
|
+
divider.focus();
|
|
215
|
+
|
|
216
|
+
await userEvent.keyboard("{ArrowLeft}");
|
|
217
|
+
await expect.poll(() => width(second)).toBe(305);
|
|
218
|
+
|
|
219
|
+
await userEvent.keyboard("{ArrowRight}");
|
|
220
|
+
await expect.poll(() => width(second)).toBe(300);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("ignores the arrows across its direction and with modifier keys", async () => {
|
|
224
|
+
let { divider, first } = renderSplit({ defaultFixedSize: 300 });
|
|
225
|
+
await measured(divider, HEIGHT);
|
|
226
|
+
divider.focus();
|
|
227
|
+
|
|
228
|
+
await userEvent.keyboard("{ArrowRight}");
|
|
229
|
+
await userEvent.keyboard("{Control>}{ArrowDown}{/Control}");
|
|
230
|
+
|
|
231
|
+
expect(height(first)).toBe(300);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("keeps within the limits", async () => {
|
|
235
|
+
let { divider, first } = renderSplit({ defaultFixedSize: 202, min: 200 });
|
|
236
|
+
await measured(divider, HEIGHT);
|
|
237
|
+
divider.focus();
|
|
238
|
+
|
|
239
|
+
await userEvent.keyboard("{ArrowUp}");
|
|
240
|
+
|
|
241
|
+
await expect.poll(() => height(first)).toBe(200);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe("with an id", () => {
|
|
246
|
+
it("restores the size the user chose after the page is reloaded", async () => {
|
|
247
|
+
let id = uniqueId();
|
|
248
|
+
let { divider, unmount } = renderSplit({ id, defaultFixedSize: 300 });
|
|
249
|
+
await measured(divider, HEIGHT);
|
|
250
|
+
drag(divider, 0, 100);
|
|
251
|
+
await expect.poll(() => divider.getAttribute("aria-valuenow")).toBe("400");
|
|
252
|
+
unmount();
|
|
253
|
+
|
|
254
|
+
let again = renderSplit({ id, defaultFixedSize: 300 });
|
|
255
|
+
|
|
256
|
+
await expect.poll(() => height(again.first)).toBe(400);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("starts from the default again when the layout version changes", async () => {
|
|
260
|
+
let id = uniqueId();
|
|
261
|
+
let { divider, unmount } = renderSplit({ id, defaultFixedSize: 300, layoutVersion: 1 });
|
|
262
|
+
await measured(divider, HEIGHT);
|
|
263
|
+
drag(divider, 0, 100);
|
|
264
|
+
await expect.poll(() => divider.getAttribute("aria-valuenow")).toBe("400");
|
|
265
|
+
unmount();
|
|
266
|
+
|
|
267
|
+
let again = renderSplit({ id, defaultFixedSize: 300, layoutVersion: 2 });
|
|
268
|
+
await measured(again.divider, HEIGHT);
|
|
269
|
+
|
|
270
|
+
// Give a stored size the chance to be (wrongly) restored.
|
|
271
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
272
|
+
expect(height(again.first)).toBe(300);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("keeps containers with different ids apart", async () => {
|
|
276
|
+
let id = uniqueId();
|
|
277
|
+
let { divider, unmount } = renderSplit({ id, defaultFixedSize: 300 });
|
|
278
|
+
await measured(divider, HEIGHT);
|
|
279
|
+
drag(divider, 0, 100);
|
|
280
|
+
await expect.poll(() => divider.getAttribute("aria-valuenow")).toBe("400");
|
|
281
|
+
unmount();
|
|
282
|
+
|
|
283
|
+
let other = renderSplit({ id: uniqueId(), defaultFixedSize: 300 });
|
|
284
|
+
await measured(other.divider, HEIGHT);
|
|
285
|
+
|
|
286
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
287
|
+
expect(height(other.first)).toBe(300);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("does not remember the size without an id", async () => {
|
|
291
|
+
let { divider, unmount } = renderSplit({ defaultFixedSize: 300 });
|
|
292
|
+
await measured(divider, HEIGHT);
|
|
293
|
+
drag(divider, 0, 100);
|
|
294
|
+
await expect.poll(() => divider.getAttribute("aria-valuenow")).toBe("400");
|
|
295
|
+
unmount();
|
|
296
|
+
|
|
297
|
+
let again = renderSplit({ defaultFixedSize: 300 });
|
|
298
|
+
await measured(again.divider, HEIGHT);
|
|
299
|
+
|
|
300
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
301
|
+
expect(height(again.first)).toBe(300);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
});
|