@open-mercato/ui 0.5.1-develop.2912.8d7b1fef24 → 0.5.1-develop.2924.d13908516e
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/.turbo/turbo-build.log +1 -1
- package/dist/backend/CrudForm.js +51 -4
- package/dist/backend/CrudForm.js.map +2 -2
- package/dist/backend/crud/CollapsibleGroup.js +57 -32
- package/dist/backend/crud/CollapsibleGroup.js.map +2 -2
- package/dist/backend/crud/SortableGroupHandle.js +40 -0
- package/dist/backend/crud/SortableGroupHandle.js.map +7 -0
- package/package.json +3 -3
- package/src/backend/CrudForm.tsx +56 -5
- package/src/backend/__tests__/CrudForm.sortable.test.tsx +96 -0
- package/src/backend/crud/CollapsibleGroup.tsx +52 -30
- package/src/backend/crud/SortableGroupHandle.tsx +50 -0
- package/src/backend/crud/__tests__/SortableGroupHandle.test.tsx +87 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { render } from '@testing-library/react'
|
|
4
|
+
import {
|
|
5
|
+
SortableGroupHandle,
|
|
6
|
+
SortableGroupHandleProvider,
|
|
7
|
+
useSortableGroupHandle,
|
|
8
|
+
type SortableGroupHandleProps,
|
|
9
|
+
} from '../SortableGroupHandle'
|
|
10
|
+
|
|
11
|
+
function makeHandleProps(overrides: Partial<SortableGroupHandleProps> = {}): SortableGroupHandleProps {
|
|
12
|
+
return {
|
|
13
|
+
ref: () => {},
|
|
14
|
+
attributes: { role: 'button', tabIndex: 0 },
|
|
15
|
+
listeners: { onKeyDown: () => {} },
|
|
16
|
+
isDragging: false,
|
|
17
|
+
disabled: false,
|
|
18
|
+
...overrides,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('SortableGroupHandle', () => {
|
|
23
|
+
it('returns null when context is absent', () => {
|
|
24
|
+
const { container } = render(<SortableGroupHandle ariaLabel="Drag" />)
|
|
25
|
+
expect(container.firstChild).toBeNull()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('renders a button with the given aria-label when context is provided', () => {
|
|
29
|
+
const { container } = render(
|
|
30
|
+
<SortableGroupHandleProvider value={makeHandleProps()}>
|
|
31
|
+
<SortableGroupHandle ariaLabel="Drag to reorder" />
|
|
32
|
+
</SortableGroupHandleProvider>,
|
|
33
|
+
)
|
|
34
|
+
const button = container.querySelector('button[aria-label="Drag to reorder"]')
|
|
35
|
+
expect(button).not.toBeNull()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('forwards the ref callback from context to the underlying button', () => {
|
|
39
|
+
const refCalls: Array<HTMLElement | null> = []
|
|
40
|
+
const handleProps = makeHandleProps({
|
|
41
|
+
ref: (node) => refCalls.push(node),
|
|
42
|
+
})
|
|
43
|
+
render(
|
|
44
|
+
<SortableGroupHandleProvider value={handleProps}>
|
|
45
|
+
<SortableGroupHandle ariaLabel="Drag" />
|
|
46
|
+
</SortableGroupHandleProvider>,
|
|
47
|
+
)
|
|
48
|
+
expect(refCalls.length).toBeGreaterThanOrEqual(1)
|
|
49
|
+
const node = refCalls.find((n) => n !== null)
|
|
50
|
+
expect(node?.tagName).toBe('BUTTON')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('renders disabled when context says disabled', () => {
|
|
54
|
+
const { container } = render(
|
|
55
|
+
<SortableGroupHandleProvider value={makeHandleProps({ disabled: true })}>
|
|
56
|
+
<SortableGroupHandle ariaLabel="Drag" />
|
|
57
|
+
</SortableGroupHandleProvider>,
|
|
58
|
+
)
|
|
59
|
+
const button = container.querySelector('button[aria-label="Drag"]') as HTMLButtonElement
|
|
60
|
+
expect(button?.disabled).toBe(true)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
describe('useSortableGroupHandle', () => {
|
|
65
|
+
function HookProbe({ onValue }: { onValue: (v: SortableGroupHandleProps | null) => void }) {
|
|
66
|
+
const value = useSortableGroupHandle()
|
|
67
|
+
onValue(value)
|
|
68
|
+
return null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
it('returns null outside provider', () => {
|
|
72
|
+
let captured: SortableGroupHandleProps | null | undefined
|
|
73
|
+
render(<HookProbe onValue={(v) => { captured = v }} />)
|
|
74
|
+
expect(captured).toBeNull()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('returns the provided context value', () => {
|
|
78
|
+
const handleProps = makeHandleProps({ isDragging: true })
|
|
79
|
+
let captured: SortableGroupHandleProps | null | undefined
|
|
80
|
+
render(
|
|
81
|
+
<SortableGroupHandleProvider value={handleProps}>
|
|
82
|
+
<HookProbe onValue={(v) => { captured = v }} />
|
|
83
|
+
</SortableGroupHandleProvider>,
|
|
84
|
+
)
|
|
85
|
+
expect(captured?.isDragging).toBe(true)
|
|
86
|
+
})
|
|
87
|
+
})
|