ywana-core8 0.1.103 → 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 +9 -25
- 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
package/src/html/button.test.js
DELETED
@@ -1,422 +0,0 @@
|
|
1
|
-
import React from 'react'
|
2
|
-
import { Button, ActionButton } from './button'
|
3
|
-
|
4
|
-
// Pruebas unitarias para los componentes Button
|
5
|
-
describe('Button Components', () => {
|
6
|
-
// Mock de los componentes dependientes
|
7
|
-
const mockText = jest.fn()
|
8
|
-
const mockIcon = jest.fn()
|
9
|
-
|
10
|
-
beforeEach(() => {
|
11
|
-
jest.clearAllMocks()
|
12
|
-
|
13
|
-
// Mock del componente Text
|
14
|
-
jest.doMock('./text', () => ({
|
15
|
-
Text: mockText
|
16
|
-
}))
|
17
|
-
|
18
|
-
// Mock del componente Icon
|
19
|
-
jest.doMock('./icon', () => ({
|
20
|
-
Icon: mockIcon
|
21
|
-
}))
|
22
|
-
|
23
|
-
// Mock de console.warn para las pruebas
|
24
|
-
jest.spyOn(console, 'warn').mockImplementation(() => {})
|
25
|
-
})
|
26
|
-
|
27
|
-
afterEach(() => {
|
28
|
-
console.warn.mockRestore()
|
29
|
-
})
|
30
|
-
|
31
|
-
describe('Button Component', () => {
|
32
|
-
test('component exports correctly', () => {
|
33
|
-
expect(Button).toBeDefined()
|
34
|
-
expect(typeof Button).toBe('function')
|
35
|
-
})
|
36
|
-
|
37
|
-
test('component has correct PropTypes', () => {
|
38
|
-
expect(Button.propTypes).toBeDefined()
|
39
|
-
expect(Button.propTypes.id).toBeDefined()
|
40
|
-
expect(Button.propTypes.label).toBeDefined()
|
41
|
-
expect(Button.propTypes.icon).toBeDefined()
|
42
|
-
expect(Button.propTypes.action).toBeDefined()
|
43
|
-
expect(Button.propTypes.disabled).toBeDefined()
|
44
|
-
expect(Button.propTypes.loading).toBeDefined()
|
45
|
-
expect(Button.propTypes.outlined).toBeDefined()
|
46
|
-
expect(Button.propTypes.raised).toBeDefined()
|
47
|
-
expect(Button.propTypes.size).toBeDefined()
|
48
|
-
expect(Button.propTypes.type).toBeDefined()
|
49
|
-
expect(Button.propTypes.className).toBeDefined()
|
50
|
-
expect(Button.propTypes.ariaLabel).toBeDefined()
|
51
|
-
expect(Button.propTypes.onClick).toBeDefined()
|
52
|
-
})
|
53
|
-
|
54
|
-
test('component has correct defaultProps', () => {
|
55
|
-
expect(Button.defaultProps).toBeDefined()
|
56
|
-
expect(Button.defaultProps.disabled).toBe(false)
|
57
|
-
expect(Button.defaultProps.loading).toBe(false)
|
58
|
-
expect(Button.defaultProps.outlined).toBe(false)
|
59
|
-
expect(Button.defaultProps.raised).toBe(false)
|
60
|
-
expect(Button.defaultProps.size).toBe('normal')
|
61
|
-
expect(Button.defaultProps.type).toBe('button')
|
62
|
-
expect(Button.defaultProps.className).toBe('')
|
63
|
-
})
|
64
|
-
|
65
|
-
test('warns when accessibility props are missing', () => {
|
66
|
-
const validateAccessibility = (label, icon, ariaLabel) => {
|
67
|
-
if (!label && !icon && !ariaLabel) {
|
68
|
-
console.warn('Button component: label, icon, or ariaLabel prop is required for accessibility')
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
validateAccessibility(null, null, null)
|
73
|
-
expect(console.warn).toHaveBeenCalledWith('Button component: label, icon, or ariaLabel prop is required for accessibility')
|
74
|
-
|
75
|
-
console.warn.mockClear()
|
76
|
-
validateAccessibility('Test Label', null, null)
|
77
|
-
expect(console.warn).not.toHaveBeenCalled()
|
78
|
-
})
|
79
|
-
|
80
|
-
test('generates correct CSS classes for different variants', () => {
|
81
|
-
const generateClasses = (raised, outlined, size, disabled, loading, className) => {
|
82
|
-
const variant = raised ? 'raised' : outlined ? 'outlined' : 'normal'
|
83
|
-
const state = disabled ? 'disabled' : loading ? 'loading' : ''
|
84
|
-
|
85
|
-
return [
|
86
|
-
'btn',
|
87
|
-
variant,
|
88
|
-
size,
|
89
|
-
state,
|
90
|
-
className || ''
|
91
|
-
].filter(Boolean).join(' ')
|
92
|
-
}
|
93
|
-
|
94
|
-
expect(generateClasses(false, false, 'normal', false, false, '')).toBe('btn normal normal')
|
95
|
-
expect(generateClasses(true, false, 'normal', false, false, '')).toBe('btn raised normal')
|
96
|
-
expect(generateClasses(false, true, 'normal', false, false, '')).toBe('btn outlined normal')
|
97
|
-
expect(generateClasses(false, false, 'small', false, false, '')).toBe('btn normal small')
|
98
|
-
expect(generateClasses(false, false, 'normal', true, false, '')).toBe('btn normal normal disabled')
|
99
|
-
expect(generateClasses(false, false, 'normal', false, true, '')).toBe('btn normal normal loading')
|
100
|
-
expect(generateClasses(false, false, 'normal', false, false, 'custom')).toBe('btn normal normal custom')
|
101
|
-
})
|
102
|
-
|
103
|
-
test('click handler works correctly', () => {
|
104
|
-
const mockAction = jest.fn()
|
105
|
-
const mockOnClick = jest.fn()
|
106
|
-
|
107
|
-
const simulateClick = (disabled, loading, action, onClick, type) => {
|
108
|
-
const event = {
|
109
|
-
stopPropagation: jest.fn(),
|
110
|
-
preventDefault: jest.fn()
|
111
|
-
}
|
112
|
-
|
113
|
-
if (!disabled && !loading) {
|
114
|
-
if (type !== 'submit') {
|
115
|
-
event.stopPropagation()
|
116
|
-
event.preventDefault()
|
117
|
-
}
|
118
|
-
|
119
|
-
if (action) action(event)
|
120
|
-
if (onClick) onClick(event)
|
121
|
-
}
|
122
|
-
|
123
|
-
return event
|
124
|
-
}
|
125
|
-
|
126
|
-
// Click normal
|
127
|
-
const event1 = simulateClick(false, false, mockAction, mockOnClick, 'button')
|
128
|
-
expect(event1.stopPropagation).toHaveBeenCalled()
|
129
|
-
expect(event1.preventDefault).toHaveBeenCalled()
|
130
|
-
expect(mockAction).toHaveBeenCalledWith(event1)
|
131
|
-
expect(mockOnClick).toHaveBeenCalledWith(event1)
|
132
|
-
|
133
|
-
mockAction.mockClear()
|
134
|
-
mockOnClick.mockClear()
|
135
|
-
|
136
|
-
// Click con disabled
|
137
|
-
simulateClick(true, false, mockAction, mockOnClick, 'button')
|
138
|
-
expect(mockAction).not.toHaveBeenCalled()
|
139
|
-
expect(mockOnClick).not.toHaveBeenCalled()
|
140
|
-
|
141
|
-
// Click con loading
|
142
|
-
simulateClick(false, true, mockAction, mockOnClick, 'button')
|
143
|
-
expect(mockAction).not.toHaveBeenCalled()
|
144
|
-
expect(mockOnClick).not.toHaveBeenCalled()
|
145
|
-
|
146
|
-
// Submit button (no preventDefault)
|
147
|
-
const event2 = simulateClick(false, false, mockAction, mockOnClick, 'submit')
|
148
|
-
expect(event2.preventDefault).not.toHaveBeenCalled()
|
149
|
-
expect(mockAction).toHaveBeenCalledWith(event2)
|
150
|
-
})
|
151
|
-
|
152
|
-
test('keyboard event handling works correctly', () => {
|
153
|
-
const mockClick = jest.fn()
|
154
|
-
const mockOnKeyDown = jest.fn()
|
155
|
-
|
156
|
-
const simulateKeyDown = (key, type, click, onKeyDown) => {
|
157
|
-
const event = {
|
158
|
-
key,
|
159
|
-
preventDefault: jest.fn()
|
160
|
-
}
|
161
|
-
|
162
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
163
|
-
if (type === 'button') {
|
164
|
-
event.preventDefault()
|
165
|
-
click(event)
|
166
|
-
}
|
167
|
-
}
|
168
|
-
if (onKeyDown) onKeyDown(event)
|
169
|
-
|
170
|
-
return event
|
171
|
-
}
|
172
|
-
|
173
|
-
// Enter key on button
|
174
|
-
const enterEvent = simulateKeyDown('Enter', 'button', mockClick, mockOnKeyDown)
|
175
|
-
expect(enterEvent.preventDefault).toHaveBeenCalled()
|
176
|
-
expect(mockClick).toHaveBeenCalledWith(enterEvent)
|
177
|
-
expect(mockOnKeyDown).toHaveBeenCalledWith(enterEvent)
|
178
|
-
|
179
|
-
mockClick.mockClear()
|
180
|
-
mockOnKeyDown.mockClear()
|
181
|
-
|
182
|
-
// Space key on button
|
183
|
-
const spaceEvent = simulateKeyDown(' ', 'button', mockClick, mockOnKeyDown)
|
184
|
-
expect(spaceEvent.preventDefault).toHaveBeenCalled()
|
185
|
-
expect(mockClick).toHaveBeenCalledWith(spaceEvent)
|
186
|
-
|
187
|
-
mockClick.mockClear()
|
188
|
-
|
189
|
-
// Enter key on submit (should not prevent default)
|
190
|
-
const submitEvent = simulateKeyDown('Enter', 'submit', mockClick, mockOnKeyDown)
|
191
|
-
expect(submitEvent.preventDefault).not.toHaveBeenCalled()
|
192
|
-
expect(mockClick).not.toHaveBeenCalled()
|
193
|
-
})
|
194
|
-
|
195
|
-
test('accessibility attributes generation works correctly', () => {
|
196
|
-
const generateAriaAttributes = (ariaLabel, icon, label, disabled, loading, tooltip, id) => {
|
197
|
-
return {
|
198
|
-
'aria-label': ariaLabel || (icon && !label ? `${icon} button` : undefined),
|
199
|
-
'aria-disabled': disabled || loading,
|
200
|
-
'aria-busy': loading,
|
201
|
-
'aria-describedby': tooltip ? `${id}-tooltip` : undefined
|
202
|
-
}
|
203
|
-
}
|
204
|
-
|
205
|
-
const basic = generateAriaAttributes(null, null, 'Test Label', false, false, null, 'test')
|
206
|
-
expect(basic['aria-label']).toBeUndefined()
|
207
|
-
expect(basic['aria-disabled']).toBe(false)
|
208
|
-
expect(basic['aria-busy']).toBe(false)
|
209
|
-
|
210
|
-
const withIcon = generateAriaAttributes(null, 'add', null, false, false, null, 'test')
|
211
|
-
expect(basic['aria-label']).toBeUndefined()
|
212
|
-
|
213
|
-
const withAriaLabel = generateAriaAttributes('Custom ARIA', null, null, false, false, null, 'test')
|
214
|
-
expect(withAriaLabel['aria-label']).toBe('Custom ARIA')
|
215
|
-
|
216
|
-
const disabled = generateAriaAttributes(null, null, 'Test', true, false, null, 'test')
|
217
|
-
expect(disabled['aria-disabled']).toBe(true)
|
218
|
-
|
219
|
-
const loading = generateAriaAttributes(null, null, 'Test', false, true, null, 'test')
|
220
|
-
expect(loading['aria-busy']).toBe(true)
|
221
|
-
expect(loading['aria-disabled']).toBe(true)
|
222
|
-
})
|
223
|
-
|
224
|
-
test('icon configuration works correctly', () => {
|
225
|
-
const getIconProps = (loading, icon, size, disabled) => {
|
226
|
-
return {
|
227
|
-
icon: loading ? 'hourglass_empty' : icon,
|
228
|
-
size: size === 'small' ? 'small' : size === 'large' ? 'normal' : 'small',
|
229
|
-
disabled: disabled || loading,
|
230
|
-
className: loading ? 'loading-icon' : ''
|
231
|
-
}
|
232
|
-
}
|
233
|
-
|
234
|
-
const normal = getIconProps(false, 'add', 'normal', false)
|
235
|
-
expect(normal.icon).toBe('add')
|
236
|
-
expect(normal.size).toBe('small')
|
237
|
-
expect(normal.disabled).toBe(false)
|
238
|
-
expect(normal.className).toBe('')
|
239
|
-
|
240
|
-
const loadingIcon = getIconProps(true, 'add', 'normal', false)
|
241
|
-
expect(loadingIcon.icon).toBe('hourglass_empty')
|
242
|
-
expect(loadingIcon.disabled).toBe(true)
|
243
|
-
expect(loadingIcon.className).toBe('loading-icon')
|
244
|
-
|
245
|
-
const smallSize = getIconProps(false, 'add', 'small', false)
|
246
|
-
expect(smallSize.size).toBe('small')
|
247
|
-
|
248
|
-
const largeSize = getIconProps(false, 'add', 'large', false)
|
249
|
-
expect(largeSize.size).toBe('normal')
|
250
|
-
})
|
251
|
-
})
|
252
|
-
|
253
|
-
describe('ActionButton Component', () => {
|
254
|
-
test('component exports correctly', () => {
|
255
|
-
expect(ActionButton).toBeDefined()
|
256
|
-
expect(typeof ActionButton).toBe('function')
|
257
|
-
})
|
258
|
-
|
259
|
-
test('component has correct PropTypes', () => {
|
260
|
-
expect(ActionButton.propTypes).toBeDefined()
|
261
|
-
expect(ActionButton.propTypes.states).toBeDefined()
|
262
|
-
expect(ActionButton.propTypes.state).toBeDefined()
|
263
|
-
expect(ActionButton.propTypes.disabled).toBeDefined()
|
264
|
-
expect(ActionButton.propTypes.className).toBeDefined()
|
265
|
-
expect(ActionButton.propTypes.onStateChange).toBeDefined()
|
266
|
-
})
|
267
|
-
|
268
|
-
test('component has correct defaultProps', () => {
|
269
|
-
expect(ActionButton.defaultProps).toBeDefined()
|
270
|
-
expect(ActionButton.defaultProps.disabled).toBe(false)
|
271
|
-
expect(ActionButton.defaultProps.className).toBe('')
|
272
|
-
})
|
273
|
-
|
274
|
-
test('warns when required props are missing', () => {
|
275
|
-
const validateStates = (states) => {
|
276
|
-
if (!states || typeof states !== 'object') {
|
277
|
-
console.warn('ActionButton component: states prop is required and must be an object')
|
278
|
-
return null
|
279
|
-
}
|
280
|
-
return true
|
281
|
-
}
|
282
|
-
|
283
|
-
const validateState = (state) => {
|
284
|
-
if (!state) {
|
285
|
-
console.warn('ActionButton component: state prop is required')
|
286
|
-
return null
|
287
|
-
}
|
288
|
-
return true
|
289
|
-
}
|
290
|
-
|
291
|
-
expect(validateStates(null)).toBeNull()
|
292
|
-
expect(console.warn).toHaveBeenCalledWith('ActionButton component: states prop is required and must be an object')
|
293
|
-
|
294
|
-
console.warn.mockClear()
|
295
|
-
expect(validateState(null)).toBeNull()
|
296
|
-
expect(console.warn).toHaveBeenCalledWith('ActionButton component: state prop is required')
|
297
|
-
})
|
298
|
-
|
299
|
-
test('state synchronization works correctly', () => {
|
300
|
-
let currentState = null
|
301
|
-
|
302
|
-
const syncState = (externalState) => {
|
303
|
-
currentState = externalState
|
304
|
-
}
|
305
|
-
|
306
|
-
syncState('normal')
|
307
|
-
expect(currentState).toBe('normal')
|
308
|
-
|
309
|
-
syncState('running')
|
310
|
-
expect(currentState).toBe('running')
|
311
|
-
})
|
312
|
-
|
313
|
-
test('execution logic works correctly', async () => {
|
314
|
-
const mockAction = jest.fn().mockResolvedValue('success')
|
315
|
-
const mockOnStateChange = jest.fn()
|
316
|
-
|
317
|
-
const states = {
|
318
|
-
normal: { icon: 'add', label: 'Start', action: mockAction },
|
319
|
-
success: { icon: 'check', label: 'Done' }
|
320
|
-
}
|
321
|
-
|
322
|
-
const simulateExecution = async (disabled, isExecuting, currentState, states, onStateChange) => {
|
323
|
-
if (disabled || isExecuting) return
|
324
|
-
|
325
|
-
const stateConfig = states[currentState]
|
326
|
-
if (!stateConfig) return
|
327
|
-
|
328
|
-
let newState = null
|
329
|
-
if (stateConfig.action) {
|
330
|
-
newState = await stateConfig.action()
|
331
|
-
if (newState && states[newState]) {
|
332
|
-
if (onStateChange) onStateChange(newState)
|
333
|
-
}
|
334
|
-
}
|
335
|
-
return newState
|
336
|
-
}
|
337
|
-
|
338
|
-
// Normal execution
|
339
|
-
const result = await simulateExecution(false, false, 'normal', states, mockOnStateChange)
|
340
|
-
expect(mockAction).toHaveBeenCalled()
|
341
|
-
expect(mockOnStateChange).toHaveBeenCalledWith('success')
|
342
|
-
expect(result).toBe('success')
|
343
|
-
|
344
|
-
mockAction.mockClear()
|
345
|
-
mockOnStateChange.mockClear()
|
346
|
-
|
347
|
-
// Disabled execution
|
348
|
-
await simulateExecution(true, false, 'normal', states, mockOnStateChange)
|
349
|
-
expect(mockAction).not.toHaveBeenCalled()
|
350
|
-
expect(mockOnStateChange).not.toHaveBeenCalled()
|
351
|
-
|
352
|
-
// Already executing
|
353
|
-
await simulateExecution(false, true, 'normal', states, mockOnStateChange)
|
354
|
-
expect(mockAction).not.toHaveBeenCalled()
|
355
|
-
})
|
356
|
-
|
357
|
-
test('error handling works correctly', async () => {
|
358
|
-
const mockAction = jest.fn().mockRejectedValue(new Error('Test error'))
|
359
|
-
const mockOnStateChange = jest.fn()
|
360
|
-
|
361
|
-
const states = {
|
362
|
-
normal: { icon: 'add', label: 'Start', action: mockAction },
|
363
|
-
error: { icon: 'error', label: 'Error' }
|
364
|
-
}
|
365
|
-
|
366
|
-
const simulateExecutionWithError = async (currentState, states, onStateChange) => {
|
367
|
-
const stateConfig = states[currentState]
|
368
|
-
if (!stateConfig) return
|
369
|
-
|
370
|
-
try {
|
371
|
-
if (stateConfig.action) {
|
372
|
-
await stateConfig.action()
|
373
|
-
}
|
374
|
-
} catch (error) {
|
375
|
-
console.error('ActionButton execution error:', error)
|
376
|
-
if (states.error) {
|
377
|
-
if (onStateChange) onStateChange('error')
|
378
|
-
}
|
379
|
-
}
|
380
|
-
}
|
381
|
-
|
382
|
-
// Mock console.error
|
383
|
-
jest.spyOn(console, 'error').mockImplementation(() => {})
|
384
|
-
|
385
|
-
await simulateExecutionWithError('normal', states, mockOnStateChange)
|
386
|
-
expect(mockAction).toHaveBeenCalled()
|
387
|
-
expect(console.error).toHaveBeenCalledWith('ActionButton execution error:', expect.any(Error))
|
388
|
-
expect(mockOnStateChange).toHaveBeenCalledWith('error')
|
389
|
-
|
390
|
-
console.error.mockRestore()
|
391
|
-
})
|
392
|
-
|
393
|
-
test('autoexec functionality works correctly', () => {
|
394
|
-
const mockExecute = jest.fn()
|
395
|
-
|
396
|
-
const simulateAutoexec = (currentState, states, isExecuting, execute) => {
|
397
|
-
if (states[currentState] && states[currentState].autoexec && !isExecuting) {
|
398
|
-
execute()
|
399
|
-
}
|
400
|
-
}
|
401
|
-
|
402
|
-
const states = {
|
403
|
-
normal: { icon: 'add', label: 'Start' },
|
404
|
-
running: { icon: 'rotate', label: 'Running', autoexec: true }
|
405
|
-
}
|
406
|
-
|
407
|
-
// Normal state (no autoexec)
|
408
|
-
simulateAutoexec('normal', states, false, mockExecute)
|
409
|
-
expect(mockExecute).not.toHaveBeenCalled()
|
410
|
-
|
411
|
-
// Running state (with autoexec)
|
412
|
-
simulateAutoexec('running', states, false, mockExecute)
|
413
|
-
expect(mockExecute).toHaveBeenCalled()
|
414
|
-
|
415
|
-
mockExecute.mockClear()
|
416
|
-
|
417
|
-
// Running state but already executing
|
418
|
-
simulateAutoexec('running', states, true, mockExecute)
|
419
|
-
expect(mockExecute).not.toHaveBeenCalled()
|
420
|
-
})
|
421
|
-
})
|
422
|
-
})
|