@olenbetong/synergi-react 4.3.1 → 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/dist/styles/styles.css +1 -1
- package/dist/styles/styles.css.map +1 -1
- package/es/components/Checkbox/index.js +1 -9
- 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.d.ts +7 -0
- package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +20 -0
- package/es/components/MergeProgressDialog/index.d.ts +3 -8
- package/es/components/MergeProgressDialog/index.js +4 -133
- package/es/components/MergeProgressDialog/useMergeJob.d.ts +36 -0
- package/es/components/MergeProgressDialog/useMergeJob.js +142 -0
- package/es/components/Portal/index.js +20 -20
- package/es/components/ProgressBar/index.css +1 -1
- package/es/components/SplitContainer/index.js +3 -1
- package/es/components/Toolbar/index.js +6 -1
- package/es/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +81 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.d.ts +2 -2
- package/es/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.js +1 -2
- package/es/elements/ElementLookupDialog/BarcodeScanner/Error.js +3 -29
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +8 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +1 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +3 -28
- 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/index.css +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/mui/index.d.ts +1 -0
- package/es/mui/index.js +1 -0
- package/es/useTranslation/index.js +5 -3
- package/package.json +34 -15
- package/src/chrome/AppShell/AppShell.test.tsx +48 -0
- package/src/chrome/openReport.test.ts +50 -0
- package/src/colorScheme.test.ts +188 -0
- package/src/components/Checkbox/Checkbox.browser.test.tsx +116 -0
- package/src/components/Checkbox/index.tsx +1 -10
- package/src/components/ColorCard/ColorCard.test.tsx +34 -0
- package/src/components/DateNavigator/DateNavigator.test.tsx +175 -0
- package/src/components/FilePond.browser.test.tsx +389 -0
- package/src/components/FilePond.tsx +3 -12
- package/src/components/ImageEditor/ImageEditor.browser.test.tsx +286 -0
- package/src/components/ImageEditor/ImageEditor.test.tsx +299 -0
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.test.ts +225 -0
- package/src/components/ImageEditor/plugins/plugins.browser.test.ts +252 -0
- 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/useZoomPan.test.ts +154 -0
- package/src/components/ImageEditor/useEdgeDetection.test.ts +96 -0
- package/src/components/ImageEditor/useImageHistory.test.ts +409 -0
- package/src/components/ImageEditor/useImageHistory.ts +10 -1
- package/src/components/ImageEditor/useOpenCV.test.ts +208 -0
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.browser.test.tsx +156 -0
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +92 -0
- package/src/components/MergeProgressDialog/index.tsx +5 -158
- package/src/components/MergeProgressDialog/useMergeJob.test.ts +326 -0
- package/src/components/MergeProgressDialog/useMergeJob.ts +170 -0
- package/src/components/PdfViewer/PdfViewer.browser.test.tsx +78 -0
- package/src/components/Portal/Portal.test.tsx +106 -0
- package/src/components/Portal/index.tsx +22 -25
- package/src/components/ProgressBar/index.scss +23 -54
- 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 +3 -1
- 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 +6 -1
- package/src/components/ValueToggleGroup/ValueToggleGroup.test.tsx +112 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.browser.test.tsx +175 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +81 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.tsx +4 -4
- package/src/elements/ElementLookupDialog/BarcodeScanner/Error.tsx +7 -36
- 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/BarcodeScanner/index.tsx +20 -49
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.test.ts +124 -0
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.ts +2 -1
- package/src/elements/ElementLookupDialog/getElement.test.ts +133 -0
- package/src/elements/ElementLookupDialog/utils/Giai.test.ts +53 -0
- 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/i18n.test.ts +31 -0
- package/src/index.ts +5 -1
- package/src/mui/index.ts +1 -0
- 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 +15 -0
- 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 -1
- package/es/test/setup.js +0 -6
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from "react";
|
|
2
2
|
import { createPortal } from "react-dom";
|
|
3
3
|
|
|
4
|
-
function useForceUpdate() {
|
|
5
|
-
const [, setVal] = useState(false);
|
|
6
|
-
|
|
7
|
-
return () => setVal((val) => !val);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
4
|
export type PortalProps = {
|
|
11
5
|
children: React.ReactNode;
|
|
12
6
|
root?: string;
|
|
@@ -14,30 +8,33 @@ export type PortalProps = {
|
|
|
14
8
|
};
|
|
15
9
|
|
|
16
10
|
export function Portal({ children, root, type = "div" }: PortalProps) {
|
|
17
|
-
const forceUpdate = useForceUpdate();
|
|
18
11
|
const mountNode = useRef<HTMLDivElement>(null);
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
const ownerDocument = useRef<Document | null>(null);
|
|
13
|
+
const [portalNode, setPortalNode] = useState<HTMLElement | null>(null);
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* The element is created after mount, in the document the placeholder was rendered in, and
|
|
17
|
+
* held in state: a remount (StrictMode) or a new root/type creates a fresh one and renders
|
|
18
|
+
* into it, rather than into the element the previous run removed.
|
|
19
|
+
*/
|
|
22
20
|
useEffect(() => {
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
21
|
+
let doc = mountNode.current?.ownerDocument ?? ownerDocument.current ?? globalThis.document;
|
|
22
|
+
if (!doc) return;
|
|
23
|
+
ownerDocument.current = doc;
|
|
24
|
+
|
|
25
|
+
let parent = (root ? doc.querySelector(root) : null) ?? doc.body;
|
|
26
|
+
let node = doc.createElement(type);
|
|
27
|
+
parent.appendChild(node);
|
|
28
|
+
setPortalNode(node);
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
parent.removeChild(node);
|
|
32
|
+
};
|
|
36
33
|
}, [root, type]);
|
|
37
34
|
|
|
38
|
-
if (!portalNode
|
|
35
|
+
if (!portalNode) {
|
|
39
36
|
return <div ref={mountNode} />;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
return createPortal(children, portalNode
|
|
39
|
+
return createPortal(children, portalNode);
|
|
43
40
|
}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
@use "../../styles/variables";
|
|
2
2
|
|
|
3
|
+
// Designsystemet tokens, so the bar follows the colour scheme on the 2026 template; the old
|
|
4
|
+
// colours are the fallbacks on templates that do not load Designsystemet.
|
|
3
5
|
.ObProgressBar-root {
|
|
6
|
+
--ob-progress-track: var(--ds-color-neutral-surface-active, whiteSmoke);
|
|
7
|
+
--ob-progress-value-start: var(--ds-color-brand-base-default, var(--brand-primary));
|
|
8
|
+
--ob-progress-value-end: var(--ds-color-brand-base-hover, var(--brand-light));
|
|
9
|
+
--ob-progress-stripe: rgb(0 0 0 / 0.1);
|
|
10
|
+
--ob-progress-shadow: 0 2px 3px rgb(0 0 0 / 0.2) inset;
|
|
11
|
+
|
|
4
12
|
height: 1.5em;
|
|
5
13
|
width: 100%;
|
|
6
14
|
appearance: none;
|
|
7
15
|
-webkit-appearance: none;
|
|
8
|
-
background-color:
|
|
16
|
+
background-color: var(--ob-progress-track);
|
|
9
17
|
border: none;
|
|
10
|
-
border-radius: 3px;
|
|
11
|
-
box-shadow:
|
|
12
|
-
color:
|
|
18
|
+
border-radius: var(--ds-border-radius-sm, 3px);
|
|
19
|
+
box-shadow: var(--ob-progress-shadow);
|
|
20
|
+
color: var(--ob-progress-value-start);
|
|
13
21
|
position: relative;
|
|
14
22
|
|
|
15
23
|
&::-webkit-progress-bar {
|
|
16
|
-
background-color:
|
|
17
|
-
border-radius: 3px;
|
|
18
|
-
box-shadow:
|
|
24
|
+
background-color: var(--ob-progress-track);
|
|
25
|
+
border-radius: var(--ds-border-radius-sm, 3px);
|
|
26
|
+
box-shadow: var(--ob-progress-shadow);
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
&::-webkit-progress-value {
|
|
@@ -24,73 +32,34 @@
|
|
|
24
32
|
135deg,
|
|
25
33
|
transparent,
|
|
26
34
|
transparent 33%,
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
var(--ob-progress-stripe) 33%,
|
|
36
|
+
var(--ob-progress-stripe) 66%,
|
|
29
37
|
transparent 66%
|
|
30
38
|
),
|
|
31
|
-
linear-gradient(
|
|
32
|
-
linear-gradient(left, var(--brand-primary), var(--brand-light));
|
|
33
|
-
background-image:
|
|
34
|
-
-webkit-linear-gradient(
|
|
35
|
-
135deg,
|
|
36
|
-
transparent,
|
|
37
|
-
transparent 33%,
|
|
38
|
-
rgba(0, 0, 0, 0.1) 33%,
|
|
39
|
-
rgba(0, 0, 0, 0.1) 66%,
|
|
40
|
-
transparent 66%
|
|
41
|
-
),
|
|
42
|
-
-webkit-linear-gradient(top, rgba(255, 255, 255, 0.25), rgba(0, 0, 0, 0.2)),
|
|
43
|
-
-webkit-linear-gradient(left, var(--brand-primary), var(--brand-light));
|
|
39
|
+
linear-gradient(to right, var(--ob-progress-value-start), var(--ob-progress-value-end));
|
|
44
40
|
background-size:
|
|
45
41
|
35px 20px,
|
|
46
|
-
100% 100%,
|
|
47
42
|
100% 100%;
|
|
48
|
-
border-radius: 3px;
|
|
43
|
+
border-radius: var(--ds-border-radius-sm, 3px);
|
|
49
44
|
position: relative;
|
|
50
45
|
transition: width 0.5s ease-out;
|
|
51
46
|
}
|
|
52
47
|
|
|
53
|
-
&::-webkit-progress-value:after {
|
|
54
|
-
background-color: white;
|
|
55
|
-
content: "";
|
|
56
|
-
|
|
57
|
-
border-radius: 100%;
|
|
58
|
-
height: 5px;
|
|
59
|
-
|
|
60
|
-
position: absolute;
|
|
61
|
-
right: 7px;
|
|
62
|
-
top: 7px;
|
|
63
|
-
width: 5px;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
48
|
&::-moz-progress-bar {
|
|
67
49
|
background-image:
|
|
68
50
|
linear-gradient(
|
|
69
51
|
135deg,
|
|
70
52
|
transparent,
|
|
71
53
|
transparent 33%,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
transparent 66%
|
|
75
|
-
),
|
|
76
|
-
linear-gradient(top, rgba(255, 255, 255, 0.25), rgba(0, 0, 0, 0.2)),
|
|
77
|
-
linear-gradient(left, var(--brand-primary), var(--brand-light));
|
|
78
|
-
background-image:
|
|
79
|
-
-moz-linear-gradient(
|
|
80
|
-
135deg,
|
|
81
|
-
transparent,
|
|
82
|
-
transparent 33%,
|
|
83
|
-
rgba(0, 0, 0, 0.1) 33%,
|
|
84
|
-
rgba(0, 0, 0, 0.1) 66%,
|
|
54
|
+
var(--ob-progress-stripe) 33%,
|
|
55
|
+
var(--ob-progress-stripe) 66%,
|
|
85
56
|
transparent 66%
|
|
86
57
|
),
|
|
87
|
-
|
|
88
|
-
-moz-linear-gradient(left, var(--brand-primary), var(--brand-light));
|
|
58
|
+
linear-gradient(to right, var(--ob-progress-value-start), var(--ob-progress-value-end));
|
|
89
59
|
background-size:
|
|
90
60
|
35px 20px,
|
|
91
|
-
100% 100%,
|
|
92
61
|
100% 100%;
|
|
93
|
-
border-radius: 3px;
|
|
62
|
+
border-radius: var(--ds-border-radius-sm, 3px);
|
|
94
63
|
transition: width 0.5s ease-out;
|
|
95
64
|
}
|
|
96
65
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { userEvent } from "vitest/browser";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { Sidebar } from "./index";
|
|
6
|
+
|
|
7
|
+
describe("Sidebar in a real browser", () => {
|
|
8
|
+
it("slides in from the edge and out again, dropping its content when it has left", async () => {
|
|
9
|
+
let { rerender } = render(
|
|
10
|
+
<Sidebar>
|
|
11
|
+
<h2>Customer</h2>
|
|
12
|
+
</Sidebar>,
|
|
13
|
+
);
|
|
14
|
+
let panel = document.querySelector<HTMLElement>(".ObSidebar-root")!;
|
|
15
|
+
expect(panel.getBoundingClientRect().right).toBeLessThanOrEqual(0);
|
|
16
|
+
|
|
17
|
+
rerender(
|
|
18
|
+
<Sidebar open>
|
|
19
|
+
<h2>Customer</h2>
|
|
20
|
+
</Sidebar>,
|
|
21
|
+
);
|
|
22
|
+
await expect.poll(() => panel.getBoundingClientRect().left).toBe(0);
|
|
23
|
+
|
|
24
|
+
rerender(
|
|
25
|
+
<Sidebar open={false}>
|
|
26
|
+
<h2>Customer</h2>
|
|
27
|
+
</Sidebar>,
|
|
28
|
+
);
|
|
29
|
+
expect(screen.getByRole("heading", { name: "Customer" })).toBeInTheDocument();
|
|
30
|
+
await expect.poll(() => screen.queryByRole("heading", { name: "Customer" })).toBeNull();
|
|
31
|
+
expect(panel.getBoundingClientRect().right).toBeLessThanOrEqual(0);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("slides in from the right with pullRight", async () => {
|
|
35
|
+
render(
|
|
36
|
+
<Sidebar open pullRight>
|
|
37
|
+
<h2>Customer</h2>
|
|
38
|
+
</Sidebar>,
|
|
39
|
+
);
|
|
40
|
+
let panel = document.querySelector<HTMLElement>(".ObSidebar-root")!;
|
|
41
|
+
|
|
42
|
+
await expect.poll(() => Math.round(panel.getBoundingClientRect().right)).toBe(window.innerWidth);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("closes when the user clicks beside it", async () => {
|
|
46
|
+
let onClose = vi.fn();
|
|
47
|
+
render(
|
|
48
|
+
<Sidebar open onClose={onClose} style={{ width: 200 }}>
|
|
49
|
+
<h2>Customer</h2>
|
|
50
|
+
</Sidebar>,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
await userEvent.click(document.body, { position: { x: window.innerWidth - 20, y: 20 } });
|
|
54
|
+
|
|
55
|
+
expect(onClose).toHaveBeenCalledOnce();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -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
|
+
});
|
|
@@ -209,7 +209,9 @@ export function SplitContainer({
|
|
|
209
209
|
) as HTMLElement;
|
|
210
210
|
|
|
211
211
|
function clampSize(size: number) {
|
|
212
|
-
|
|
212
|
+
// Leave room for the divider itself, so it is never pushed out of the container.
|
|
213
|
+
let dividerSize = divider ? (direction === "horizontal" ? divider.offsetWidth : divider.offsetHeight) : 0;
|
|
214
|
+
let adjustedContainerSize = containerSize - Math.max(dividerSize, 10);
|
|
213
215
|
let maxSize = Math.min(max ?? adjustedContainerSize, adjustedContainerSize);
|
|
214
216
|
if (size < min) {
|
|
215
217
|
size = min;
|