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
@@ -1,71 +0,0 @@
|
|
1
|
-
import React, { useContext, useEffect, useState } from 'react'
|
2
|
-
import { CheckBox } from '../html'
|
3
|
-
import { CollectionContext, CollectionContextProvider } from './CollectionContext'
|
4
|
-
import { CollectionEditor } from './CollectionEditor'
|
5
|
-
import { CollectionFilters } from './CollectionFilters'
|
6
|
-
import { CollectionList } from './CollectionList'
|
7
|
-
|
8
|
-
const CollectionContextTest = (props) => {
|
9
|
-
|
10
|
-
const config = {
|
11
|
-
host: "http://localhost:3000",
|
12
|
-
url: "/references",
|
13
|
-
}
|
14
|
-
|
15
|
-
const style = {
|
16
|
-
display: "flex",
|
17
|
-
flexDirection: "row",
|
18
|
-
}
|
19
|
-
|
20
|
-
const schema = [
|
21
|
-
{ id: "id", type: "string", label: "ID" },
|
22
|
-
{ id: "name", type: "string", label: "Name", filter: true, like: true },
|
23
|
-
{ id: "gender", type: "string", label: "Gender", filter: true, options: [
|
24
|
-
{ label: "Masculine", value: 1 },
|
25
|
-
{ label: "Feminine", value: 0 }
|
26
|
-
]},
|
27
|
-
{ id: "description", type: "string", label: "Description" },
|
28
|
-
]
|
29
|
-
|
30
|
-
return (
|
31
|
-
<div style={style}>
|
32
|
-
<CollectionContextProvider {...config}>
|
33
|
-
<CollectionFilters schema={schema} >
|
34
|
-
<CustomFilter1 />
|
35
|
-
</CollectionFilters>
|
36
|
-
<CollectionList />
|
37
|
-
<CollectionEditor />
|
38
|
-
</CollectionContextProvider>
|
39
|
-
</div>
|
40
|
-
|
41
|
-
)
|
42
|
-
}
|
43
|
-
|
44
|
-
const CustomFilter1 = (props) => {
|
45
|
-
|
46
|
-
const context = useContext(CollectionContext)
|
47
|
-
const [active, setActive] = useState(false)
|
48
|
-
|
49
|
-
useEffect(() => {
|
50
|
-
if (active) {
|
51
|
-
context.addCustomFilter("ACTIVE", filter)
|
52
|
-
} else {
|
53
|
-
context.removeCustomFilter("ACTIVE")
|
54
|
-
}
|
55
|
-
}, [active])
|
56
|
-
|
57
|
-
function change(id, value) {
|
58
|
-
setActive(value)
|
59
|
-
}
|
60
|
-
|
61
|
-
function filter(all) {
|
62
|
-
console.log("CUSTOMFILTER1 DO NOTHING")
|
63
|
-
return all
|
64
|
-
}
|
65
|
-
|
66
|
-
return (
|
67
|
-
<div>
|
68
|
-
<CheckBox id="custom1" label="Custom Filter 1" value={active} onChange={change} />
|
69
|
-
</div>
|
70
|
-
)
|
71
|
-
}
|
@@ -1,112 +0,0 @@
|
|
1
|
-
import React, { useContext, useEffect, useState } from 'react'
|
2
|
-
import { CheckBox } from '../html'
|
3
|
-
import { CollectionContext } from './CollectionContext'
|
4
|
-
import { CollectionPage } from './CollectionPage'
|
5
|
-
|
6
|
-
const CollectionPageTest = (prop) => {
|
7
|
-
|
8
|
-
const schema = {
|
9
|
-
id: { id: "id", type: "string", label: "ID" },
|
10
|
-
name: { id: "name", type: "string", label: "Name", filter: true },
|
11
|
-
gender: {
|
12
|
-
id: "gender", type: "string", label: "Gender", filter: true, options: [
|
13
|
-
{ label: "Masculine", value: 1 },
|
14
|
-
{ label: "Feminine", value: 0 }
|
15
|
-
]
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
const listItemRenderer = (item) => {
|
20
|
-
return {
|
21
|
-
id: item.id,
|
22
|
-
icon: "star",
|
23
|
-
line1: item.name,
|
24
|
-
line2: item.name,
|
25
|
-
meta: item.state,
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
const props = {
|
30
|
-
host: "http://localhost:3000",
|
31
|
-
url: "/references",
|
32
|
-
schema,
|
33
|
-
layout: "ide",
|
34
|
-
title: <CustomTitle />,
|
35
|
-
canFilter: true,
|
36
|
-
customFilters: [<CustomFilters/>,],
|
37
|
-
filtersValue: {},
|
38
|
-
listSearchBy: ["name"],
|
39
|
-
listGroupBy: "name",
|
40
|
-
listItemRenderer,
|
41
|
-
customEditor: <CustomEditor />
|
42
|
-
}
|
43
|
-
|
44
|
-
return (
|
45
|
-
<>
|
46
|
-
<CollectionPage {...props} />
|
47
|
-
</>
|
48
|
-
)
|
49
|
-
}
|
50
|
-
|
51
|
-
const CustomTitle = (props) => {
|
52
|
-
return (
|
53
|
-
<h1>Custom Title</h1>
|
54
|
-
)
|
55
|
-
}
|
56
|
-
|
57
|
-
const CustomEditor = () => {
|
58
|
-
|
59
|
-
const context = useContext(CollectionContext)
|
60
|
-
const { all, selected } = context
|
61
|
-
|
62
|
-
return (
|
63
|
-
<div>
|
64
|
-
<header>
|
65
|
-
CUSTOM EDITOR {all.length}
|
66
|
-
</header>
|
67
|
-
<main>
|
68
|
-
ID: {selected ? selected.id : null}
|
69
|
-
</main>
|
70
|
-
</div>
|
71
|
-
)
|
72
|
-
}
|
73
|
-
|
74
|
-
|
75
|
-
const CustomFilters = (props) => {
|
76
|
-
|
77
|
-
return (
|
78
|
-
<>
|
79
|
-
<CustomFilter1 id="customfilter1" label="1"/>
|
80
|
-
<CustomFilter1 id="customfilter2" label="2"/>
|
81
|
-
</>
|
82
|
-
)
|
83
|
-
}
|
84
|
-
|
85
|
-
const CustomFilter1 = (props) => {
|
86
|
-
|
87
|
-
const { id, label} = props
|
88
|
-
const context = useContext(CollectionContext)
|
89
|
-
const [active, setActive] = useState(true)
|
90
|
-
|
91
|
-
useEffect(async () => {
|
92
|
-
if (active) {
|
93
|
-
await context.addCustomFilter(id, filter)
|
94
|
-
} else {
|
95
|
-
await context.removeCustomFilter(id)
|
96
|
-
}
|
97
|
-
}, [active])
|
98
|
-
|
99
|
-
function change(id, value) {
|
100
|
-
setActive(value)
|
101
|
-
}
|
102
|
-
|
103
|
-
function filter(all) {
|
104
|
-
return all.filter(item => {
|
105
|
-
return item.name.startsWith("1")
|
106
|
-
})
|
107
|
-
}
|
108
|
-
|
109
|
-
return (
|
110
|
-
<CheckBox id={id} value={active} label={label} onChange={change} />
|
111
|
-
)
|
112
|
-
}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import React, { useState } from 'react'
|
2
|
-
import { DynamicForm } from './DynamicForm'
|
3
|
-
import { FORMATS } from './FORMATS'
|
4
|
-
import { TYPES } from './TYPES'
|
5
|
-
|
6
|
-
const DynamicFormTest = (props) => {
|
7
|
-
|
8
|
-
const config = {
|
9
|
-
host: "http://localhost:3000",
|
10
|
-
url: "/references",
|
11
|
-
}
|
12
|
-
|
13
|
-
const style = {
|
14
|
-
display: "flex",
|
15
|
-
flexDirection: "row",
|
16
|
-
}
|
17
|
-
|
18
|
-
const schema = [
|
19
|
-
{ id: "id", type: "string", label: "ID", editable: false },
|
20
|
-
{ id: "name", type: "string", label: "Name", filter: true, like: true },
|
21
|
-
{
|
22
|
-
id: "gender", type: "string", label: "Gender", filter: true, editable: true, options: [
|
23
|
-
{ label: "Masculine", value: 1 },
|
24
|
-
{ label: "Feminine", value: 0 }
|
25
|
-
]
|
26
|
-
},
|
27
|
-
{ id: "initDate", type: TYPES.STRING, label: "Init Date", format: FORMATS.DATE },
|
28
|
-
{ id: "hour", type: TYPES.STRING, label: "Hour", format: FORMATS.TIME },
|
29
|
-
{ id: "range", type: TYPES.STRING, label: "Range", format: FORMATS.DATERANGE },
|
30
|
-
{ id: "email", type: TYPES.STRING, label: "Email", format: FORMATS.EMAIL },
|
31
|
-
{ id: "color", type: TYPES.STRING, label: "Color", format: FORMATS.COLOR },
|
32
|
-
{ id: "active", type: TYPES.BOOLEAN , label: "Active", format: FORMATS.CHECKBOX },
|
33
|
-
]
|
34
|
-
|
35
|
-
const [values, setValues] = useState({})
|
36
|
-
|
37
|
-
function onChange(id, value) {
|
38
|
-
setValues({ ...values, [id]: value })
|
39
|
-
}
|
40
|
-
|
41
|
-
return (
|
42
|
-
<div style={style}>
|
43
|
-
<DynamicForm schema={schema} values={values} onChange={onChange} />
|
44
|
-
</div>
|
45
|
-
|
46
|
-
)
|
47
|
-
}
|
@@ -1,37 +0,0 @@
|
|
1
|
-
import React, { useState } from 'react'
|
2
|
-
import { Accordion } from './accordion'
|
3
|
-
import { Icon } from './icon'
|
4
|
-
|
5
|
-
const AccordionTest = (prop) => {
|
6
|
-
|
7
|
-
const info = <div>50 Unidades</div>
|
8
|
-
|
9
|
-
const toolbar = [<Icon icon="edit" size="small" clickable />, <Icon icon="delete" size="small" clickable />]
|
10
|
-
|
11
|
-
const sections = [
|
12
|
-
{ id: 1 , checked: false, icon: 'star', title: 'Section 1' , subtitle: 'Subtitle 1' , info, toolbar, open: true , children: <div>Section 1 content</div> },
|
13
|
-
{ id: 2 , checked: false, icon: 'star', title: 'Section 2' , subtitle: 'Subtitle 2' , info, toolbar, open: true , children: <div>Section 2 content</div> },
|
14
|
-
{ id: 3 , checked: false, icon: 'star', title: 'Section 3' , subtitle: 'Subtitle 3' , info, toolbar, open: false, children: <div>Section 3 content</div> },
|
15
|
-
{ id: 4 , checked: false, icon: 'star', title: 'Section 4' , subtitle: 'Subtitle 4' , info, toolbar, open: false, children: <div>Section 4 content</div> },
|
16
|
-
{ id: 5 , checked: false, icon: 'star', title: 'Section 5' , subtitle: 'Subtitle 5' , info, toolbar, open: false, children: <div>Section 5 content</div> },
|
17
|
-
{ id: 6 , checked: false, icon: 'star', title: 'Section 6' , subtitle: 'Subtitle 6' , info, toolbar, open: false, children: <div>Section 6 content</div> },
|
18
|
-
{ id: 7 , checked: false, icon: 'star', title: 'Section 7' , subtitle: 'Subtitle 7' , info, toolbar, open: false, children: <div>Section 7 content</div> },
|
19
|
-
{ id: 8 , checked: false, icon: 'star', title: 'Section 8' , subtitle: 'Subtitle 8' , info, toolbar, open: false, children: <div>Section 8 content</div> },
|
20
|
-
{ id: 9 , checked: false, icon: 'star', title: 'Section 9' , subtitle: 'Subtitle 9' , info, toolbar, open: false, children: <div>Section 9 content</div> },
|
21
|
-
{ id: 10, checked: false, icon: 'star', title: 'Section 10', subtitle: 'Subtitle 10', info, toolbar, open: false, children: <div>Section 10 content</div> },
|
22
|
-
{ id: 11, checked: false, icon: 'star', title: 'Section 11', subtitle: 'Subtitle 11', info, toolbar, open: false, children: <div>Section 11 content</div> },
|
23
|
-
{ id: 12, checked: false, icon: 'star', title: 'Section 12', subtitle: 'Subtitle 12', info, toolbar, open: false, children: <div>Section 12 content</div> },
|
24
|
-
{ id: 13, checked: false, icon: 'star', title: 'Section 13', subtitle: 'Subtitle 13', info, toolbar, open: false, children: <div>Section 13 content</div> },
|
25
|
-
{ id: 14, checked: false, icon: 'star', title: 'Section 14', subtitle: 'Subtitle 14', info, toolbar, open: false, children: <div>Section 14 content</div> },
|
26
|
-
{ id: 15, checked: false, icon: 'star', title: 'Section 15', subtitle: 'Subtitle 15', info, toolbar, open: false, children: <div>Section 15 content</div> },
|
27
|
-
{ id: 16, checked: false, icon: 'star', title: 'Section 16', subtitle: 'Subtitle 16', info, toolbar, open: false, children: <div>Section 16 content</div> },
|
28
|
-
{ id: 17, checked: false, icon: 'star', title: 'Section 17', subtitle: 'Subtitle 17', info, toolbar, open: false, children: <div>Section 17 content</div> },
|
29
|
-
]
|
30
|
-
|
31
|
-
|
32
|
-
return (
|
33
|
-
<>
|
34
|
-
<Accordion sections={sections} onCheck={console.log} />
|
35
|
-
</>
|
36
|
-
)
|
37
|
-
}
|
@@ -1,334 +0,0 @@
|
|
1
|
-
import React from 'react'
|
2
|
-
import { Accordion } from './accordion'
|
3
|
-
|
4
|
-
// Pruebas unitarias para el componente Accordion mejorado
|
5
|
-
describe('Accordion Component', () => {
|
6
|
-
// Mock de los componentes dependientes
|
7
|
-
const mockIcon = jest.fn()
|
8
|
-
|
9
|
-
beforeEach(() => {
|
10
|
-
jest.clearAllMocks()
|
11
|
-
|
12
|
-
// Mock del componente Icon
|
13
|
-
jest.doMock('./icon', () => ({
|
14
|
-
Icon: mockIcon
|
15
|
-
}))
|
16
|
-
|
17
|
-
// Mock de console.warn para las pruebas
|
18
|
-
jest.spyOn(console, 'warn').mockImplementation(() => {})
|
19
|
-
})
|
20
|
-
|
21
|
-
afterEach(() => {
|
22
|
-
console.warn.mockRestore()
|
23
|
-
})
|
24
|
-
|
25
|
-
test('component exports correctly', () => {
|
26
|
-
expect(Accordion).toBeDefined()
|
27
|
-
expect(typeof Accordion).toBe('function')
|
28
|
-
})
|
29
|
-
|
30
|
-
test('component has correct PropTypes', () => {
|
31
|
-
expect(Accordion.propTypes).toBeDefined()
|
32
|
-
expect(Accordion.propTypes.sections).toBeDefined()
|
33
|
-
expect(Accordion.propTypes.className).toBeDefined()
|
34
|
-
expect(Accordion.propTypes.disabled).toBeDefined()
|
35
|
-
expect(Accordion.propTypes.allowMultiple).toBeDefined()
|
36
|
-
expect(Accordion.propTypes.animated).toBeDefined()
|
37
|
-
expect(Accordion.propTypes.ariaLabel).toBeDefined()
|
38
|
-
expect(Accordion.propTypes.onCheck).toBeDefined()
|
39
|
-
expect(Accordion.propTypes.onToggle).toBeDefined()
|
40
|
-
expect(Accordion.propTypes.onSectionChange).toBeDefined()
|
41
|
-
})
|
42
|
-
|
43
|
-
test('component has correct defaultProps', () => {
|
44
|
-
expect(Accordion.defaultProps).toBeDefined()
|
45
|
-
expect(Accordion.defaultProps.className).toBe('')
|
46
|
-
expect(Accordion.defaultProps.disabled).toBe(false)
|
47
|
-
expect(Accordion.defaultProps.allowMultiple).toBe(true)
|
48
|
-
expect(Accordion.defaultProps.animated).toBe(true)
|
49
|
-
})
|
50
|
-
|
51
|
-
test('warns when sections is not an array', () => {
|
52
|
-
const validateSections = (sections) => {
|
53
|
-
if (!Array.isArray(sections)) {
|
54
|
-
console.warn('Accordion component: sections prop must be an array')
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
validateSections('not an array')
|
59
|
-
expect(console.warn).toHaveBeenCalledWith('Accordion component: sections prop must be an array')
|
60
|
-
|
61
|
-
console.warn.mockClear()
|
62
|
-
validateSections([])
|
63
|
-
expect(console.warn).not.toHaveBeenCalled()
|
64
|
-
})
|
65
|
-
|
66
|
-
test('sections state initialization works correctly', () => {
|
67
|
-
const sections = [
|
68
|
-
{ id: 1, open: true, checked: false },
|
69
|
-
{ id: 2, open: false, checked: true },
|
70
|
-
{ id: 3, open: true, checked: true }
|
71
|
-
]
|
72
|
-
|
73
|
-
const initializeState = (sections) => {
|
74
|
-
const openSections = sections.map(section => section.open || false)
|
75
|
-
const checkedSections = sections.map(section => section.checked || false)
|
76
|
-
return { openSections, checkedSections }
|
77
|
-
}
|
78
|
-
|
79
|
-
const result = initializeState(sections)
|
80
|
-
expect(result.openSections).toEqual([true, false, true])
|
81
|
-
expect(result.checkedSections).toEqual([false, true, true])
|
82
|
-
})
|
83
|
-
|
84
|
-
test('toggle logic works correctly with allowMultiple=true', () => {
|
85
|
-
const openSections = [true, false, true]
|
86
|
-
const allowMultiple = true
|
87
|
-
const index = 1
|
88
|
-
|
89
|
-
const toggle = (openSections, index, allowMultiple) => {
|
90
|
-
return allowMultiple
|
91
|
-
? openSections.map((open, i) => i === index ? !open : open)
|
92
|
-
: openSections.map((open, i) => i === index ? !open : false)
|
93
|
-
}
|
94
|
-
|
95
|
-
const result = toggle(openSections, index, allowMultiple)
|
96
|
-
expect(result).toEqual([true, true, true])
|
97
|
-
})
|
98
|
-
|
99
|
-
test('toggle logic works correctly with allowMultiple=false', () => {
|
100
|
-
const openSections = [true, false, true]
|
101
|
-
const allowMultiple = false
|
102
|
-
const index = 1
|
103
|
-
|
104
|
-
const toggle = (openSections, index, allowMultiple) => {
|
105
|
-
return allowMultiple
|
106
|
-
? openSections.map((open, i) => i === index ? !open : open)
|
107
|
-
: openSections.map((open, i) => i === index ? !open : false)
|
108
|
-
}
|
109
|
-
|
110
|
-
const result = toggle(openSections, index, allowMultiple)
|
111
|
-
expect(result).toEqual([false, true, false])
|
112
|
-
})
|
113
|
-
|
114
|
-
test('check logic works correctly', () => {
|
115
|
-
const checkedSections = [false, true, false]
|
116
|
-
const index = 0
|
117
|
-
|
118
|
-
const check = (checkedSections, index) => {
|
119
|
-
return checkedSections.map((checked, i) => i === index ? !checked : checked)
|
120
|
-
}
|
121
|
-
|
122
|
-
const result = check(checkedSections, index)
|
123
|
-
expect(result).toEqual([true, true, false])
|
124
|
-
})
|
125
|
-
|
126
|
-
test('CSS classes generation works correctly', () => {
|
127
|
-
const generateClasses = (disabled, animated, className) => {
|
128
|
-
return [
|
129
|
-
'accordion',
|
130
|
-
disabled && 'disabled',
|
131
|
-
animated && 'animated',
|
132
|
-
className || ''
|
133
|
-
].filter(Boolean).join(' ')
|
134
|
-
}
|
135
|
-
|
136
|
-
expect(generateClasses(false, false, '')).toBe('accordion')
|
137
|
-
expect(generateClasses(true, false, '')).toBe('accordion disabled')
|
138
|
-
expect(generateClasses(false, true, '')).toBe('accordion animated')
|
139
|
-
expect(generateClasses(true, true, 'custom')).toBe('accordion disabled animated custom')
|
140
|
-
})
|
141
|
-
|
142
|
-
test('accessibility attributes generation works correctly', () => {
|
143
|
-
const generateAriaAttributes = (ariaLabel, disabled) => {
|
144
|
-
return {
|
145
|
-
'aria-label': ariaLabel || 'Accordion',
|
146
|
-
'aria-disabled': disabled,
|
147
|
-
role: 'region'
|
148
|
-
}
|
149
|
-
}
|
150
|
-
|
151
|
-
const result1 = generateAriaAttributes(null, false)
|
152
|
-
expect(result1['aria-label']).toBe('Accordion')
|
153
|
-
expect(result1['aria-disabled']).toBe(false)
|
154
|
-
expect(result1.role).toBe('region')
|
155
|
-
|
156
|
-
const result2 = generateAriaAttributes('Custom Accordion', true)
|
157
|
-
expect(result2['aria-label']).toBe('Custom Accordion')
|
158
|
-
expect(result2['aria-disabled']).toBe(true)
|
159
|
-
})
|
160
|
-
|
161
|
-
test('section ID generation works correctly', () => {
|
162
|
-
const generateSectionId = (section, index) => {
|
163
|
-
return section.id || `accordion-section-${index}`
|
164
|
-
}
|
165
|
-
|
166
|
-
expect(generateSectionId({ id: 'custom-id' }, 0)).toBe('custom-id')
|
167
|
-
expect(generateSectionId({}, 0)).toBe('accordion-section-0')
|
168
|
-
expect(generateSectionId({ id: null }, 1)).toBe('accordion-section-1')
|
169
|
-
})
|
170
|
-
|
171
|
-
test('callback handling works correctly', () => {
|
172
|
-
const mockOnCheck = jest.fn()
|
173
|
-
const mockOnToggle = jest.fn()
|
174
|
-
const mockOnSectionChange = jest.fn()
|
175
|
-
|
176
|
-
const simulateCheck = (index, newValue, section, onCheck, onSectionChange) => {
|
177
|
-
if (onCheck) {
|
178
|
-
onCheck(index, newValue, section?.id, section)
|
179
|
-
}
|
180
|
-
|
181
|
-
if (onSectionChange) {
|
182
|
-
onSectionChange('check', index, newValue, section)
|
183
|
-
}
|
184
|
-
}
|
185
|
-
|
186
|
-
const simulateToggle = (index, newValue, section, onToggle, onSectionChange) => {
|
187
|
-
if (onToggle) {
|
188
|
-
onToggle(index, newValue, section)
|
189
|
-
}
|
190
|
-
|
191
|
-
if (onSectionChange) {
|
192
|
-
onSectionChange('toggle', index, newValue, section)
|
193
|
-
}
|
194
|
-
}
|
195
|
-
|
196
|
-
const section = { id: 'test-section', title: 'Test' }
|
197
|
-
|
198
|
-
simulateCheck(0, true, section, mockOnCheck, mockOnSectionChange)
|
199
|
-
expect(mockOnCheck).toHaveBeenCalledWith(0, true, 'test-section', section)
|
200
|
-
expect(mockOnSectionChange).toHaveBeenCalledWith('check', 0, true, section)
|
201
|
-
|
202
|
-
simulateToggle(0, true, section, mockOnToggle, mockOnSectionChange)
|
203
|
-
expect(mockOnToggle).toHaveBeenCalledWith(0, true, section)
|
204
|
-
expect(mockOnSectionChange).toHaveBeenCalledWith('toggle', 0, true, section)
|
205
|
-
})
|
206
|
-
|
207
|
-
test('disabled state prevents interactions', () => {
|
208
|
-
const simulateInteraction = (disabled) => {
|
209
|
-
if (disabled) return false
|
210
|
-
return true
|
211
|
-
}
|
212
|
-
|
213
|
-
expect(simulateInteraction(true)).toBe(false)
|
214
|
-
expect(simulateInteraction(false)).toBe(true)
|
215
|
-
})
|
216
|
-
})
|
217
|
-
|
218
|
-
// AccordionSection tests
|
219
|
-
describe('AccordionSection Component', () => {
|
220
|
-
test('keyboard navigation logic works correctly', () => {
|
221
|
-
const mockOnToggle = jest.fn()
|
222
|
-
|
223
|
-
const handleKeyDown = (event, disabled, onToggle) => {
|
224
|
-
if (disabled) return false
|
225
|
-
|
226
|
-
switch (event.key) {
|
227
|
-
case 'Enter':
|
228
|
-
case ' ':
|
229
|
-
if (onToggle) onToggle()
|
230
|
-
return true
|
231
|
-
default:
|
232
|
-
return false
|
233
|
-
}
|
234
|
-
}
|
235
|
-
|
236
|
-
// Test Enter key
|
237
|
-
expect(handleKeyDown({ key: 'Enter' }, false, mockOnToggle)).toBe(true)
|
238
|
-
expect(mockOnToggle).toHaveBeenCalled()
|
239
|
-
|
240
|
-
mockOnToggle.mockClear()
|
241
|
-
|
242
|
-
// Test Space key
|
243
|
-
expect(handleKeyDown({ key: ' ' }, false, mockOnToggle)).toBe(true)
|
244
|
-
expect(mockOnToggle).toHaveBeenCalled()
|
245
|
-
|
246
|
-
mockOnToggle.mockClear()
|
247
|
-
|
248
|
-
// Test disabled state
|
249
|
-
expect(handleKeyDown({ key: 'Enter' }, true, mockOnToggle)).toBe(false)
|
250
|
-
expect(mockOnToggle).not.toHaveBeenCalled()
|
251
|
-
|
252
|
-
// Test other keys
|
253
|
-
expect(handleKeyDown({ key: 'Tab' }, false, mockOnToggle)).toBe(false)
|
254
|
-
})
|
255
|
-
|
256
|
-
test('header click logic works correctly', () => {
|
257
|
-
const mockOnToggle = jest.fn()
|
258
|
-
|
259
|
-
const handleHeaderClick = (event, disabled, onToggle) => {
|
260
|
-
if (disabled) return false
|
261
|
-
|
262
|
-
// Don't toggle if clicking on interactive elements
|
263
|
-
if (event.target.closest('.accordion-section-checker') ||
|
264
|
-
event.target.closest('.accordion-section--toolbar')) {
|
265
|
-
return false
|
266
|
-
}
|
267
|
-
|
268
|
-
if (onToggle) onToggle()
|
269
|
-
return true
|
270
|
-
}
|
271
|
-
|
272
|
-
// Normal click
|
273
|
-
const normalEvent = { target: { closest: () => null } }
|
274
|
-
expect(handleHeaderClick(normalEvent, false, mockOnToggle)).toBe(true)
|
275
|
-
expect(mockOnToggle).toHaveBeenCalled()
|
276
|
-
|
277
|
-
mockOnToggle.mockClear()
|
278
|
-
|
279
|
-
// Click on checker
|
280
|
-
const checkerEvent = { target: { closest: (selector) => selector === '.accordion-section-checker' ? true : null } }
|
281
|
-
expect(handleHeaderClick(checkerEvent, false, mockOnToggle)).toBe(false)
|
282
|
-
expect(mockOnToggle).not.toHaveBeenCalled()
|
283
|
-
|
284
|
-
// Click on toolbar
|
285
|
-
const toolbarEvent = { target: { closest: (selector) => selector === '.accordion-section--toolbar' ? true : null } }
|
286
|
-
expect(handleHeaderClick(toolbarEvent, false, mockOnToggle)).toBe(false)
|
287
|
-
expect(mockOnToggle).not.toHaveBeenCalled()
|
288
|
-
|
289
|
-
// Disabled state
|
290
|
-
expect(handleHeaderClick(normalEvent, true, mockOnToggle)).toBe(false)
|
291
|
-
expect(mockOnToggle).not.toHaveBeenCalled()
|
292
|
-
})
|
293
|
-
|
294
|
-
test('section CSS classes generation works correctly', () => {
|
295
|
-
const generateSectionClasses = (open, disabled, animated, checked) => {
|
296
|
-
return [
|
297
|
-
'accordion-section',
|
298
|
-
open && 'open',
|
299
|
-
disabled && 'disabled',
|
300
|
-
animated && 'animated',
|
301
|
-
checked && 'checked'
|
302
|
-
].filter(Boolean).join(' ')
|
303
|
-
}
|
304
|
-
|
305
|
-
expect(generateSectionClasses(false, false, false, false)).toBe('accordion-section')
|
306
|
-
expect(generateSectionClasses(true, false, false, false)).toBe('accordion-section open')
|
307
|
-
expect(generateSectionClasses(false, true, false, false)).toBe('accordion-section disabled')
|
308
|
-
expect(generateSectionClasses(false, false, true, false)).toBe('accordion-section animated')
|
309
|
-
expect(generateSectionClasses(false, false, false, true)).toBe('accordion-section checked')
|
310
|
-
expect(generateSectionClasses(true, true, true, true)).toBe('accordion-section open disabled animated checked')
|
311
|
-
})
|
312
|
-
|
313
|
-
test('checked icon logic works correctly', () => {
|
314
|
-
const getCheckedIcon = (checked) => {
|
315
|
-
return checked === undefined || checked === null ?
|
316
|
-
null :
|
317
|
-
checked === false ? "check_box_outline_blank" : "check_box"
|
318
|
-
}
|
319
|
-
|
320
|
-
expect(getCheckedIcon(undefined)).toBeNull()
|
321
|
-
expect(getCheckedIcon(null)).toBeNull()
|
322
|
-
expect(getCheckedIcon(false)).toBe("check_box_outline_blank")
|
323
|
-
expect(getCheckedIcon(true)).toBe("check_box")
|
324
|
-
})
|
325
|
-
|
326
|
-
test('toggler icon logic works correctly', () => {
|
327
|
-
const getTogglerIcon = (open) => {
|
328
|
-
return open ? "expand_less" : "expand_more"
|
329
|
-
}
|
330
|
-
|
331
|
-
expect(getTogglerIcon(true)).toBe("expand_less")
|
332
|
-
expect(getTogglerIcon(false)).toBe("expand_more")
|
333
|
-
})
|
334
|
-
})
|