@registrucentras/rc-ses-react-components 1.11.0 → 1.13.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/README.md +5 -1
- package/dist/assets/icons/CaretUpBoldIcon.d.ts +3 -0
- package/dist/assets/icons/CaretUpIcon.d.ts +3 -0
- package/dist/assets/icons/ListIcon.d.ts +3 -0
- package/dist/assets/icons/MinusIcon.d.ts +3 -0
- package/dist/assets/icons/NotePencilIcon.d.ts +3 -0
- package/dist/assets/icons/PlusIcon.d.ts +3 -0
- package/dist/assets/icons/TrashIcon.d.ts +3 -0
- package/dist/assets/icons/UserIcon.d.ts +3 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.d.ts +106 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.d.ts +12 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.d.ts +7 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.d.ts +2 -0
- package/dist/components/common/AdvancedList/components/AdvancedListItem/index.d.ts +4 -0
- package/dist/components/common/AdvancedList/index.d.ts +11 -0
- package/dist/components/common/SelectableCardList/components/SelectableCardListItem.d.ts +4 -1
- package/dist/components/common/SelectableCardList/index.d.ts +4 -1
- package/dist/components/common/Tooltip/index.d.ts +20 -0
- package/dist/components/form/inputs/Select/index.d.ts +1 -0
- package/dist/library/icons.d.ts +9 -1
- package/dist/library/index.d.ts +5 -0
- package/dist/library/types.d.ts +2 -1
- package/dist/registrucentras-rc-ses-react-components.cjs +10 -10
- package/dist/registrucentras-rc-ses-react-components.js +4218 -3377
- package/dist/stories/components/display/AdvancedList.stories.d.ts +33 -0
- package/dist/stories/components/display/AdvancedListItem.stories.d.ts +33 -0
- package/dist/stories/components/display/SelectableCardList.stories.d.ts +8 -1
- package/dist/stories/components/display/Tooltip.stories.d.ts +48 -0
- package/dist/stories/components/loaders/LoadingSpinner.stories.d.ts +3 -3
- package/dist/theme/light/MuiTooltip.d.ts +3 -0
- package/dist/theme/motion.d.ts +16 -0
- package/package.json +1 -1
- package/src/assets/icons/CaretUpBoldIcon.tsx +17 -0
- package/src/assets/icons/CaretUpIcon.tsx +9 -0
- package/src/assets/icons/ListIcon.tsx +17 -0
- package/src/assets/icons/MinusIcon.tsx +9 -0
- package/src/assets/icons/NotePencilIcon.tsx +9 -0
- package/src/assets/icons/PlusIcon.tsx +9 -0
- package/src/assets/icons/TrashIcon.tsx +23 -0
- package/src/assets/icons/UserIcon.tsx +17 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/AdvancedListItem.types.ts +100 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemLeading.tsx +214 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/components/AdvancedListItemTrailing.tsx +241 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.test.ts +80 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/hooks/usePrefersReducedMotion.ts +28 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.test.tsx +631 -0
- package/src/components/common/AdvancedList/components/AdvancedListItem/index.tsx +329 -0
- package/src/components/common/AdvancedList/index.test.tsx +97 -0
- package/src/components/common/AdvancedList/index.tsx +52 -0
- package/src/components/common/ListWithIcons/components/ListWithIconsItem.tsx +7 -5
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.test.tsx +50 -0
- package/src/components/common/SelectableCardList/components/SelectableCardListItem.tsx +34 -0
- package/src/components/common/SelectableCardList/index.test.tsx +56 -2
- package/src/components/common/SelectableCardList/index.tsx +29 -10
- package/src/components/common/Tooltip/index.test.tsx +85 -0
- package/src/components/common/Tooltip/index.tsx +167 -0
- package/src/components/form/inputs/FileDropzone.tsx +1 -0
- package/src/components/form/inputs/FileUpload.tsx +1 -0
- package/src/components/form/inputs/NumberStepper.tsx +1 -0
- package/src/components/form/inputs/RadioButtonGroup.test.tsx +71 -0
- package/src/components/form/inputs/RadioButtonGroup.tsx +1 -0
- package/src/components/form/inputs/Select/index.test.tsx +159 -0
- package/src/components/form/inputs/Select/index.tsx +109 -53
- package/src/i18n/namespaces/common/en.json +14 -0
- package/src/i18n/namespaces/common/lt.json +14 -0
- package/src/library/icons.ts +16 -0
- package/src/library/index.ts +5 -0
- package/src/library/types.ts +2 -0
- package/src/setupTests.ts +7 -1
- package/src/stories/components/display/AdvancedList.stories.tsx +660 -0
- package/src/stories/components/display/AdvancedListItem.stories.tsx +593 -0
- package/src/stories/components/display/SelectableCardList.stories.tsx +19 -0
- package/src/stories/components/display/Tooltip.stories.tsx +67 -0
- package/src/stories/components/inputs/Select.stories.tsx +38 -2
- package/src/theme/light/MuiAutocomplete.ts +3 -1
- package/src/theme/light/MuiInputBase.ts +4 -0
- package/src/theme/light/MuiTooltip.ts +40 -0
- package/src/theme/light/index.tsx +2 -0
- package/src/theme/motion.tsx +10 -0
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
import { ThemeProvider } from '@mui/material/styles'
|
|
2
|
+
import { fireEvent, render, screen, within } from '@testing-library/react'
|
|
3
|
+
import { type ReactElement, useState } from 'react'
|
|
4
|
+
import { describe, expect, test, vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
import NotePencilIcon from '@/assets/icons/NotePencilIcon'
|
|
7
|
+
import PencilSimpleLineIcon from '@/assets/icons/PencilSimpleLineIcon'
|
|
8
|
+
import TrashIcon from '@/assets/icons/TrashIcon'
|
|
9
|
+
import theme from '@/theme/light'
|
|
10
|
+
|
|
11
|
+
import AdvancedListItem from './index'
|
|
12
|
+
|
|
13
|
+
const renderItem = (ui: ReactElement) =>
|
|
14
|
+
render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>)
|
|
15
|
+
|
|
16
|
+
describe('AdvancedListItem', () => {
|
|
17
|
+
test('renders title and subtitle', () => {
|
|
18
|
+
renderItem(<AdvancedListItem title='Main title' subtitle='Some subtitle' />)
|
|
19
|
+
|
|
20
|
+
expect(screen.getByText('Main title')).toBeInTheDocument()
|
|
21
|
+
expect(screen.getByText('Some subtitle')).toBeInTheDocument()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('renders label pill when provided', () => {
|
|
25
|
+
renderItem(<AdvancedListItem title='Title' label='Label' />)
|
|
26
|
+
|
|
27
|
+
expect(screen.getByText('Label')).toBeInTheDocument()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('renders meta items via ListWithIcons', () => {
|
|
31
|
+
renderItem(
|
|
32
|
+
<AdvancedListItem
|
|
33
|
+
title='Title'
|
|
34
|
+
metaItems={[{ text: 'Meta info 1' }, { text: 'Meta info 2' }]}
|
|
35
|
+
/>,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
expect(screen.getByText('Meta info 1')).toBeInTheDocument()
|
|
39
|
+
expect(screen.getByText('Meta info 2')).toBeInTheDocument()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
describe('leading: radio', () => {
|
|
43
|
+
test('renders and calls onChange without bubbling to root onClick', () => {
|
|
44
|
+
const onChange = vi.fn()
|
|
45
|
+
const onClick = vi.fn()
|
|
46
|
+
|
|
47
|
+
renderItem(
|
|
48
|
+
<AdvancedListItem
|
|
49
|
+
title='Savininkas juridinis asmuo'
|
|
50
|
+
onClick={onClick}
|
|
51
|
+
leading={{ type: 'radio', checked: false, onChange }}
|
|
52
|
+
/>,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
fireEvent.click(screen.getByRole('radio'))
|
|
56
|
+
|
|
57
|
+
expect(onChange).toHaveBeenCalledWith(true)
|
|
58
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('leading accessible name', () => {
|
|
63
|
+
test('radio with no explicit aria-label is labelled by the item title', () => {
|
|
64
|
+
renderItem(
|
|
65
|
+
<AdvancedListItem
|
|
66
|
+
title='Savininkas juridinis asmuo'
|
|
67
|
+
leading={{ type: 'radio', checked: false, onChange: () => {} }}
|
|
68
|
+
/>,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
expect(
|
|
72
|
+
screen.getByRole('radio', { name: 'Savininkas juridinis asmuo' }),
|
|
73
|
+
).toBeInTheDocument()
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('checkbox with no explicit aria-label is labelled by the item title', () => {
|
|
77
|
+
renderItem(
|
|
78
|
+
<AdvancedListItem
|
|
79
|
+
title='Nekilnojamasis daiktas'
|
|
80
|
+
leading={{ type: 'checkbox', checked: false, onChange: () => {} }}
|
|
81
|
+
/>,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
expect(
|
|
85
|
+
screen.getByRole('checkbox', { name: 'Nekilnojamasis daiktas' }),
|
|
86
|
+
).toBeInTheDocument()
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
test('explicit aria-label overrides the title-based label', () => {
|
|
90
|
+
renderItem(
|
|
91
|
+
<AdvancedListItem
|
|
92
|
+
title='Savininkas juridinis asmuo'
|
|
93
|
+
leading={{
|
|
94
|
+
type: 'radio',
|
|
95
|
+
checked: false,
|
|
96
|
+
onChange: () => {},
|
|
97
|
+
'aria-label': 'Pasirinkti savininko tipą',
|
|
98
|
+
}}
|
|
99
|
+
/>,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
const radio = screen.getByRole('radio', { name: 'Pasirinkti savininko tipą' })
|
|
103
|
+
expect(radio).not.toHaveAttribute('aria-labelledby')
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
describe('leading: reorder (Įgaliotojai preset)', () => {
|
|
108
|
+
test('calls onMoveUp/onMoveDown and does not bubble to root onClick', () => {
|
|
109
|
+
const onMoveUp = vi.fn()
|
|
110
|
+
const onMoveDown = vi.fn()
|
|
111
|
+
const onClick = vi.fn()
|
|
112
|
+
|
|
113
|
+
renderItem(
|
|
114
|
+
<AdvancedListItem
|
|
115
|
+
title='Jonas Jonaitis'
|
|
116
|
+
onClick={onClick}
|
|
117
|
+
leading={{ type: 'reorder', onMoveUp, onMoveDown }}
|
|
118
|
+
/>,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
fireEvent.click(screen.getByRole('button', { name: 'Perkelti aukštyn' }))
|
|
122
|
+
fireEvent.click(screen.getByRole('button', { name: 'Perkelti žemyn' }))
|
|
123
|
+
|
|
124
|
+
expect(onMoveUp).toHaveBeenCalledTimes(1)
|
|
125
|
+
expect(onMoveDown).toHaveBeenCalledTimes(1)
|
|
126
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('respects moveUpDisabled/moveDownDisabled', () => {
|
|
130
|
+
renderItem(
|
|
131
|
+
<AdvancedListItem
|
|
132
|
+
title='Jonas Jonaitis'
|
|
133
|
+
leading={{
|
|
134
|
+
type: 'reorder',
|
|
135
|
+
onMoveUp: () => {},
|
|
136
|
+
onMoveDown: () => {},
|
|
137
|
+
moveUpDisabled: true,
|
|
138
|
+
moveDownDisabled: true,
|
|
139
|
+
}}
|
|
140
|
+
/>,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
expect(screen.getByRole('button', { name: 'Perkelti aukštyn' })).toBeDisabled()
|
|
144
|
+
expect(screen.getByRole('button', { name: 'Perkelti žemyn' })).toBeDisabled()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('omits a direction entirely when its handler is not provided (Reorder-up/Reorder-down variants)', () => {
|
|
148
|
+
renderItem(
|
|
149
|
+
<AdvancedListItem
|
|
150
|
+
title='Jonas Jonaitis'
|
|
151
|
+
leading={{ type: 'reorder', onMoveUp: () => {} }}
|
|
152
|
+
/>,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
expect(screen.getByRole('button', { name: 'Perkelti aukštyn' })).toBeInTheDocument()
|
|
156
|
+
expect(
|
|
157
|
+
screen.queryByRole('button', { name: 'Perkelti žemyn' }),
|
|
158
|
+
).not.toBeInTheDocument()
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe('leading: drag / icon / avatar / index (decorative selector variants)', () => {
|
|
163
|
+
test('drag renders a non-interactive handle', () => {
|
|
164
|
+
renderItem(<AdvancedListItem title='Title' leading={{ type: 'drag' }} />)
|
|
165
|
+
|
|
166
|
+
expect(screen.queryByRole('button')).not.toBeInTheDocument()
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test('icon renders the provided icon component', () => {
|
|
170
|
+
const { container } = renderItem(
|
|
171
|
+
<AdvancedListItem
|
|
172
|
+
title='Title'
|
|
173
|
+
leading={{ type: 'icon', icon: PencilSimpleLineIcon }}
|
|
174
|
+
/>,
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
expect(container.querySelector('svg')).toBeInTheDocument()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('avatar renders the provided initials', () => {
|
|
181
|
+
renderItem(
|
|
182
|
+
<AdvancedListItem title='Title' leading={{ type: 'avatar', initials: 'JP' }} />,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
expect(screen.getByText('JP')).toBeInTheDocument()
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
test('index renders the provided number', () => {
|
|
189
|
+
renderItem(<AdvancedListItem title='Title' leading={{ type: 'index', index: 3 }} />)
|
|
190
|
+
|
|
191
|
+
expect(screen.getByText('3')).toBeInTheDocument()
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
test('a decorative leading control does not block the card itself from being keyboard-focusable', () => {
|
|
195
|
+
const onClick = vi.fn()
|
|
196
|
+
renderItem(
|
|
197
|
+
<AdvancedListItem
|
|
198
|
+
title='Title'
|
|
199
|
+
onClick={onClick}
|
|
200
|
+
leading={{ type: 'avatar', initials: 'JP' }}
|
|
201
|
+
/>,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
const root = screen.getByRole('button', { name: /Title/ })
|
|
205
|
+
fireEvent.keyDown(root, { key: 'Enter' })
|
|
206
|
+
|
|
207
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
208
|
+
})
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
describe('trailing: actions (Įgaliotojai preset)', () => {
|
|
212
|
+
test('renders Keisti/Pašalinti and calls their handlers without bubbling', () => {
|
|
213
|
+
const onEdit = vi.fn()
|
|
214
|
+
const onDelete = vi.fn()
|
|
215
|
+
const onClick = vi.fn()
|
|
216
|
+
|
|
217
|
+
renderItem(
|
|
218
|
+
<AdvancedListItem
|
|
219
|
+
title='Jonas Jonaitis'
|
|
220
|
+
onClick={onClick}
|
|
221
|
+
trailing={{
|
|
222
|
+
type: 'actions',
|
|
223
|
+
actions: [
|
|
224
|
+
{ label: 'Keisti', icon: NotePencilIcon, onClick: onEdit },
|
|
225
|
+
{ label: 'Pašalinti', icon: TrashIcon, onClick: onDelete },
|
|
226
|
+
],
|
|
227
|
+
}}
|
|
228
|
+
/>,
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
fireEvent.click(screen.getByRole('button', { name: 'Keisti' }))
|
|
232
|
+
fireEvent.click(screen.getByRole('button', { name: 'Pašalinti' }))
|
|
233
|
+
|
|
234
|
+
expect(onEdit).toHaveBeenCalledTimes(1)
|
|
235
|
+
expect(onDelete).toHaveBeenCalledTimes(1)
|
|
236
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
describe('trailing: toggle (JA atstovai redaguojama preset)', () => {
|
|
241
|
+
test('calls onChange without bubbling to root onClick', () => {
|
|
242
|
+
const onChange = vi.fn()
|
|
243
|
+
const onClick = vi.fn()
|
|
244
|
+
|
|
245
|
+
renderItem(
|
|
246
|
+
<AdvancedListItem
|
|
247
|
+
title='Petras Petraitis'
|
|
248
|
+
subtitle='Vadovas'
|
|
249
|
+
onClick={onClick}
|
|
250
|
+
trailing={{ type: 'toggle', checked: false, onChange }}
|
|
251
|
+
/>,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
fireEvent.click(screen.getByRole('switch'))
|
|
255
|
+
|
|
256
|
+
expect(onChange).toHaveBeenCalledWith(true)
|
|
257
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
258
|
+
})
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
describe('trailing: status (JA atstovai peržiūra preset)', () => {
|
|
262
|
+
test('renders the status label', () => {
|
|
263
|
+
renderItem(
|
|
264
|
+
<AdvancedListItem
|
|
265
|
+
title='Ona Onaitė'
|
|
266
|
+
subtitle='a.k. 3850.........'
|
|
267
|
+
trailing={{ type: 'status', label: 'Laukiama parašo', color: 'warning' }}
|
|
268
|
+
/>,
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
expect(screen.getByText('Laukiama parašo')).toBeInTheDocument()
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
describe('leading: checkbox + selected state (Pasirenkamas sąrašas preset)', () => {
|
|
276
|
+
test('calls onChange without bubbling and reflects checked state', () => {
|
|
277
|
+
const onChange = vi.fn()
|
|
278
|
+
const onClick = vi.fn()
|
|
279
|
+
|
|
280
|
+
renderItem(
|
|
281
|
+
<AdvancedListItem
|
|
282
|
+
title='Nekilnojamasis daiktas'
|
|
283
|
+
subtitle='Unikalus Nr. 4400.....'
|
|
284
|
+
state='selected'
|
|
285
|
+
onClick={onClick}
|
|
286
|
+
leading={{ type: 'checkbox', checked: true, onChange }}
|
|
287
|
+
/>,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
const checkbox = screen.getByRole('checkbox')
|
|
291
|
+
expect(checkbox).toBeChecked()
|
|
292
|
+
|
|
293
|
+
fireEvent.click(checkbox)
|
|
294
|
+
|
|
295
|
+
expect(onChange).toHaveBeenCalledWith(false)
|
|
296
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
297
|
+
})
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
describe('leadingMedia (avatar + checkbox people list)', () => {
|
|
301
|
+
test('renders alongside the leading selector without replacing it', () => {
|
|
302
|
+
renderItem(
|
|
303
|
+
<AdvancedListItem
|
|
304
|
+
title='Petras Petraitis'
|
|
305
|
+
leadingMedia={<span data-testid='avatar'>PP</span>}
|
|
306
|
+
leading={{ type: 'checkbox', checked: false, onChange: () => {} }}
|
|
307
|
+
/>,
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
expect(screen.getByTestId('avatar')).toBeInTheDocument()
|
|
311
|
+
expect(screen.getByRole('checkbox')).toBeInTheDocument()
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
test('omitted by default: absent leadingMedia renders nothing extra', () => {
|
|
315
|
+
renderItem(<AdvancedListItem title='No media' />)
|
|
316
|
+
|
|
317
|
+
expect(screen.queryByTestId('avatar')).not.toBeInTheDocument()
|
|
318
|
+
})
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
describe('trailing: price (Krepšelis preset)', () => {
|
|
322
|
+
test('renders amount and caption', () => {
|
|
323
|
+
renderItem(
|
|
324
|
+
<AdvancedListItem
|
|
325
|
+
title='NTR išrašas (objekto)'
|
|
326
|
+
subtitle='Elektroninis dokumentas (PDF)'
|
|
327
|
+
trailing={{ type: 'price', amount: '12,00 €', caption: 'su PVM' }}
|
|
328
|
+
/>,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
expect(screen.getByText('12,00 €')).toBeInTheDocument()
|
|
332
|
+
expect(screen.getByText('su PVM')).toBeInTheDocument()
|
|
333
|
+
})
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
describe('accessibility', () => {
|
|
337
|
+
test('root is not exposed as role=button when it has nested interactive controls, even with onClick set', () => {
|
|
338
|
+
const onClick = vi.fn()
|
|
339
|
+
|
|
340
|
+
const { container } = renderItem(
|
|
341
|
+
<AdvancedListItem
|
|
342
|
+
title='Jonas Jonaitis'
|
|
343
|
+
onClick={onClick}
|
|
344
|
+
trailing={{
|
|
345
|
+
type: 'actions',
|
|
346
|
+
actions: [{ label: 'Keisti', onClick: () => {} }],
|
|
347
|
+
}}
|
|
348
|
+
/>,
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
const root = container.firstElementChild as HTMLElement
|
|
352
|
+
expect(root.getAttribute('role')).not.toBe('button')
|
|
353
|
+
expect(root).not.toHaveAttribute('tabindex')
|
|
354
|
+
expect(screen.getByRole('button', { name: 'Keisti' })).toBeInTheDocument()
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
describe('states', () => {
|
|
359
|
+
test('disabled state blocks root onClick and marks aria-disabled', () => {
|
|
360
|
+
const onClick = vi.fn()
|
|
361
|
+
|
|
362
|
+
const { container } = renderItem(
|
|
363
|
+
<AdvancedListItem title='Disabled item' state='disabled' onClick={onClick} />,
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
const root = container.firstElementChild as HTMLElement
|
|
367
|
+
expect(root).toHaveAttribute('aria-disabled', 'true')
|
|
368
|
+
expect(root).toHaveStyle('pointer-events: none')
|
|
369
|
+
expect(root.getAttribute('role')).not.toBe('button')
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
test('clickable root is reachable via keyboard and role=button', () => {
|
|
373
|
+
const onClick = vi.fn()
|
|
374
|
+
|
|
375
|
+
renderItem(<AdvancedListItem title='Clickable item' onClick={onClick} />)
|
|
376
|
+
|
|
377
|
+
const root = screen.getByRole('button', { name: /Clickable item/ })
|
|
378
|
+
fireEvent.keyDown(root, { key: 'Enter' })
|
|
379
|
+
|
|
380
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
381
|
+
})
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
describe('layout', () => {
|
|
385
|
+
test('root always uses the standard border radius (Radius aliases/List-item)', () => {
|
|
386
|
+
const { container } = renderItem(<AdvancedListItem title='Item' />)
|
|
387
|
+
|
|
388
|
+
const root = container.firstElementChild as HTMLElement
|
|
389
|
+
expect(root).toHaveStyle('border-radius: 0.5rem')
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
test('selected state emphasizes via box-shadow, not a wider border (no sibling layout shift)', () => {
|
|
393
|
+
const { container: restContainer } = renderItem(
|
|
394
|
+
<AdvancedListItem title='Rest item' state='rest' />,
|
|
395
|
+
)
|
|
396
|
+
const { container: selectedContainer } = renderItem(
|
|
397
|
+
<AdvancedListItem title='Selected item' state='selected' />,
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
const restRoot = restContainer.firstElementChild as HTMLElement
|
|
401
|
+
const selectedRoot = selectedContainer.firstElementChild as HTMLElement
|
|
402
|
+
|
|
403
|
+
// Border width must stay identical across states — animating it would grow/shrink the
|
|
404
|
+
// item's rendered height and shift every sibling below it in the list.
|
|
405
|
+
expect(restRoot).toHaveStyle('border-width: 0.0625rem')
|
|
406
|
+
expect(selectedRoot).toHaveStyle('border-width: 0.0625rem')
|
|
407
|
+
|
|
408
|
+
// The emphasis instead comes from box-shadow, which doesn't participate in layout.
|
|
409
|
+
expect(restRoot).toHaveStyle('box-shadow: none')
|
|
410
|
+
expect(selectedRoot).toHaveStyle('box-shadow: 0 0 0 0.0625rem #06a0d4')
|
|
411
|
+
})
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
describe('expanded slot (GRM-12030 Phase 5)', () => {
|
|
415
|
+
test('empty expanded slot: behaves like a plain card, no aria-expanded on the selector', () => {
|
|
416
|
+
renderItem(
|
|
417
|
+
<AdvancedListItem
|
|
418
|
+
title='Title'
|
|
419
|
+
leading={{ type: 'radio', checked: true, onChange: () => {} }}
|
|
420
|
+
/>,
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
expect(screen.getByRole('radio')).not.toHaveAttribute('aria-expanded')
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
test('radio leading + expandedContent: wires aria-expanded/aria-controls to the content region', () => {
|
|
427
|
+
renderItem(
|
|
428
|
+
<AdvancedListItem
|
|
429
|
+
title='Savininkas juridinis asmuo'
|
|
430
|
+
leading={{ type: 'radio', checked: true, onChange: () => {} }}
|
|
431
|
+
expanded
|
|
432
|
+
expandedContent={<div>Adreso ir įmonės laukai</div>}
|
|
433
|
+
/>,
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
const radio = screen.getByRole('radio')
|
|
437
|
+
expect(radio).toHaveAttribute('aria-expanded', 'true')
|
|
438
|
+
|
|
439
|
+
const controlsId = radio.getAttribute('aria-controls')
|
|
440
|
+
expect(controlsId).toBeTruthy()
|
|
441
|
+
expect(document.getElementById(controlsId as string)).toHaveTextContent(
|
|
442
|
+
'Adreso ir įmonės laukai',
|
|
443
|
+
)
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
test('checkbox leading + expandedContent: same aria wiring, reflects collapsed state', () => {
|
|
447
|
+
renderItem(
|
|
448
|
+
<AdvancedListItem
|
|
449
|
+
title='Title'
|
|
450
|
+
leading={{ type: 'checkbox', checked: true, onChange: () => {} }}
|
|
451
|
+
expanded={false}
|
|
452
|
+
expandedContent={<div>Details</div>}
|
|
453
|
+
/>,
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
expect(screen.getByRole('checkbox')).toHaveAttribute('aria-expanded', 'false')
|
|
457
|
+
})
|
|
458
|
+
|
|
459
|
+
test('selecting the leading control calls both its own onChange and onExpandedChange', () => {
|
|
460
|
+
const onChange = vi.fn()
|
|
461
|
+
const onExpandedChange = vi.fn()
|
|
462
|
+
|
|
463
|
+
renderItem(
|
|
464
|
+
<AdvancedListItem
|
|
465
|
+
title='Title'
|
|
466
|
+
leading={{ type: 'radio', checked: false, onChange }}
|
|
467
|
+
expanded={false}
|
|
468
|
+
expandedContent={<div>Details</div>}
|
|
469
|
+
onExpandedChange={onExpandedChange}
|
|
470
|
+
/>,
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
fireEvent.click(screen.getByRole('radio'))
|
|
474
|
+
|
|
475
|
+
expect(onChange).toHaveBeenCalledWith(true)
|
|
476
|
+
expect(onExpandedChange).toHaveBeenCalledWith(true)
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
test('collapsed content values are preserved across collapse/expand (stays mounted)', () => {
|
|
480
|
+
const Wrapper = () => {
|
|
481
|
+
const [expanded, setExpanded] = useState(true)
|
|
482
|
+
return (
|
|
483
|
+
<>
|
|
484
|
+
<button type='button' onClick={() => setExpanded((prev) => !prev)}>
|
|
485
|
+
toggle
|
|
486
|
+
</button>
|
|
487
|
+
<AdvancedListItem
|
|
488
|
+
title='Title'
|
|
489
|
+
leading={{ type: 'checkbox', checked: true, onChange: () => {} }}
|
|
490
|
+
expanded={expanded}
|
|
491
|
+
expandedContent={<input aria-label='Company name' defaultValue='' />}
|
|
492
|
+
/>
|
|
493
|
+
</>
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
renderItem(<Wrapper />)
|
|
498
|
+
|
|
499
|
+
const input = screen.getByLabelText('Company name') as HTMLInputElement
|
|
500
|
+
fireEvent.change(input, { target: { value: 'UAB Įmonė' } })
|
|
501
|
+
expect(input).toHaveValue('UAB Įmonė')
|
|
502
|
+
|
|
503
|
+
fireEvent.click(screen.getByRole('button', { name: 'toggle' })) // collapse
|
|
504
|
+
fireEvent.click(screen.getByRole('button', { name: 'toggle' })) // expand again
|
|
505
|
+
|
|
506
|
+
expect(screen.getByLabelText('Company name')).toHaveValue('UAB Įmonė')
|
|
507
|
+
})
|
|
508
|
+
|
|
509
|
+
test('focus does not jump into expandedContent automatically when expanding', () => {
|
|
510
|
+
const Wrapper = () => {
|
|
511
|
+
const [expanded, setExpanded] = useState(false)
|
|
512
|
+
return (
|
|
513
|
+
<AdvancedListItem
|
|
514
|
+
title='Title'
|
|
515
|
+
leading={{
|
|
516
|
+
type: 'radio',
|
|
517
|
+
checked: expanded,
|
|
518
|
+
onChange: () => setExpanded(true),
|
|
519
|
+
}}
|
|
520
|
+
expanded={expanded}
|
|
521
|
+
expandedContent={<input aria-label='Field' />}
|
|
522
|
+
/>
|
|
523
|
+
)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
renderItem(<Wrapper />)
|
|
527
|
+
|
|
528
|
+
const radio = screen.getByRole('radio')
|
|
529
|
+
radio.focus()
|
|
530
|
+
fireEvent.click(radio)
|
|
531
|
+
|
|
532
|
+
expect(document.activeElement).toBe(radio)
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
test('collapsing returns focus to the leading control when focus was inside the content', () => {
|
|
536
|
+
const Wrapper = () => {
|
|
537
|
+
const [expanded, setExpanded] = useState(true)
|
|
538
|
+
return (
|
|
539
|
+
<>
|
|
540
|
+
<button type='button' onClick={() => setExpanded(false)}>
|
|
541
|
+
collapse
|
|
542
|
+
</button>
|
|
543
|
+
<AdvancedListItem
|
|
544
|
+
title='Title'
|
|
545
|
+
leading={{ type: 'checkbox', checked: true, onChange: () => {} }}
|
|
546
|
+
expanded={expanded}
|
|
547
|
+
expandedContent={<input aria-label='Field' />}
|
|
548
|
+
/>
|
|
549
|
+
</>
|
|
550
|
+
)
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
renderItem(<Wrapper />)
|
|
554
|
+
|
|
555
|
+
const field = screen.getByLabelText('Field')
|
|
556
|
+
field.focus()
|
|
557
|
+
expect(document.activeElement).toBe(field)
|
|
558
|
+
|
|
559
|
+
fireEvent.click(screen.getByRole('button', { name: 'collapse' }))
|
|
560
|
+
|
|
561
|
+
expect(document.activeElement).toBe(screen.getByRole('checkbox'))
|
|
562
|
+
})
|
|
563
|
+
|
|
564
|
+
test('marks collapsed content inert so it is not reachable', () => {
|
|
565
|
+
renderItem(
|
|
566
|
+
<AdvancedListItem
|
|
567
|
+
title='Title'
|
|
568
|
+
leading={{ type: 'checkbox', checked: false, onChange: () => {} }}
|
|
569
|
+
expanded={false}
|
|
570
|
+
expandedContent={<input aria-label='Field' />}
|
|
571
|
+
/>,
|
|
572
|
+
)
|
|
573
|
+
|
|
574
|
+
const field = screen.getByLabelText('Field') as HTMLInputElement
|
|
575
|
+
const contentContainer = field.closest('[id]') as HTMLElement
|
|
576
|
+
|
|
577
|
+
// jsdom doesn't implement the `.inert` IDL property (it's always undefined there even
|
|
578
|
+
// when the attribute is present), so check the attribute directly rather than the
|
|
579
|
+
// property — this is what real browsers actually reflect it from anyway.
|
|
580
|
+
expect(contentContainer).toHaveAttribute('inert')
|
|
581
|
+
})
|
|
582
|
+
|
|
583
|
+
test('nested radio group inside expandedContent is independent of the item leading control', () => {
|
|
584
|
+
renderItem(
|
|
585
|
+
<AdvancedListItem
|
|
586
|
+
title='Title'
|
|
587
|
+
leading={{ type: 'radio', checked: true, onChange: () => {} }}
|
|
588
|
+
expanded
|
|
589
|
+
expandedContent={
|
|
590
|
+
<div role='radiogroup' aria-label='Deklaracija teikiama'>
|
|
591
|
+
<label htmlFor='declaration-yes'>
|
|
592
|
+
<input id='declaration-yes' type='radio' name='declaration' value='yes' />
|
|
593
|
+
Taip
|
|
594
|
+
</label>
|
|
595
|
+
<label htmlFor='declaration-no'>
|
|
596
|
+
<input id='declaration-no' type='radio' name='declaration' value='no' />
|
|
597
|
+
Ne
|
|
598
|
+
</label>
|
|
599
|
+
</div>
|
|
600
|
+
}
|
|
601
|
+
/>,
|
|
602
|
+
)
|
|
603
|
+
|
|
604
|
+
const nestedGroup = screen.getByRole('radiogroup', { name: 'Deklaracija teikiama' })
|
|
605
|
+
const nestedRadios = within(nestedGroup).getAllByRole('radio')
|
|
606
|
+
|
|
607
|
+
expect(nestedRadios).toHaveLength(2)
|
|
608
|
+
nestedRadios.forEach((radio) => expect(radio).not.toHaveAttribute('aria-controls'))
|
|
609
|
+
})
|
|
610
|
+
|
|
611
|
+
test('typing in a field inside expandedContent does not toggle the leading control off', () => {
|
|
612
|
+
const onChange = vi.fn()
|
|
613
|
+
|
|
614
|
+
renderItem(
|
|
615
|
+
<AdvancedListItem
|
|
616
|
+
title='Nekilnojamasis daiktas'
|
|
617
|
+
leading={{ type: 'checkbox', checked: true, onChange }}
|
|
618
|
+
expanded
|
|
619
|
+
expandedContent={<input aria-label='Laukas 1' />}
|
|
620
|
+
/>,
|
|
621
|
+
)
|
|
622
|
+
|
|
623
|
+
const field = screen.getByLabelText('Laukas 1')
|
|
624
|
+
fireEvent.click(field)
|
|
625
|
+
fireEvent.change(field, { target: { value: 'x' } })
|
|
626
|
+
|
|
627
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
628
|
+
expect(screen.getByRole('checkbox')).toBeChecked()
|
|
629
|
+
})
|
|
630
|
+
})
|
|
631
|
+
})
|