ywana-core8 0.1.102 → 0.2.1
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/index.css +4941 -324
- package/dist/index.js +42338 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +37458 -31678
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +39634 -34010
- package/dist/index.umd.js.map +1 -1
- package/package.json +26 -29
- package/src/Test.stories.jsx +28 -0
- package/src/desktop/Desktop.stories.jsx +110 -0
- package/src/desktop/WindowContext.js +135 -0
- package/src/desktop/WindowManager.js +355 -0
- package/src/desktop/desktop.css +55 -4
- package/src/desktop/desktop.js +312 -6
- package/src/desktop/index.js +7 -0
- package/src/desktop/window.css +229 -36
- package/src/desktop/window.js +254 -20
- package/src/desktop.backup/desktop.css +6 -0
- package/src/desktop.backup/desktop.js +13 -0
- package/src/desktop.backup/window.css +58 -0
- package/src/desktop.backup/window.js +27 -0
- package/src/html/Accordion.stories.jsx +178 -0
- package/src/html/Button.stories.jsx +175 -0
- package/src/html/Checkbox.stories.jsx +131 -0
- package/src/html/Chip.stories.jsx +189 -0
- package/src/html/Color.stories.jsx +234 -0
- package/src/html/Form.stories.jsx +271 -0
- package/src/html/Icon.stories.jsx +233 -0
- package/src/html/Progress.stories.jsx +247 -0
- package/src/html/Radio.stories.jsx +289 -0
- package/src/html/StyleTest.stories.jsx +81 -0
- package/src/html/Switch.stories.jsx +329 -0
- package/src/html/Tab.stories.jsx +239 -0
- package/src/html/Table.stories.jsx +188 -0
- package/src/html/Table2.stories.jsx +238 -0
- package/src/html/TextField2.stories.jsx +337 -0
- package/src/html/Tree.stories.jsx +285 -0
- package/src/html/accordion.example.js +0 -74
- package/src/html/accordion.js +1 -6
- package/src/html/button.js +2 -13
- package/src/html/checkbox.js +1 -9
- package/src/html/chip.js +2 -19
- package/src/html/color.js +1 -14
- package/src/html/form.js +4 -15
- package/src/html/header2.js +1 -12
- package/src/html/icon.js +1 -7
- package/src/html/index.js +1 -1
- package/src/html/list.js +1 -19
- package/src/html/menu.js +9 -5
- package/src/html/progress.js +5 -53
- package/src/html/property.js +6 -22
- package/src/html/radio.js +2 -16
- package/src/html/section.js +1 -6
- package/src/html/selector.js +2 -19
- package/src/html/switch.css +134 -100
- package/src/html/switch.example.js +46 -36
- package/src/html/switch.js +43 -192
- package/src/html/tab.js +3 -24
- package/src/html/text.js +1 -12
- package/src/html/textfield2.js +5 -42
- package/src/html/thumbnail.js +1 -12
- package/src/html/tokenfield.js +2 -21
- package/src/html/tree.js +3 -35
- package/src/index.js +1 -0
- package/__previewjs__/Wrapper.tsx +0 -14
- package/build-doc.sh +0 -10
- package/db/db.json +0 -89
- package/db/routes.json +0 -0
- package/dist/index.cjs +0 -36722
- package/dist/index.cjs.map +0 -1
- package/dist/index.css.map +0 -1
- package/doc/README.md +0 -196
- package/doc/evalulations/ACCORDION_EVALUATION.md +0 -583
- package/doc/evalulations/CHECKBOX_EVALUATION.md +0 -273
- package/doc/evalulations/CHIP_EVALUATION.md +0 -542
- package/doc/evalulations/COLOR_EVALUATION.md +0 -524
- package/doc/evalulations/COMPONENTS_EVALUATION.md +0 -477
- package/doc/evalulations/FORM_EVALUATION.md +0 -459
- package/doc/evalulations/HEADER_EVALUATION.md +0 -436
- package/doc/evalulations/ICON_EVALUATION.md +0 -254
- package/doc/evalulations/LIST_EVALUATION.md +0 -574
- package/doc/evalulations/PROGRESS_EVALUATION.md +0 -450
- package/doc/evalulations/RADIO_EVALUATION.md +0 -439
- package/doc/evalulations/RADIO_VISUAL_FIX.md +0 -183
- package/doc/evalulations/SECTION_IMPROVEMENTS.md +0 -153
- package/doc/evalulations/SWITCH_EVALUATION.md +0 -335
- package/doc/evalulations/SWITCH_VISUAL_FIX.md +0 -232
- package/doc/evalulations/TAB_EVALUATION.md +0 -626
- package/doc/evalulations/TEXTFIELD_EVALUATION.md +0 -747
- package/doc/evalulations/TOOLTIP_FIX.md +0 -157
- package/doc/evalulations/TREE_EVALUATION.md +0 -708
- package/doc/index.html +0 -0
- package/doc/package-lock.json +0 -17298
- package/doc/package.json +0 -34
- package/doc/public/index.html +0 -24
- package/doc/scripts/generate-examples.js +0 -129
- package/doc/src/App.css +0 -171
- package/doc/src/App.js +0 -114
- package/doc/src/components/ExamplePage.js +0 -129
- package/doc/src/components/WelcomePage.js +0 -84
- package/doc/src/index.css +0 -246
- package/doc/src/index.js +0 -17
- package/doc/src/theme.css +0 -256
- package/jest.config.js +0 -24
- package/preview.config.js +0 -38
- package/publish.sh +0 -6
- package/src/desktop/dektop.test.js +0 -11
- package/src/domain/CollectionAPI.test.js +0 -19
- package/src/domain/ContentEditor.test.js +0 -52
- package/src/domain2/CollectionAPI.test.js +0 -19
- package/src/domain2/CollectionContext.test.js +0 -71
- package/src/domain2/CollectionPage.test.js +0 -112
- package/src/domain2/DynamicForm.test.js +0 -47
- package/src/html/accordion.test.js +0 -37
- package/src/html/accordion.unit.test.js +0 -334
- package/src/html/button.example.new.js +0 -416
- package/src/html/button.test.js +0 -422
- package/src/html/checkbox.test.js +0 -285
- package/src/html/chip.test.js +0 -425
- package/src/html/color.example.js.backup +0 -527
- package/src/html/color.test.js +0 -377
- package/src/html/components.example.js.backup +0 -492
- package/src/html/components_enhanced.test.js +0 -581
- package/src/html/form.example.js.backup +0 -385
- package/src/html/form.test.js +0 -369
- package/src/html/header2.example.js.backup +0 -411
- package/src/html/header2.test.js +0 -377
- package/src/html/icon.example.js.backup +0 -268
- package/src/html/icon.test.js +0 -231
- package/src/html/label.test.js +0 -0
- package/src/html/list.example.js.backup +0 -404
- package/src/html/list.test.js +0 -383
- package/src/html/progress.example.js.backup +0 -424
- package/src/html/progress.test.js +0 -313
- package/src/html/property.example.js.backup +0 -553
- package/src/html/property.test.js +0 -371
- package/src/html/radio.example.js.backup +0 -389
- package/src/html/radio.test.js +0 -318
- package/src/html/section.example.js.backup +0 -99
- package/src/html/section.test.js +0 -131
- package/src/html/selector.test.js +0 -20
- package/src/html/switch.example.js.backup +0 -461
- package/src/html/switch.test.js +0 -355
- package/src/html/tab.example.js.backup +0 -446
- package/src/html/tab.test.js +0 -25
- package/src/html/tab_enhanced.test.js +0 -504
- package/src/html/table.test.js +0 -70
- package/src/html/table2.test.js +0 -582
- package/src/html/text.test.js +0 -15
- package/src/html/textfield.test.js +0 -51
- package/src/html/textfield2.example.js.backup +0 -1370
- package/src/html/textfield2.test.js +0 -950
- package/src/html/tokenfield.example.js.backup +0 -503
- package/src/html/tokenfield.test.js +0 -423
- package/src/html/tree.example.js.backup +0 -475
- package/src/html/tree.test.js +0 -43
- package/src/html/tree_enhanced.test.js +0 -495
- package/src/http/token.test.js +0 -50
- package/src/incubator/pdfViewer.js +0 -33
- package/src/incubator/wizard.test.js +0 -127
- package/src/site/site.test.js +0 -230
- package/src/site/view.test.js +0 -41
- package/src/widgets/calendar/Calendar.test.js +0 -28
- package/src/widgets/explorer/Explorer.test.js +0 -121
- package/src/widgets/ide/editor.test.js +0 -33
- package/src/widgets/kanban/Kanban.test.js +0 -78
- package/src/widgets/login/LoginBox.test.js +0 -12
- package/src/widgets/login/ResetPasswordBox.test.js +0 -34
- package/src/widgets/login/validations.test.js +0 -51
- package/src/widgets/planner/Planner.test.js +0 -60
- package/src/widgets/upload/Upload.test.js +0 -32
- package/table2.test.js +0 -454
@@ -1,371 +0,0 @@
|
|
1
|
-
import React, { useState } from 'react'
|
2
|
-
import { Property } from './property'
|
3
|
-
|
4
|
-
// Pruebas unitarias para el componente Property mejorado
|
5
|
-
describe('Enhanced Property Component', () => {
|
6
|
-
// Mock de los componentes dependientes
|
7
|
-
const mockIcon = jest.fn()
|
8
|
-
const mockText = jest.fn()
|
9
|
-
|
10
|
-
beforeEach(() => {
|
11
|
-
jest.clearAllMocks()
|
12
|
-
|
13
|
-
// Mock de componentes
|
14
|
-
jest.doMock('./icon', () => ({ Icon: mockIcon }))
|
15
|
-
jest.doMock('./text', () => ({ Text: mockText }))
|
16
|
-
|
17
|
-
// Mock de console.warn
|
18
|
-
jest.spyOn(console, 'warn').mockImplementation(() => {})
|
19
|
-
|
20
|
-
// Mock de navigator.clipboard
|
21
|
-
global.navigator = {
|
22
|
-
clipboard: {
|
23
|
-
writeText: jest.fn().mockResolvedValue(undefined)
|
24
|
-
}
|
25
|
-
}
|
26
|
-
})
|
27
|
-
|
28
|
-
afterEach(() => {
|
29
|
-
console.warn.mockRestore()
|
30
|
-
})
|
31
|
-
|
32
|
-
// Property Component Tests
|
33
|
-
describe('Property Component', () => {
|
34
|
-
test('component exports correctly', () => {
|
35
|
-
expect(Property).toBeDefined()
|
36
|
-
expect(typeof Property).toBe('function')
|
37
|
-
})
|
38
|
-
|
39
|
-
test('component has correct PropTypes', () => {
|
40
|
-
expect(Property.propTypes).toBeDefined()
|
41
|
-
expect(Property.propTypes.id).toBeDefined()
|
42
|
-
expect(Property.propTypes.className).toBeDefined()
|
43
|
-
expect(Property.propTypes.label).toBeDefined()
|
44
|
-
expect(Property.propTypes.name).toBeDefined()
|
45
|
-
expect(Property.propTypes.initial).toBeDefined()
|
46
|
-
expect(Property.propTypes.value).toBeDefined()
|
47
|
-
expect(Property.propTypes.editable).toBeDefined()
|
48
|
-
expect(Property.propTypes.onChange).toBeDefined()
|
49
|
-
expect(Property.propTypes.options).toBeDefined()
|
50
|
-
expect(Property.propTypes.type).toBeDefined()
|
51
|
-
expect(Property.propTypes.disabled).toBeDefined()
|
52
|
-
expect(Property.propTypes.required).toBeDefined()
|
53
|
-
expect(Property.propTypes.multiline).toBeDefined()
|
54
|
-
expect(Property.propTypes.validateValue).toBeDefined()
|
55
|
-
})
|
56
|
-
|
57
|
-
test('component has correct defaultProps', () => {
|
58
|
-
expect(Property.defaultProps).toBeDefined()
|
59
|
-
expect(Property.defaultProps.editable).toBe(false)
|
60
|
-
expect(Property.defaultProps.type).toBe('text')
|
61
|
-
expect(Property.defaultProps.disabled).toBe(false)
|
62
|
-
expect(Property.defaultProps.required).toBe(false)
|
63
|
-
expect(Property.defaultProps.multiline).toBe(false)
|
64
|
-
expect(Property.defaultProps.rows).toBe(3)
|
65
|
-
expect(Property.defaultProps.size).toBe('medium')
|
66
|
-
expect(Property.defaultProps.variant).toBe('default')
|
67
|
-
expect(Property.defaultProps.layout).toBe('horizontal')
|
68
|
-
expect(Property.defaultProps.nameWidth).toBe('50%')
|
69
|
-
expect(Property.defaultProps.copyable).toBe(false)
|
70
|
-
expect(Property.defaultProps.clearable).toBe(true)
|
71
|
-
})
|
72
|
-
|
73
|
-
test('validates props correctly', () => {
|
74
|
-
const validateProps = (options) => {
|
75
|
-
if (options && !Array.isArray(options)) {
|
76
|
-
console.warn('Property: options prop must be an array')
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
// Invalid options prop
|
81
|
-
validateProps('not an array')
|
82
|
-
expect(console.warn).toHaveBeenCalledWith('Property: options prop must be an array')
|
83
|
-
|
84
|
-
console.warn.mockClear()
|
85
|
-
|
86
|
-
// Valid options prop
|
87
|
-
validateProps([{ label: 'Option 1', value: '1' }])
|
88
|
-
expect(console.warn).not.toHaveBeenCalled()
|
89
|
-
|
90
|
-
// Null options (valid)
|
91
|
-
validateProps(null)
|
92
|
-
expect(console.warn).not.toHaveBeenCalled()
|
93
|
-
})
|
94
|
-
|
95
|
-
test('validates value correctly', () => {
|
96
|
-
const validateValueFunc = (val, required, minLength, maxLength, pattern, validateValue) => {
|
97
|
-
if (!val && required) {
|
98
|
-
return { isValid: false, error: 'This field is required' }
|
99
|
-
}
|
100
|
-
|
101
|
-
if (val && minLength && val.length < minLength) {
|
102
|
-
return { isValid: false, error: `Minimum ${minLength} characters required` }
|
103
|
-
}
|
104
|
-
|
105
|
-
if (val && maxLength && val.length > maxLength) {
|
106
|
-
return { isValid: false, error: `Maximum ${maxLength} characters allowed` }
|
107
|
-
}
|
108
|
-
|
109
|
-
if (val && pattern) {
|
110
|
-
const regex = new RegExp(pattern)
|
111
|
-
if (!regex.test(val)) {
|
112
|
-
return { isValid: false, error: 'Invalid format' }
|
113
|
-
}
|
114
|
-
}
|
115
|
-
|
116
|
-
if (validateValue) {
|
117
|
-
const customValidation = validateValue(val)
|
118
|
-
if (customValidation && !customValidation.isValid) {
|
119
|
-
return customValidation
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
return { isValid: true }
|
124
|
-
}
|
125
|
-
|
126
|
-
// Required field empty
|
127
|
-
expect(validateValueFunc('', true, null, null, null, null))
|
128
|
-
.toEqual({ isValid: false, error: 'This field is required' })
|
129
|
-
|
130
|
-
// Min length validation
|
131
|
-
expect(validateValueFunc('ab', false, 3, null, null, null))
|
132
|
-
.toEqual({ isValid: false, error: 'Minimum 3 characters required' })
|
133
|
-
|
134
|
-
// Max length validation
|
135
|
-
expect(validateValueFunc('abcdef', false, null, 5, null, null))
|
136
|
-
.toEqual({ isValid: false, error: 'Maximum 5 characters allowed' })
|
137
|
-
|
138
|
-
// Pattern validation
|
139
|
-
expect(validateValueFunc('invalid', false, null, null, '^[0-9]+$', null))
|
140
|
-
.toEqual({ isValid: false, error: 'Invalid format' })
|
141
|
-
|
142
|
-
// Custom validation
|
143
|
-
const customValidator = () => ({ isValid: false, error: 'Custom error' })
|
144
|
-
expect(validateValueFunc('test', false, null, null, null, customValidator))
|
145
|
-
.toEqual({ isValid: false, error: 'Custom error' })
|
146
|
-
|
147
|
-
// Valid value
|
148
|
-
expect(validateValueFunc('valid', false, null, null, null, null))
|
149
|
-
.toEqual({ isValid: true })
|
150
|
-
})
|
151
|
-
|
152
|
-
test('handles change correctly', () => {
|
153
|
-
const mockOnChange = jest.fn()
|
154
|
-
const mockOnValidationError = jest.fn()
|
155
|
-
|
156
|
-
const change = (event, disabled, readOnly, validateValueFunc, onValidationError, onChange, id) => {
|
157
|
-
if (disabled || readOnly) return
|
158
|
-
|
159
|
-
const newValue = event.target.value
|
160
|
-
|
161
|
-
// Validate value
|
162
|
-
const validation = validateValueFunc(newValue)
|
163
|
-
|
164
|
-
if (!validation.isValid && onValidationError) {
|
165
|
-
onValidationError(validation.error, newValue)
|
166
|
-
}
|
167
|
-
|
168
|
-
if (onChange) {
|
169
|
-
onChange(id, newValue)
|
170
|
-
}
|
171
|
-
}
|
172
|
-
|
173
|
-
const mockEvent = { target: { value: 'new value' } }
|
174
|
-
const mockValidateFunc = jest.fn().mockReturnValue({ isValid: true })
|
175
|
-
|
176
|
-
// Normal change
|
177
|
-
change(mockEvent, false, false, mockValidateFunc, mockOnValidationError, mockOnChange, 'prop1')
|
178
|
-
expect(mockOnChange).toHaveBeenCalledWith('prop1', 'new value')
|
179
|
-
expect(mockValidateFunc).toHaveBeenCalledWith('new value')
|
180
|
-
|
181
|
-
mockOnChange.mockClear()
|
182
|
-
|
183
|
-
// Disabled change
|
184
|
-
change(mockEvent, true, false, mockValidateFunc, mockOnValidationError, mockOnChange, 'prop1')
|
185
|
-
expect(mockOnChange).not.toHaveBeenCalled()
|
186
|
-
|
187
|
-
// ReadOnly change
|
188
|
-
change(mockEvent, false, true, mockValidateFunc, mockOnValidationError, mockOnChange, 'prop1')
|
189
|
-
expect(mockOnChange).not.toHaveBeenCalled()
|
190
|
-
|
191
|
-
// Validation error
|
192
|
-
const mockValidateFuncError = jest.fn().mockReturnValue({ isValid: false, error: 'Validation error' })
|
193
|
-
change(mockEvent, false, false, mockValidateFuncError, mockOnValidationError, mockOnChange, 'prop1')
|
194
|
-
expect(mockOnValidationError).toHaveBeenCalledWith('Validation error', 'new value')
|
195
|
-
})
|
196
|
-
|
197
|
-
test('handles clear correctly', () => {
|
198
|
-
const mockOnChange = jest.fn()
|
199
|
-
|
200
|
-
const clear = (disabled, readOnly, onChange, id) => {
|
201
|
-
if (disabled || readOnly) return
|
202
|
-
|
203
|
-
if (onChange) onChange(id, "")
|
204
|
-
}
|
205
|
-
|
206
|
-
// Normal clear
|
207
|
-
clear(false, false, mockOnChange, 'prop1')
|
208
|
-
expect(mockOnChange).toHaveBeenCalledWith('prop1', '')
|
209
|
-
|
210
|
-
mockOnChange.mockClear()
|
211
|
-
|
212
|
-
// Disabled clear
|
213
|
-
clear(true, false, mockOnChange, 'prop1')
|
214
|
-
expect(mockOnChange).not.toHaveBeenCalled()
|
215
|
-
|
216
|
-
// ReadOnly clear
|
217
|
-
clear(false, true, mockOnChange, 'prop1')
|
218
|
-
expect(mockOnChange).not.toHaveBeenCalled()
|
219
|
-
})
|
220
|
-
|
221
|
-
test('handles copy correctly', async () => {
|
222
|
-
const handleCopy = async (copyable, value) => {
|
223
|
-
if (!copyable || !value) return
|
224
|
-
|
225
|
-
try {
|
226
|
-
await navigator.clipboard.writeText(value)
|
227
|
-
} catch (error) {
|
228
|
-
console.warn('Failed to copy property value:', error)
|
229
|
-
}
|
230
|
-
}
|
231
|
-
|
232
|
-
// Normal copy
|
233
|
-
await handleCopy(true, 'test value')
|
234
|
-
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('test value')
|
235
|
-
|
236
|
-
navigator.clipboard.writeText.mockClear()
|
237
|
-
|
238
|
-
// Copy disabled
|
239
|
-
await handleCopy(false, 'test value')
|
240
|
-
expect(navigator.clipboard.writeText).not.toHaveBeenCalled()
|
241
|
-
|
242
|
-
// Empty value
|
243
|
-
await handleCopy(true, '')
|
244
|
-
expect(navigator.clipboard.writeText).not.toHaveBeenCalled()
|
245
|
-
})
|
246
|
-
|
247
|
-
test('processes value with options correctly', () => {
|
248
|
-
const processValue = (value, initial, options) => {
|
249
|
-
let value2 = value || initial || ''
|
250
|
-
|
251
|
-
if (options && Array.isArray(options)) {
|
252
|
-
const opt = options.find(option => option.value == value2)
|
253
|
-
if (opt) value2 = opt.label
|
254
|
-
}
|
255
|
-
|
256
|
-
return value2
|
257
|
-
}
|
258
|
-
|
259
|
-
const options = [
|
260
|
-
{ label: 'Option One', value: '1' },
|
261
|
-
{ label: 'Option Two', value: '2' }
|
262
|
-
]
|
263
|
-
|
264
|
-
// Value with options
|
265
|
-
expect(processValue('1', '', options)).toBe('Option One')
|
266
|
-
expect(processValue('2', '', options)).toBe('Option Two')
|
267
|
-
|
268
|
-
// Value not in options
|
269
|
-
expect(processValue('3', '', options)).toBe('3')
|
270
|
-
|
271
|
-
// No options
|
272
|
-
expect(processValue('test', '', null)).toBe('test')
|
273
|
-
|
274
|
-
// Initial value
|
275
|
-
expect(processValue('', 'initial', options)).toBe('initial')
|
276
|
-
|
277
|
-
// Empty value and initial
|
278
|
-
expect(processValue('', '', options)).toBe('')
|
279
|
-
})
|
280
|
-
|
281
|
-
test('generates CSS classes correctly', () => {
|
282
|
-
const generateClasses = (id, size, variant, layout, disabled, readOnly, required, isFocused, error, isValid, loading, skeleton, copyable, className) => {
|
283
|
-
return [
|
284
|
-
'property',
|
285
|
-
`property-${id}`,
|
286
|
-
`property--${size}`,
|
287
|
-
`property--${variant}`,
|
288
|
-
`property--${layout}`,
|
289
|
-
disabled && 'property--disabled',
|
290
|
-
readOnly && 'property--readonly',
|
291
|
-
required && 'property--required',
|
292
|
-
isFocused && 'property--focused',
|
293
|
-
error && 'property--error',
|
294
|
-
!isValid && 'property--invalid',
|
295
|
-
loading && 'property--loading',
|
296
|
-
skeleton && 'property--skeleton',
|
297
|
-
copyable && 'property--copyable',
|
298
|
-
className
|
299
|
-
].filter(Boolean).join(' ')
|
300
|
-
}
|
301
|
-
|
302
|
-
expect(generateClasses('prop1', 'medium', 'default', 'horizontal', false, false, false, false, null, true, false, false, false, ''))
|
303
|
-
.toBe('property property-prop1 property--medium property--default property--horizontal')
|
304
|
-
|
305
|
-
expect(generateClasses('prop2', 'large', 'outlined', 'vertical', true, true, true, true, 'Error', false, true, true, true, 'custom'))
|
306
|
-
.toBe('property property-prop2 property--large property--outlined property--vertical property--disabled property--readonly property--required property--focused property--error property--invalid property--loading property--skeleton property--copyable custom')
|
307
|
-
})
|
308
|
-
|
309
|
-
test('handles keyboard events correctly', () => {
|
310
|
-
const handleKeyDown = (event, multiline, inputRef) => {
|
311
|
-
if (event.key === 'Enter' && !multiline) {
|
312
|
-
event.preventDefault()
|
313
|
-
if (inputRef.current) inputRef.current.blur()
|
314
|
-
}
|
315
|
-
|
316
|
-
if (event.key === 'Escape') {
|
317
|
-
if (inputRef.current) inputRef.current.blur()
|
318
|
-
}
|
319
|
-
}
|
320
|
-
|
321
|
-
const mockEvent = {
|
322
|
-
preventDefault: jest.fn(),
|
323
|
-
key: 'Enter'
|
324
|
-
}
|
325
|
-
const mockInputRef = {
|
326
|
-
current: {
|
327
|
-
blur: jest.fn()
|
328
|
-
}
|
329
|
-
}
|
330
|
-
|
331
|
-
// Enter key (not multiline)
|
332
|
-
handleKeyDown(mockEvent, false, mockInputRef)
|
333
|
-
expect(mockEvent.preventDefault).toHaveBeenCalled()
|
334
|
-
expect(mockInputRef.current.blur).toHaveBeenCalled()
|
335
|
-
|
336
|
-
mockEvent.preventDefault.mockClear()
|
337
|
-
mockInputRef.current.blur.mockClear()
|
338
|
-
|
339
|
-
// Enter key (multiline)
|
340
|
-
handleKeyDown(mockEvent, true, mockInputRef)
|
341
|
-
expect(mockEvent.preventDefault).not.toHaveBeenCalled()
|
342
|
-
|
343
|
-
// Escape key
|
344
|
-
const escapeEvent = { ...mockEvent, key: 'Escape' }
|
345
|
-
handleKeyDown(escapeEvent, false, mockInputRef)
|
346
|
-
expect(mockInputRef.current.blur).toHaveBeenCalled()
|
347
|
-
})
|
348
|
-
})
|
349
|
-
})
|
350
|
-
|
351
|
-
// Original test component (maintaining compatibility)
|
352
|
-
const PropertyTest = () => {
|
353
|
-
const [form, setForm] = useState({
|
354
|
-
name: 'John',
|
355
|
-
address: 'Porto Colon'
|
356
|
-
})
|
357
|
-
|
358
|
-
function change(id, value) {
|
359
|
-
const next = Object.assign({}, form, { [id] : value })
|
360
|
-
setForm(next)
|
361
|
-
}
|
362
|
-
|
363
|
-
return (
|
364
|
-
<>
|
365
|
-
<Property id="name" label="Name" initial="John" value={form.name} editable={true} onChange={change}/>
|
366
|
-
<Property id="address" label="Address" initial="Porto Colon" value={form.address} editable={true} onChange={change}/>
|
367
|
-
</>
|
368
|
-
)
|
369
|
-
}
|
370
|
-
|
371
|
-
export default PropertyTest
|