@datametria/vue-components 2.3.1 → 2.4.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 +625 -594
- package/dist/index.es.js +1962 -1887
- package/dist/index.umd.js +6 -6
- package/dist/src/components/DatametriaForm.vue.d.ts +1 -1
- package/dist/src/components/DatametriaInput.vue.d.ts +9 -1
- package/dist/src/components/DatametriaSelect.vue.d.ts +10 -1
- package/dist/vue-components.css +1 -1
- package/package.json +103 -102
- package/src/components/DatametriaAlert.vue +151 -133
- package/src/components/DatametriaAutocomplete.vue +250 -229
- package/src/components/DatametriaAvatar.vue +256 -238
- package/src/components/DatametriaBadge.vue +101 -96
- package/src/components/DatametriaBreadcrumb.vue +132 -128
- package/src/components/DatametriaButton.vue +191 -173
- package/src/components/DatametriaCard.vue +84 -66
- package/src/components/DatametriaCheckbox.vue +197 -193
- package/src/components/DatametriaCheckboxGroup.vue +56 -38
- package/src/components/DatametriaChip.vue +159 -141
- package/src/components/DatametriaContainer.vue +70 -52
- package/src/components/DatametriaDataTable.vue +318 -300
- package/src/components/DatametriaDatePicker.vue +396 -378
- package/src/components/DatametriaDialog.vue +297 -293
- package/src/components/DatametriaDivider.vue +105 -98
- package/src/components/DatametriaDropdown.vue +356 -350
- package/src/components/DatametriaEmpty.vue +155 -151
- package/src/components/DatametriaFileUpload.vue +413 -395
- package/src/components/DatametriaFloatingBar.vue +144 -126
- package/src/components/DatametriaForm.vue +174 -156
- package/src/components/DatametriaFormItem.vue +183 -179
- package/src/components/DatametriaGrid.vue +55 -37
- package/src/components/DatametriaInput.vue +314 -263
- package/src/components/DatametriaMenu.vue +618 -600
- package/src/components/DatametriaModal.vue +147 -129
- package/src/components/DatametriaNavbar.vue +277 -223
- package/src/components/DatametriaPagination.vue +375 -371
- package/src/components/DatametriaPasswordInput.vue +444 -426
- package/src/components/DatametriaPopconfirm.vue +240 -234
- package/src/components/DatametriaProgress.vue +228 -224
- package/src/components/DatametriaRadio.vue +151 -147
- package/src/components/DatametriaRadioGroup.vue +55 -37
- package/src/components/DatametriaResult.vue +135 -131
- package/src/components/DatametriaSelect.vue +311 -211
- package/src/components/DatametriaSidebar.vue +294 -222
- package/src/components/DatametriaSkeleton.vue +257 -234
- package/src/components/DatametriaSlider.vue +409 -391
- package/src/components/DatametriaSortableTable.vue +820 -802
- package/src/components/DatametriaSpinner.vue +114 -110
- package/src/components/DatametriaSteps.vue +318 -312
- package/src/components/DatametriaSwitch.vue +146 -142
- package/src/components/DatametriaTabPane.vue +94 -76
- package/src/components/DatametriaTable.vue +118 -100
- package/src/components/DatametriaTabs.vue +315 -297
- package/src/components/DatametriaTextarea.vue +213 -195
- package/src/components/DatametriaTimePicker.vue +317 -299
- package/src/components/DatametriaToast.vue +176 -176
- package/src/components/DatametriaTooltip.vue +421 -400
- package/src/components/DatametriaTree.vue +126 -122
- package/src/components/DatametriaTreeNode.vue +176 -172
- package/src/components/DatametriaUpload.vue +379 -361
- package/src/components/__tests__/DatametriaAlert.test.js +35 -35
- package/src/components/__tests__/DatametriaAlert.test.ts +190 -190
- package/src/components/__tests__/DatametriaAvatar.test.ts +151 -151
- package/src/components/__tests__/DatametriaBadge.test.js +29 -29
- package/src/components/__tests__/DatametriaBadge.test.ts +167 -167
- package/src/components/__tests__/DatametriaBreadcrumb.test.ts +187 -0
- package/src/components/__tests__/DatametriaButton.test.js +30 -30
- package/src/components/__tests__/DatametriaButton.test.ts +283 -283
- package/src/components/__tests__/DatametriaCard.test.ts +201 -201
- package/src/components/__tests__/DatametriaCheckbox.test.ts +204 -0
- package/src/components/__tests__/DatametriaChip.test.js +38 -38
- package/src/components/__tests__/DatametriaContainer.test.ts +52 -52
- package/src/components/__tests__/DatametriaDialog.test.ts +338 -0
- package/src/components/__tests__/DatametriaDivider.test.ts +54 -54
- package/src/components/__tests__/DatametriaDropdown.test.ts +357 -0
- package/src/components/__tests__/DatametriaEmpty.test.ts +261 -0
- package/src/components/__tests__/DatametriaFileUpload.test.ts +290 -290
- package/src/components/__tests__/DatametriaFloatingBar.test.ts +137 -137
- package/src/components/__tests__/DatametriaForm.test.ts +96 -0
- package/src/components/__tests__/DatametriaFormItem.test.ts +58 -0
- package/src/components/__tests__/DatametriaGrid.test.ts +31 -31
- package/src/components/__tests__/DatametriaInput.test.ts +72 -72
- package/src/components/__tests__/DatametriaMenu.test.ts +366 -366
- package/src/components/__tests__/DatametriaModal.test.ts +86 -86
- package/src/components/__tests__/DatametriaNavbar.test.js +48 -48
- package/src/components/__tests__/DatametriaNavbar.test.ts +203 -203
- package/src/components/__tests__/DatametriaPasswordInput.test.js +305 -305
- package/src/components/__tests__/DatametriaRadio.test.ts +195 -0
- package/src/components/__tests__/DatametriaSelect.test.ts +77 -77
- package/src/components/__tests__/DatametriaSidebar.test.ts +169 -169
- package/src/components/__tests__/DatametriaSlider.test.ts +261 -261
- package/src/components/__tests__/DatametriaSortableTable.test.js +168 -168
- package/src/components/__tests__/DatametriaSpinner.test.ts +156 -156
- package/src/components/__tests__/DatametriaSteps.test.ts +211 -0
- package/src/components/__tests__/DatametriaSwitch.test.ts +129 -0
- package/src/components/__tests__/DatametriaTabPane.test.ts +205 -0
- package/src/components/__tests__/DatametriaTable.test.ts +97 -97
- package/src/components/__tests__/DatametriaTabs.test.ts +232 -232
- package/src/components/__tests__/DatametriaToast.test.js +48 -48
- package/src/components/__tests__/DatametriaToast.test.ts +99 -99
- package/src/components/__tests__/DatametriaTree.test.ts +376 -0
- package/src/components/__tests__/index.test.ts +48 -0
- package/src/composables/useAccessibilityScale.ts +94 -94
- package/src/composables/useBreakpoints.ts +82 -82
- package/src/composables/useHapticFeedback.ts +439 -439
- package/src/composables/useRipple.ts +218 -218
- package/src/composables/useTheme.ts +5 -1
- package/src/index.ts +84 -84
- package/src/stories/Variants.stories.js +95 -95
- package/src/styles/design-tokens.css +623 -623
- package/src/theme/ThemeProvider.vue +96 -96
- package/src/theme/__tests__/ThemeProvider.test.ts +208 -208
- package/src/theme/__tests__/constants.test.ts +31 -31
- package/src/theme/__tests__/presets.test.ts +166 -166
- package/src/theme/__tests__/tokens.test.ts +155 -155
- package/src/theme/__tests__/types.test.ts +153 -153
- package/src/theme/__tests__/useTheme.test.ts +146 -146
- package/src/theme/constants.ts +14 -14
- package/src/theme/index.ts +12 -12
- package/src/theme/presets/datametria.ts +94 -94
- package/src/theme/presets/default.ts +94 -94
- package/src/theme/presets/index.ts +8 -8
- package/src/theme/tokens/colors.ts +28 -28
- package/src/theme/tokens/index.ts +47 -47
- package/src/theme/tokens/spacing.ts +21 -21
- package/src/theme/tokens/typography.ts +35 -35
- package/src/theme/types.ts +111 -111
- package/src/theme/useTheme.ts +28 -28
- package/src/types/index.ts +55 -55
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { mount } from '@vue/test-utils'
|
|
3
|
-
import DatametriaToast from '../DatametriaToast.vue'
|
|
4
|
-
|
|
5
|
-
describe('DatametriaToast', () => {
|
|
6
|
-
it('renders with primary variant', () => {
|
|
7
|
-
// Create body element for Teleport
|
|
8
|
-
const body = document.createElement('div')
|
|
9
|
-
document.body.appendChild(body)
|
|
10
|
-
|
|
11
|
-
const wrapper = mount(DatametriaToast, {
|
|
12
|
-
props: {
|
|
13
|
-
message: 'Test message',
|
|
14
|
-
variant: 'primary',
|
|
15
|
-
modelValue: true
|
|
16
|
-
},
|
|
17
|
-
attachTo: body
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
// Check if toast exists in document body
|
|
21
|
-
const toast = document.querySelector('.dm-toast')
|
|
22
|
-
expect(toast).toBeTruthy()
|
|
23
|
-
expect(toast.classList.contains('dm-toast--primary')).toBe(true)
|
|
24
|
-
|
|
25
|
-
wrapper.unmount()
|
|
26
|
-
document.body.removeChild(body)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('validates invalid variant in development', () => {
|
|
30
|
-
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
31
|
-
const originalEnv = process.env.NODE_ENV
|
|
32
|
-
process.env.NODE_ENV = 'development'
|
|
33
|
-
|
|
34
|
-
mount(DatametriaToast, {
|
|
35
|
-
props: {
|
|
36
|
-
message: 'Test',
|
|
37
|
-
variant: 'invalid',
|
|
38
|
-
modelValue: true
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
43
|
-
expect.stringContaining('[DatametriaToast] Invalid variant "invalid"')
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
process.env.NODE_ENV = originalEnv
|
|
47
|
-
consoleSpy.mockRestore()
|
|
48
|
-
})
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import DatametriaToast from '../DatametriaToast.vue'
|
|
4
|
+
|
|
5
|
+
describe('DatametriaToast', () => {
|
|
6
|
+
it('renders with primary variant', () => {
|
|
7
|
+
// Create body element for Teleport
|
|
8
|
+
const body = document.createElement('div')
|
|
9
|
+
document.body.appendChild(body)
|
|
10
|
+
|
|
11
|
+
const wrapper = mount(DatametriaToast, {
|
|
12
|
+
props: {
|
|
13
|
+
message: 'Test message',
|
|
14
|
+
variant: 'primary',
|
|
15
|
+
modelValue: true
|
|
16
|
+
},
|
|
17
|
+
attachTo: body
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// Check if toast exists in document body
|
|
21
|
+
const toast = document.querySelector('.dm-toast')
|
|
22
|
+
expect(toast).toBeTruthy()
|
|
23
|
+
expect(toast.classList.contains('dm-toast--primary')).toBe(true)
|
|
24
|
+
|
|
25
|
+
wrapper.unmount()
|
|
26
|
+
document.body.removeChild(body)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('validates invalid variant in development', () => {
|
|
30
|
+
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
31
|
+
const originalEnv = process.env.NODE_ENV
|
|
32
|
+
process.env.NODE_ENV = 'development'
|
|
33
|
+
|
|
34
|
+
mount(DatametriaToast, {
|
|
35
|
+
props: {
|
|
36
|
+
message: 'Test',
|
|
37
|
+
variant: 'invalid',
|
|
38
|
+
modelValue: true
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
43
|
+
expect.stringContaining('[DatametriaToast] Invalid variant "invalid"')
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
process.env.NODE_ENV = originalEnv
|
|
47
|
+
consoleSpy.mockRestore()
|
|
48
|
+
})
|
|
49
49
|
})
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
|
2
|
-
import { mount } from '@vue/test-utils'
|
|
3
|
-
import DatametriaToast from '../DatametriaToast.vue'
|
|
4
|
-
|
|
5
|
-
describe.skip('DatametriaToast', () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
vi.useFakeTimers()
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
vi.restoreAllMocks()
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('renders correctly when visible', () => {
|
|
15
|
-
const wrapper = mount(DatametriaToast, {
|
|
16
|
-
props: { message: 'Test message', modelValue: true }
|
|
17
|
-
})
|
|
18
|
-
expect(wrapper.html()).toContain('dm-toast')
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('displays message correctly', () => {
|
|
22
|
-
const wrapper = mount(DatametriaToast, {
|
|
23
|
-
props: { message: 'Test message', modelValue: true }
|
|
24
|
-
})
|
|
25
|
-
expect(wrapper.html()).toContain('Test message')
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('applies success variant class', () => {
|
|
29
|
-
const wrapper = mount(DatametriaToast, {
|
|
30
|
-
props: { message: 'Success', variant: 'success', modelValue: true }
|
|
31
|
-
})
|
|
32
|
-
expect(wrapper.html()).toContain('dm-toast--success')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('applies error variant class', () => {
|
|
36
|
-
const wrapper = mount(DatametriaToast, {
|
|
37
|
-
props: { message: 'Error', variant: 'error', modelValue: true }
|
|
38
|
-
})
|
|
39
|
-
expect(wrapper.html()).toContain('dm-toast--error')
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('applies warning variant class', () => {
|
|
43
|
-
const wrapper = mount(DatametriaToast, {
|
|
44
|
-
props: { message: 'Warning', variant: 'warning', modelValue: true }
|
|
45
|
-
})
|
|
46
|
-
expect(wrapper.html()).toContain('dm-toast--warning')
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('applies primary variant class', () => {
|
|
50
|
-
const wrapper = mount(DatametriaToast, {
|
|
51
|
-
props: { message: 'Primary', variant: 'primary', modelValue: true }
|
|
52
|
-
})
|
|
53
|
-
expect(wrapper.html()).toContain('dm-toast--primary')
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('applies info variant class', () => {
|
|
57
|
-
const wrapper = mount(DatametriaToast, {
|
|
58
|
-
props: { message: 'Info', variant: 'info', modelValue: true }
|
|
59
|
-
})
|
|
60
|
-
expect(wrapper.html()).toContain('dm-toast--info')
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('renders close button when closable', () => {
|
|
64
|
-
const wrapper = mount(DatametriaToast, {
|
|
65
|
-
props: { message: 'Test', closable: true, modelValue: true }
|
|
66
|
-
})
|
|
67
|
-
expect(wrapper.html()).toContain('dm-toast__close')
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('does not render close button when not closable', () => {
|
|
71
|
-
const wrapper = mount(DatametriaToast, {
|
|
72
|
-
props: { message: 'Test', closable: false, modelValue: true }
|
|
73
|
-
})
|
|
74
|
-
expect(wrapper.html()).not.toContain('dm-toast__close')
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('emits update:modelValue when close called', async () => {
|
|
78
|
-
const wrapper = mount(DatametriaToast, {
|
|
79
|
-
props: { message: 'Test', closable: true, modelValue: true }
|
|
80
|
-
})
|
|
81
|
-
await (wrapper.vm as any).close()
|
|
82
|
-
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([false])
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('emits close event when close called', async () => {
|
|
86
|
-
const wrapper = mount(DatametriaToast, {
|
|
87
|
-
props: { message: 'Test', closable: true, modelValue: true }
|
|
88
|
-
})
|
|
89
|
-
await (wrapper.vm as any).close()
|
|
90
|
-
expect(wrapper.emitted('close')).toBeTruthy()
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('uses CSS variables with fallbacks', () => {
|
|
94
|
-
const wrapper = mount(DatametriaToast, {
|
|
95
|
-
props: { message: 'Test', modelValue: true }
|
|
96
|
-
})
|
|
97
|
-
expect(wrapper.html()).toContain('--dm-')
|
|
98
|
-
})
|
|
99
|
-
})
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import DatametriaToast from '../DatametriaToast.vue'
|
|
4
|
+
|
|
5
|
+
describe.skip('DatametriaToast', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
vi.useFakeTimers()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
vi.restoreAllMocks()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('renders correctly when visible', () => {
|
|
15
|
+
const wrapper = mount(DatametriaToast, {
|
|
16
|
+
props: { message: 'Test message', modelValue: true }
|
|
17
|
+
})
|
|
18
|
+
expect(wrapper.html()).toContain('dm-toast')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('displays message correctly', () => {
|
|
22
|
+
const wrapper = mount(DatametriaToast, {
|
|
23
|
+
props: { message: 'Test message', modelValue: true }
|
|
24
|
+
})
|
|
25
|
+
expect(wrapper.html()).toContain('Test message')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('applies success variant class', () => {
|
|
29
|
+
const wrapper = mount(DatametriaToast, {
|
|
30
|
+
props: { message: 'Success', variant: 'success', modelValue: true }
|
|
31
|
+
})
|
|
32
|
+
expect(wrapper.html()).toContain('dm-toast--success')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('applies error variant class', () => {
|
|
36
|
+
const wrapper = mount(DatametriaToast, {
|
|
37
|
+
props: { message: 'Error', variant: 'error', modelValue: true }
|
|
38
|
+
})
|
|
39
|
+
expect(wrapper.html()).toContain('dm-toast--error')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('applies warning variant class', () => {
|
|
43
|
+
const wrapper = mount(DatametriaToast, {
|
|
44
|
+
props: { message: 'Warning', variant: 'warning', modelValue: true }
|
|
45
|
+
})
|
|
46
|
+
expect(wrapper.html()).toContain('dm-toast--warning')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('applies primary variant class', () => {
|
|
50
|
+
const wrapper = mount(DatametriaToast, {
|
|
51
|
+
props: { message: 'Primary', variant: 'primary', modelValue: true }
|
|
52
|
+
})
|
|
53
|
+
expect(wrapper.html()).toContain('dm-toast--primary')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('applies info variant class', () => {
|
|
57
|
+
const wrapper = mount(DatametriaToast, {
|
|
58
|
+
props: { message: 'Info', variant: 'info', modelValue: true }
|
|
59
|
+
})
|
|
60
|
+
expect(wrapper.html()).toContain('dm-toast--info')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('renders close button when closable', () => {
|
|
64
|
+
const wrapper = mount(DatametriaToast, {
|
|
65
|
+
props: { message: 'Test', closable: true, modelValue: true }
|
|
66
|
+
})
|
|
67
|
+
expect(wrapper.html()).toContain('dm-toast__close')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('does not render close button when not closable', () => {
|
|
71
|
+
const wrapper = mount(DatametriaToast, {
|
|
72
|
+
props: { message: 'Test', closable: false, modelValue: true }
|
|
73
|
+
})
|
|
74
|
+
expect(wrapper.html()).not.toContain('dm-toast__close')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('emits update:modelValue when close called', async () => {
|
|
78
|
+
const wrapper = mount(DatametriaToast, {
|
|
79
|
+
props: { message: 'Test', closable: true, modelValue: true }
|
|
80
|
+
})
|
|
81
|
+
await (wrapper.vm as any).close()
|
|
82
|
+
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([false])
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('emits close event when close called', async () => {
|
|
86
|
+
const wrapper = mount(DatametriaToast, {
|
|
87
|
+
props: { message: 'Test', closable: true, modelValue: true }
|
|
88
|
+
})
|
|
89
|
+
await (wrapper.vm as any).close()
|
|
90
|
+
expect(wrapper.emitted('close')).toBeTruthy()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('uses CSS variables with fallbacks', () => {
|
|
94
|
+
const wrapper = mount(DatametriaToast, {
|
|
95
|
+
props: { message: 'Test', modelValue: true }
|
|
96
|
+
})
|
|
97
|
+
expect(wrapper.html()).toContain('--dm-')
|
|
98
|
+
})
|
|
99
|
+
})
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import DatametriaTree from '../DatametriaTree.vue'
|
|
4
|
+
import type { TreeNode } from '../src/components/DatametriaTree.vue'
|
|
5
|
+
|
|
6
|
+
describe('DatametriaTree', () => {
|
|
7
|
+
const mockData: TreeNode[] = [
|
|
8
|
+
{
|
|
9
|
+
id: '1',
|
|
10
|
+
label: 'Node 1',
|
|
11
|
+
children: [
|
|
12
|
+
{ id: '1-1', label: 'Node 1-1' },
|
|
13
|
+
{ id: '1-2', label: 'Node 1-2' }
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: '2',
|
|
18
|
+
label: 'Node 2',
|
|
19
|
+
children: [
|
|
20
|
+
{
|
|
21
|
+
id: '2-1',
|
|
22
|
+
label: 'Node 2-1',
|
|
23
|
+
children: [
|
|
24
|
+
{ id: '2-1-1', label: 'Node 2-1-1' }
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{ id: '3', label: 'Node 3' }
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
describe('Rendering', () => {
|
|
33
|
+
it('renders correctly', () => {
|
|
34
|
+
const wrapper = mount(DatametriaTree, {
|
|
35
|
+
props: { data: mockData }
|
|
36
|
+
})
|
|
37
|
+
expect(wrapper.find('.datametria-tree').exists()).toBe(true)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('renders all root nodes', () => {
|
|
41
|
+
const wrapper = mount(DatametriaTree, {
|
|
42
|
+
props: { data: mockData }
|
|
43
|
+
})
|
|
44
|
+
const nodes = wrapper.findAll('.datametria-tree-node')
|
|
45
|
+
expect(nodes.length).toBeGreaterThanOrEqual(3)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('renders node labels', () => {
|
|
49
|
+
const wrapper = mount(DatametriaTree, {
|
|
50
|
+
props: { data: mockData }
|
|
51
|
+
})
|
|
52
|
+
expect(wrapper.text()).toContain('Node 1')
|
|
53
|
+
expect(wrapper.text()).toContain('Node 2')
|
|
54
|
+
expect(wrapper.text()).toContain('Node 3')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('renders with custom nodeKey', () => {
|
|
58
|
+
const customData = [
|
|
59
|
+
{ key: 'a', name: 'Item A' },
|
|
60
|
+
{ key: 'b', name: 'Item B' }
|
|
61
|
+
]
|
|
62
|
+
const wrapper = mount(DatametriaTree, {
|
|
63
|
+
props: { data: customData, nodeKey: 'key' }
|
|
64
|
+
})
|
|
65
|
+
expect(wrapper.text()).toContain('Item A')
|
|
66
|
+
expect(wrapper.text()).toContain('Item B')
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
describe('Expand/Collapse', () => {
|
|
71
|
+
it('nodes are collapsed by default', () => {
|
|
72
|
+
const wrapper = mount(DatametriaTree, {
|
|
73
|
+
props: { data: mockData }
|
|
74
|
+
})
|
|
75
|
+
expect(wrapper.text()).not.toContain('Node 1-1')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('expands node on click', async () => {
|
|
79
|
+
const wrapper = mount(DatametriaTree, {
|
|
80
|
+
props: { data: mockData }
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const firstNode = wrapper.find('.datametria-tree-node__content')
|
|
84
|
+
await firstNode.trigger('click')
|
|
85
|
+
|
|
86
|
+
expect(wrapper.text()).toContain('Node 1-1')
|
|
87
|
+
expect(wrapper.text()).toContain('Node 1-2')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('collapses expanded node on click', async () => {
|
|
91
|
+
const wrapper = mount(DatametriaTree, {
|
|
92
|
+
props: { data: mockData }
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
const firstNode = wrapper.find('.datametria-tree-node__content')
|
|
96
|
+
await firstNode.trigger('click')
|
|
97
|
+
expect(wrapper.text()).toContain('Node 1-1')
|
|
98
|
+
|
|
99
|
+
await firstNode.trigger('click')
|
|
100
|
+
expect(wrapper.text()).not.toContain('Node 1-1')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('expands all nodes when defaultExpandAll is true', () => {
|
|
104
|
+
const wrapper = mount(DatametriaTree, {
|
|
105
|
+
props: { data: mockData, defaultExpandAll: true }
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
expect(wrapper.text()).toContain('Node 1-1')
|
|
109
|
+
expect(wrapper.text()).toContain('Node 1-2')
|
|
110
|
+
expect(wrapper.text()).toContain('Node 2-1')
|
|
111
|
+
expect(wrapper.text()).toContain('Node 2-1-1')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('expands specific nodes with defaultExpandedKeys', () => {
|
|
115
|
+
const wrapper = mount(DatametriaTree, {
|
|
116
|
+
props: {
|
|
117
|
+
data: mockData,
|
|
118
|
+
defaultExpandedKeys: ['1']
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
expect(wrapper.text()).toContain('Node 1-1')
|
|
123
|
+
expect(wrapper.text()).toContain('Node 1-2')
|
|
124
|
+
expect(wrapper.text()).not.toContain('Node 2-1')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('shows expand icon for parent nodes', () => {
|
|
128
|
+
const wrapper = mount(DatametriaTree, {
|
|
129
|
+
props: { data: mockData }
|
|
130
|
+
})
|
|
131
|
+
const expandIcons = wrapper.findAll('.datametria-tree-node__icon')
|
|
132
|
+
expect(expandIcons.length).toBeGreaterThan(0)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('changes icon when expanded', async () => {
|
|
136
|
+
const wrapper = mount(DatametriaTree, {
|
|
137
|
+
props: { data: mockData }
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const expandIcon = wrapper.find('.datametria-tree-node__icon')
|
|
141
|
+
expect(expandIcon.text()).toBe('▶')
|
|
142
|
+
|
|
143
|
+
const firstNode = wrapper.find('.datametria-tree-node__content')
|
|
144
|
+
await firstNode.trigger('click')
|
|
145
|
+
|
|
146
|
+
expect(expandIcon.text()).toBe('▼')
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
describe('Checkable', () => {
|
|
151
|
+
it('does not show checkboxes by default', () => {
|
|
152
|
+
const wrapper = mount(DatametriaTree, {
|
|
153
|
+
props: { data: mockData }
|
|
154
|
+
})
|
|
155
|
+
expect(wrapper.find('.datametria-tree-node__checkbox').exists()).toBe(false)
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('shows checkboxes when checkable is true', () => {
|
|
159
|
+
const wrapper = mount(DatametriaTree, {
|
|
160
|
+
props: { data: mockData, checkable: true }
|
|
161
|
+
})
|
|
162
|
+
const checkboxes = wrapper.findAll('.datametria-tree-node__checkbox')
|
|
163
|
+
expect(checkboxes.length).toBeGreaterThan(0)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('checks node when checkbox is clicked', async () => {
|
|
167
|
+
const wrapper = mount(DatametriaTree, {
|
|
168
|
+
props: { data: mockData, checkable: true }
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
const checkbox = wrapper.find('.datametria-tree-node__checkbox')
|
|
172
|
+
await checkbox.setValue(true)
|
|
173
|
+
|
|
174
|
+
expect((checkbox.element as HTMLInputElement).checked).toBe(true)
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('checks specific nodes with defaultCheckedKeys', () => {
|
|
178
|
+
const wrapper = mount(DatametriaTree, {
|
|
179
|
+
props: {
|
|
180
|
+
data: mockData,
|
|
181
|
+
checkable: true,
|
|
182
|
+
defaultCheckedKeys: ['1', '3']
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const checkboxes = wrapper.findAll('.datametria-tree-node__checkbox')
|
|
187
|
+
expect((checkboxes[0].element as HTMLInputElement).checked).toBe(true)
|
|
188
|
+
})
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
describe('Events', () => {
|
|
192
|
+
it('emits nodeExpand when node is expanded', async () => {
|
|
193
|
+
const wrapper = mount(DatametriaTree, {
|
|
194
|
+
props: { data: mockData }
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
const firstNode = wrapper.find('.datametria-tree-node__content')
|
|
198
|
+
await firstNode.trigger('click')
|
|
199
|
+
|
|
200
|
+
expect(wrapper.emitted('nodeExpand')).toBeTruthy()
|
|
201
|
+
expect(wrapper.emitted('nodeExpand')?.[0][0]).toEqual(mockData[0])
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it('emits nodeCollapse when node is collapsed', async () => {
|
|
205
|
+
const wrapper = mount(DatametriaTree, {
|
|
206
|
+
props: { data: mockData }
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
const firstNode = wrapper.find('.datametria-tree-node__content')
|
|
210
|
+
await firstNode.trigger('click')
|
|
211
|
+
await firstNode.trigger('click')
|
|
212
|
+
|
|
213
|
+
expect(wrapper.emitted('nodeCollapse')).toBeTruthy()
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
it('emits check event when checkbox is changed', async () => {
|
|
217
|
+
const wrapper = mount(DatametriaTree, {
|
|
218
|
+
props: { data: mockData, checkable: true }
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
const checkbox = wrapper.find('.datametria-tree-node__checkbox')
|
|
222
|
+
await checkbox.setValue(true)
|
|
223
|
+
|
|
224
|
+
expect(wrapper.emitted('check')).toBeTruthy()
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
describe('Props', () => {
|
|
229
|
+
it('accepts data prop', () => {
|
|
230
|
+
const wrapper = mount(DatametriaTree, {
|
|
231
|
+
props: { data: mockData }
|
|
232
|
+
})
|
|
233
|
+
expect(wrapper.props('data')).toEqual(mockData)
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
it('accepts nodeKey prop', () => {
|
|
237
|
+
const wrapper = mount(DatametriaTree, {
|
|
238
|
+
props: { data: mockData, nodeKey: 'id' }
|
|
239
|
+
})
|
|
240
|
+
expect(wrapper.props('nodeKey')).toBe('id')
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it('accepts defaultExpandAll prop', () => {
|
|
244
|
+
const wrapper = mount(DatametriaTree, {
|
|
245
|
+
props: { data: mockData, defaultExpandAll: true }
|
|
246
|
+
})
|
|
247
|
+
expect(wrapper.props('defaultExpandAll')).toBe(true)
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
it('accepts checkable prop', () => {
|
|
251
|
+
const wrapper = mount(DatametriaTree, {
|
|
252
|
+
props: { data: mockData, checkable: true }
|
|
253
|
+
})
|
|
254
|
+
expect(wrapper.props('checkable')).toBe(true)
|
|
255
|
+
})
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
describe('Methods', () => {
|
|
259
|
+
it('exposes expandAll method', () => {
|
|
260
|
+
const wrapper = mount(DatametriaTree, {
|
|
261
|
+
props: { data: mockData }
|
|
262
|
+
})
|
|
263
|
+
expect(wrapper.vm.expandAll).toBeDefined()
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
it('exposes collapseAll method', () => {
|
|
267
|
+
const wrapper = mount(DatametriaTree, {
|
|
268
|
+
props: { data: mockData }
|
|
269
|
+
})
|
|
270
|
+
expect(wrapper.vm.collapseAll).toBeDefined()
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
it('expandAll expands all nodes', async () => {
|
|
274
|
+
const wrapper = mount(DatametriaTree, {
|
|
275
|
+
props: { data: mockData }
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
expect(wrapper.text()).not.toContain('Node 1-1')
|
|
279
|
+
|
|
280
|
+
wrapper.vm.expandAll()
|
|
281
|
+
await wrapper.vm.$nextTick()
|
|
282
|
+
|
|
283
|
+
expect(wrapper.text()).toContain('Node 1-1')
|
|
284
|
+
expect(wrapper.text()).toContain('Node 2-1-1')
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
it('collapseAll collapses all nodes', async () => {
|
|
288
|
+
const wrapper = mount(DatametriaTree, {
|
|
289
|
+
props: { data: mockData, defaultExpandAll: true }
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
expect(wrapper.text()).toContain('Node 1-1')
|
|
293
|
+
|
|
294
|
+
wrapper.vm.collapseAll()
|
|
295
|
+
await wrapper.vm.$nextTick()
|
|
296
|
+
|
|
297
|
+
expect(wrapper.text()).not.toContain('Node 1-1')
|
|
298
|
+
})
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
describe('Accessibility', () => {
|
|
302
|
+
it('has role tree', () => {
|
|
303
|
+
const wrapper = mount(DatametriaTree, {
|
|
304
|
+
props: { data: mockData }
|
|
305
|
+
})
|
|
306
|
+
expect(wrapper.attributes('role')).toBe('tree')
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
it('tree nodes have role treeitem', () => {
|
|
310
|
+
const wrapper = mount(DatametriaTree, {
|
|
311
|
+
props: { data: mockData }
|
|
312
|
+
})
|
|
313
|
+
const nodes = wrapper.findAll('[role="treeitem"]')
|
|
314
|
+
expect(nodes.length).toBeGreaterThan(0)
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
it('expanded nodes have aria-expanded true', async () => {
|
|
318
|
+
const wrapper = mount(DatametriaTree, {
|
|
319
|
+
props: { data: mockData }
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
const firstNode = wrapper.find('.datametria-tree-node__content')
|
|
323
|
+
await firstNode.trigger('click')
|
|
324
|
+
|
|
325
|
+
const treeItem = wrapper.find('[role="treeitem"]')
|
|
326
|
+
expect(treeItem.attributes('aria-expanded')).toBe('true')
|
|
327
|
+
})
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
describe('Edge Cases', () => {
|
|
331
|
+
it('renders with empty data', () => {
|
|
332
|
+
const wrapper = mount(DatametriaTree, {
|
|
333
|
+
props: { data: [] }
|
|
334
|
+
})
|
|
335
|
+
expect(wrapper.find('.datametria-tree').exists()).toBe(true)
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it('handles nodes without children', () => {
|
|
339
|
+
const simpleData = [{ id: '1', label: 'Leaf Node' }]
|
|
340
|
+
const wrapper = mount(DatametriaTree, {
|
|
341
|
+
props: { data: simpleData }
|
|
342
|
+
})
|
|
343
|
+
expect(wrapper.text()).toContain('Leaf Node')
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
it('handles deeply nested nodes', () => {
|
|
347
|
+
const deepData = [
|
|
348
|
+
{
|
|
349
|
+
id: '1',
|
|
350
|
+
label: 'Level 1',
|
|
351
|
+
children: [
|
|
352
|
+
{
|
|
353
|
+
id: '1-1',
|
|
354
|
+
label: 'Level 2',
|
|
355
|
+
children: [
|
|
356
|
+
{
|
|
357
|
+
id: '1-1-1',
|
|
358
|
+
label: 'Level 3',
|
|
359
|
+
children: [
|
|
360
|
+
{ id: '1-1-1-1', label: 'Level 4' }
|
|
361
|
+
]
|
|
362
|
+
}
|
|
363
|
+
]
|
|
364
|
+
}
|
|
365
|
+
]
|
|
366
|
+
}
|
|
367
|
+
]
|
|
368
|
+
|
|
369
|
+
const wrapper = mount(DatametriaTree, {
|
|
370
|
+
props: { data: deepData, defaultExpandAll: true }
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
expect(wrapper.text()).toContain('Level 4')
|
|
374
|
+
})
|
|
375
|
+
})
|
|
376
|
+
})
|