@datametria/vue-components 2.3.1 → 2.4.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.
Files changed (126) hide show
  1. package/README.md +625 -594
  2. package/dist/index.es.js +1962 -1887
  3. package/dist/index.umd.js +6 -6
  4. package/dist/src/components/DatametriaForm.vue.d.ts +1 -1
  5. package/dist/src/components/DatametriaInput.vue.d.ts +9 -1
  6. package/dist/src/components/DatametriaSelect.vue.d.ts +10 -1
  7. package/dist/vue-components.css +1 -1
  8. package/package.json +103 -102
  9. package/src/components/DatametriaAlert.vue +151 -133
  10. package/src/components/DatametriaAutocomplete.vue +250 -229
  11. package/src/components/DatametriaAvatar.vue +256 -238
  12. package/src/components/DatametriaBadge.vue +101 -96
  13. package/src/components/DatametriaBreadcrumb.vue +132 -128
  14. package/src/components/DatametriaButton.vue +191 -173
  15. package/src/components/DatametriaCard.vue +84 -66
  16. package/src/components/DatametriaCheckbox.vue +197 -193
  17. package/src/components/DatametriaChip.vue +159 -141
  18. package/src/components/DatametriaContainer.vue +70 -52
  19. package/src/components/DatametriaDataTable.vue +318 -300
  20. package/src/components/DatametriaDatePicker.vue +396 -378
  21. package/src/components/DatametriaDialog.vue +297 -293
  22. package/src/components/DatametriaDivider.vue +105 -98
  23. package/src/components/DatametriaDropdown.vue +356 -350
  24. package/src/components/DatametriaEmpty.vue +155 -151
  25. package/src/components/DatametriaFileUpload.vue +413 -395
  26. package/src/components/DatametriaFloatingBar.vue +144 -126
  27. package/src/components/DatametriaForm.vue +174 -156
  28. package/src/components/DatametriaFormItem.vue +183 -179
  29. package/src/components/DatametriaGrid.vue +55 -37
  30. package/src/components/DatametriaInput.vue +314 -263
  31. package/src/components/DatametriaMenu.vue +618 -600
  32. package/src/components/DatametriaModal.vue +147 -129
  33. package/src/components/DatametriaNavbar.vue +277 -223
  34. package/src/components/DatametriaPagination.vue +375 -371
  35. package/src/components/DatametriaPasswordInput.vue +446 -426
  36. package/src/components/DatametriaPopconfirm.vue +240 -234
  37. package/src/components/DatametriaProgress.vue +228 -224
  38. package/src/components/DatametriaRadio.vue +151 -147
  39. package/src/components/DatametriaResult.vue +135 -131
  40. package/src/components/DatametriaSelect.vue +311 -211
  41. package/src/components/DatametriaSidebar.vue +294 -222
  42. package/src/components/DatametriaSkeleton.vue +257 -234
  43. package/src/components/DatametriaSlider.vue +409 -391
  44. package/src/components/DatametriaSortableTable.vue +826 -802
  45. package/src/components/DatametriaSpinner.vue +114 -110
  46. package/src/components/DatametriaSteps.vue +318 -312
  47. package/src/components/DatametriaSwitch.vue +146 -142
  48. package/src/components/DatametriaTabPane.vue +94 -76
  49. package/src/components/DatametriaTable.vue +118 -100
  50. package/src/components/DatametriaTabs.vue +315 -297
  51. package/src/components/DatametriaTextarea.vue +213 -195
  52. package/src/components/DatametriaTimePicker.vue +317 -299
  53. package/src/components/DatametriaToast.vue +176 -176
  54. package/src/components/DatametriaTooltip.vue +421 -400
  55. package/src/components/DatametriaTree.vue +126 -122
  56. package/src/components/DatametriaTreeNode.vue +176 -172
  57. package/src/components/DatametriaUpload.vue +379 -361
  58. package/src/components/__tests__/DatametriaAlert.test.js +35 -35
  59. package/src/components/__tests__/DatametriaAlert.test.ts +190 -190
  60. package/src/components/__tests__/DatametriaAvatar.test.ts +151 -151
  61. package/src/components/__tests__/DatametriaBadge.test.js +29 -29
  62. package/src/components/__tests__/DatametriaBadge.test.ts +167 -167
  63. package/src/components/__tests__/DatametriaBreadcrumb.test.ts +187 -0
  64. package/src/components/__tests__/DatametriaButton.test.js +30 -30
  65. package/src/components/__tests__/DatametriaButton.test.ts +283 -283
  66. package/src/components/__tests__/DatametriaCard.test.ts +201 -201
  67. package/src/components/__tests__/DatametriaCheckbox.test.ts +204 -0
  68. package/src/components/__tests__/DatametriaChip.test.js +38 -38
  69. package/src/components/__tests__/DatametriaContainer.test.ts +52 -52
  70. package/src/components/__tests__/DatametriaDialog.test.ts +338 -0
  71. package/src/components/__tests__/DatametriaDivider.test.ts +54 -54
  72. package/src/components/__tests__/DatametriaDropdown.test.ts +357 -0
  73. package/src/components/__tests__/DatametriaEmpty.test.ts +261 -0
  74. package/src/components/__tests__/DatametriaFileUpload.test.ts +290 -290
  75. package/src/components/__tests__/DatametriaFloatingBar.test.ts +137 -137
  76. package/src/components/__tests__/DatametriaForm.test.ts +96 -0
  77. package/src/components/__tests__/DatametriaFormItem.test.ts +58 -0
  78. package/src/components/__tests__/DatametriaGrid.test.ts +31 -31
  79. package/src/components/__tests__/DatametriaInput.test.ts +72 -72
  80. package/src/components/__tests__/DatametriaMenu.test.ts +366 -366
  81. package/src/components/__tests__/DatametriaModal.test.ts +86 -86
  82. package/src/components/__tests__/DatametriaNavbar.test.js +48 -48
  83. package/src/components/__tests__/DatametriaNavbar.test.ts +203 -203
  84. package/src/components/__tests__/DatametriaPasswordInput.test.js +305 -305
  85. package/src/components/__tests__/DatametriaRadio.test.ts +195 -0
  86. package/src/components/__tests__/DatametriaSelect.test.ts +77 -77
  87. package/src/components/__tests__/DatametriaSidebar.test.ts +169 -169
  88. package/src/components/__tests__/DatametriaSlider.test.ts +261 -261
  89. package/src/components/__tests__/DatametriaSortableTable.test.js +168 -168
  90. package/src/components/__tests__/DatametriaSpinner.test.ts +156 -156
  91. package/src/components/__tests__/DatametriaSteps.test.ts +211 -0
  92. package/src/components/__tests__/DatametriaSwitch.test.ts +129 -0
  93. package/src/components/__tests__/DatametriaTabPane.test.ts +205 -0
  94. package/src/components/__tests__/DatametriaTable.test.ts +97 -97
  95. package/src/components/__tests__/DatametriaTabs.test.ts +232 -232
  96. package/src/components/__tests__/DatametriaToast.test.js +48 -48
  97. package/src/components/__tests__/DatametriaToast.test.ts +99 -99
  98. package/src/components/__tests__/DatametriaTree.test.ts +376 -0
  99. package/src/components/__tests__/index.test.ts +48 -0
  100. package/src/composables/useAccessibilityScale.ts +94 -94
  101. package/src/composables/useBreakpoints.ts +82 -82
  102. package/src/composables/useHapticFeedback.ts +439 -439
  103. package/src/composables/useRipple.ts +218 -218
  104. package/src/composables/useTheme.ts +5 -1
  105. package/src/index.ts +84 -84
  106. package/src/stories/Variants.stories.js +95 -95
  107. package/src/styles/design-tokens.css +623 -623
  108. package/src/theme/ThemeProvider.vue +96 -96
  109. package/src/theme/__tests__/ThemeProvider.test.ts +208 -208
  110. package/src/theme/__tests__/constants.test.ts +31 -31
  111. package/src/theme/__tests__/presets.test.ts +166 -166
  112. package/src/theme/__tests__/tokens.test.ts +155 -155
  113. package/src/theme/__tests__/types.test.ts +153 -153
  114. package/src/theme/__tests__/useTheme.test.ts +146 -146
  115. package/src/theme/constants.ts +14 -14
  116. package/src/theme/index.ts +12 -12
  117. package/src/theme/presets/datametria.ts +94 -94
  118. package/src/theme/presets/default.ts +94 -94
  119. package/src/theme/presets/index.ts +8 -8
  120. package/src/theme/tokens/colors.ts +28 -28
  121. package/src/theme/tokens/index.ts +47 -47
  122. package/src/theme/tokens/spacing.ts +21 -21
  123. package/src/theme/tokens/typography.ts +35 -35
  124. package/src/theme/types.ts +111 -111
  125. package/src/theme/useTheme.ts +28 -28
  126. package/src/types/index.ts +55 -55
@@ -1,97 +1,97 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { mount } from '@vue/test-utils'
3
- import DatametriaTable from '../DatametriaTable.vue'
4
-
5
- describe('DatametriaTable', () => {
6
- const columns = [
7
- { key: 'name', label: 'Name' },
8
- { key: 'email', label: 'Email' },
9
- { key: 'age', label: 'Age' }
10
- ]
11
-
12
- const data = [
13
- { name: 'John Doe', email: 'john@example.com', age: 30 },
14
- { name: 'Jane Smith', email: 'jane@example.com', age: 25 }
15
- ]
16
-
17
- it('renders correctly', () => {
18
- const wrapper = mount(DatametriaTable, {
19
- props: { columns, data }
20
- })
21
- expect(wrapper.find('.datametria-table').exists()).toBe(true)
22
- })
23
-
24
- it('renders table headers correctly', () => {
25
- const wrapper = mount(DatametriaTable, {
26
- props: { columns, data }
27
- })
28
- const headers = wrapper.findAll('.datametria-table__th')
29
- expect(headers).toHaveLength(3)
30
- expect(headers[0].text()).toBe('Name')
31
- expect(headers[1].text()).toBe('Email')
32
- expect(headers[2].text()).toBe('Age')
33
- })
34
-
35
- it('renders table rows correctly', () => {
36
- const wrapper = mount(DatametriaTable, {
37
- props: { columns, data }
38
- })
39
- const rows = wrapper.findAll('.datametria-table__tr')
40
- expect(rows).toHaveLength(2)
41
- })
42
-
43
- it('renders table cells correctly', () => {
44
- const wrapper = mount(DatametriaTable, {
45
- props: { columns, data }
46
- })
47
- const cells = wrapper.findAll('.datametria-table__td')
48
- expect(cells[0].text()).toBe('John Doe')
49
- expect(cells[1].text()).toBe('john@example.com')
50
- expect(cells[2].text()).toBe('30')
51
- })
52
-
53
- it('shows empty state when no data', () => {
54
- const wrapper = mount(DatametriaTable, {
55
- props: { columns, data: [] }
56
- })
57
- expect(wrapper.find('.datametria-table__empty').exists()).toBe(true)
58
- expect(wrapper.find('.datametria-table__empty').text()).toBe('Nenhum dado disponível')
59
- })
60
-
61
- it('renders custom empty slot', () => {
62
- const wrapper = mount(DatametriaTable, {
63
- props: { columns, data: [] },
64
- slots: { empty: 'Custom empty message' }
65
- })
66
- expect(wrapper.find('.datametria-table__empty').text()).toBe('Custom empty message')
67
- })
68
-
69
- it('applies column width when specified', () => {
70
- const columnsWithWidth = [
71
- { key: 'name', label: 'Name', width: '200px' },
72
- { key: 'email', label: 'Email' }
73
- ]
74
- const wrapper = mount(DatametriaTable, {
75
- props: { columns: columnsWithWidth, data }
76
- })
77
- const firstHeader = wrapper.find('.datametria-table__th')
78
- expect(firstHeader.attributes('style')).toContain('width: 200px')
79
- })
80
-
81
- it('renders custom cell slot', () => {
82
- const wrapper = mount(DatametriaTable, {
83
- props: { columns, data },
84
- slots: {
85
- 'cell-name': '<strong>Custom Name</strong>'
86
- }
87
- })
88
- expect(wrapper.html()).toContain('<strong>Custom Name</strong>')
89
- })
90
-
91
- it('uses CSS variables with fallbacks', () => {
92
- const wrapper = mount(DatametriaTable, {
93
- props: { columns, data }
94
- })
95
- expect(wrapper.html()).toContain('datametria-table')
96
- })
97
- })
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import DatametriaTable from '../DatametriaTable.vue'
4
+
5
+ describe('DatametriaTable', () => {
6
+ const columns = [
7
+ { key: 'name', label: 'Name' },
8
+ { key: 'email', label: 'Email' },
9
+ { key: 'age', label: 'Age' }
10
+ ]
11
+
12
+ const data = [
13
+ { name: 'John Doe', email: 'john@example.com', age: 30 },
14
+ { name: 'Jane Smith', email: 'jane@example.com', age: 25 }
15
+ ]
16
+
17
+ it('renders correctly', () => {
18
+ const wrapper = mount(DatametriaTable, {
19
+ props: { columns, data }
20
+ })
21
+ expect(wrapper.find('.datametria-table').exists()).toBe(true)
22
+ })
23
+
24
+ it('renders table headers correctly', () => {
25
+ const wrapper = mount(DatametriaTable, {
26
+ props: { columns, data }
27
+ })
28
+ const headers = wrapper.findAll('.datametria-table__th')
29
+ expect(headers).toHaveLength(3)
30
+ expect(headers[0].text()).toBe('Name')
31
+ expect(headers[1].text()).toBe('Email')
32
+ expect(headers[2].text()).toBe('Age')
33
+ })
34
+
35
+ it('renders table rows correctly', () => {
36
+ const wrapper = mount(DatametriaTable, {
37
+ props: { columns, data }
38
+ })
39
+ const rows = wrapper.findAll('.datametria-table__tr')
40
+ expect(rows).toHaveLength(2)
41
+ })
42
+
43
+ it('renders table cells correctly', () => {
44
+ const wrapper = mount(DatametriaTable, {
45
+ props: { columns, data }
46
+ })
47
+ const cells = wrapper.findAll('.datametria-table__td')
48
+ expect(cells[0].text()).toBe('John Doe')
49
+ expect(cells[1].text()).toBe('john@example.com')
50
+ expect(cells[2].text()).toBe('30')
51
+ })
52
+
53
+ it('shows empty state when no data', () => {
54
+ const wrapper = mount(DatametriaTable, {
55
+ props: { columns, data: [] }
56
+ })
57
+ expect(wrapper.find('.datametria-table__empty').exists()).toBe(true)
58
+ expect(wrapper.find('.datametria-table__empty').text()).toBe('Nenhum dado disponível')
59
+ })
60
+
61
+ it('renders custom empty slot', () => {
62
+ const wrapper = mount(DatametriaTable, {
63
+ props: { columns, data: [] },
64
+ slots: { empty: 'Custom empty message' }
65
+ })
66
+ expect(wrapper.find('.datametria-table__empty').text()).toBe('Custom empty message')
67
+ })
68
+
69
+ it('applies column width when specified', () => {
70
+ const columnsWithWidth = [
71
+ { key: 'name', label: 'Name', width: '200px' },
72
+ { key: 'email', label: 'Email' }
73
+ ]
74
+ const wrapper = mount(DatametriaTable, {
75
+ props: { columns: columnsWithWidth, data }
76
+ })
77
+ const firstHeader = wrapper.find('.datametria-table__th')
78
+ expect(firstHeader.attributes('style')).toContain('width: 200px')
79
+ })
80
+
81
+ it('renders custom cell slot', () => {
82
+ const wrapper = mount(DatametriaTable, {
83
+ props: { columns, data },
84
+ slots: {
85
+ 'cell-name': '<strong>Custom Name</strong>'
86
+ }
87
+ })
88
+ expect(wrapper.html()).toContain('<strong>Custom Name</strong>')
89
+ })
90
+
91
+ it('uses CSS variables with fallbacks', () => {
92
+ const wrapper = mount(DatametriaTable, {
93
+ props: { columns, data }
94
+ })
95
+ expect(wrapper.html()).toContain('datametria-table')
96
+ })
97
+ })
@@ -1,232 +1,232 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { mount } from '@vue/test-utils'
3
- import DatametriaTabs from '../DatametriaTabs.vue'
4
-
5
- describe('DatametriaTabs', () => {
6
- const tabs = ['Tab 1', 'Tab 2', 'Tab 3']
7
-
8
- it('renders correctly', () => {
9
- const wrapper = mount(DatametriaTabs, { props: { tabs } })
10
- expect(wrapper.find('.dm-tabs').exists()).toBe(true)
11
- })
12
-
13
- it('renders all tabs', () => {
14
- const wrapper = mount(DatametriaTabs, { props: { tabs } })
15
- const tabButtons = wrapper.findAll('.dm-tabs__tab')
16
- expect(tabButtons).toHaveLength(3)
17
- expect(tabButtons[0].text()).toBe('Tab 1')
18
- expect(tabButtons[1].text()).toBe('Tab 2')
19
- expect(tabButtons[2].text()).toBe('Tab 3')
20
- })
21
-
22
- it('applies variant classes', () => {
23
- const variants = ['default', 'pills', 'underline'] as const
24
- variants.forEach(variant => {
25
- const wrapper = mount(DatametriaTabs, { props: { tabs, variant } })
26
- expect(wrapper.find(`.dm-tabs--${variant}`).exists()).toBe(true)
27
- })
28
- })
29
-
30
- it('applies orientation classes', () => {
31
- const horizontal = mount(DatametriaTabs, { props: { tabs, orientation: 'horizontal' } })
32
- expect(horizontal.find('.dm-tabs--horizontal').exists()).toBe(true)
33
-
34
- const vertical = mount(DatametriaTabs, { props: { tabs, orientation: 'vertical' } })
35
- expect(vertical.find('.dm-tabs--vertical').exists()).toBe(true)
36
- })
37
-
38
- it('sets first tab as active by default', () => {
39
- const wrapper = mount(DatametriaTabs, { props: { tabs } })
40
- expect(wrapper.findAll('.dm-tabs__tab')[0].classes()).toContain('dm-tabs__tab--active')
41
- })
42
-
43
- it('respects modelValue prop', () => {
44
- const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 1 } })
45
- expect(wrapper.findAll('.dm-tabs__tab')[1].classes()).toContain('dm-tabs__tab--active')
46
- })
47
-
48
- it('changes active tab on click', async () => {
49
- const wrapper = mount(DatametriaTabs, { props: { tabs } })
50
- await wrapper.findAll('.dm-tabs__tab')[1].trigger('click')
51
- expect(wrapper.findAll('.dm-tabs__tab')[1].classes()).toContain('dm-tabs__tab--active')
52
- })
53
-
54
- it('emits update:modelValue on tab click', async () => {
55
- const wrapper = mount(DatametriaTabs, { props: { tabs } })
56
- await wrapper.findAll('.dm-tabs__tab')[2].trigger('click')
57
- expect(wrapper.emitted('update:modelValue')).toBeTruthy()
58
- expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([2])
59
- })
60
-
61
- it('emits change event on tab click', async () => {
62
- const wrapper = mount(DatametriaTabs, { props: { tabs } })
63
- await wrapper.findAll('.dm-tabs__tab')[1].trigger('click')
64
- expect(wrapper.emitted('change')).toBeTruthy()
65
- expect(wrapper.emitted('change')?.[0]).toEqual([1])
66
- })
67
-
68
- it('renders tab panels', () => {
69
- const wrapper = mount(DatametriaTabs, {
70
- props: { tabs },
71
- slots: {
72
- 'panel-0': '<div class="panel-0">Panel 1</div>',
73
- 'panel-1': '<div class="panel-1">Panel 2</div>',
74
- 'panel-2': '<div class="panel-2">Panel 3</div>'
75
- }
76
- })
77
- expect(wrapper.find('.panel-0').exists()).toBe(true)
78
- expect(wrapper.find('.panel-1').exists()).toBe(true)
79
- expect(wrapper.find('.panel-2').exists()).toBe(true)
80
- })
81
-
82
- it('shows only active panel', () => {
83
- const wrapper = mount(DatametriaTabs, {
84
- props: { tabs, modelValue: 1 },
85
- slots: {
86
- 'panel-0': '<div class="panel-0">Panel 1</div>',
87
- 'panel-1': '<div class="panel-1">Panel 2</div>',
88
- 'panel-2': '<div class="panel-2">Panel 3</div>'
89
- }
90
- })
91
- const panels = wrapper.findAll('.dm-tabs__panel')
92
- expect(panels[0].classes()).not.toContain('dm-tabs__panel--active')
93
- expect(panels[1].classes()).toContain('dm-tabs__panel--active')
94
- expect(panels[2].classes()).not.toContain('dm-tabs__panel--active')
95
- })
96
-
97
- it('handles keyboard navigation - ArrowRight', async () => {
98
- const wrapper = mount(DatametriaTabs, { props: { tabs } })
99
- const tabButtons = wrapper.findAll('.dm-tabs__tab')
100
-
101
- await tabButtons[0].trigger('keydown', { key: 'ArrowRight' })
102
- expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([1])
103
- })
104
-
105
- it('handles keyboard navigation - ArrowLeft', async () => {
106
- const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 1 } })
107
- const tabButtons = wrapper.findAll('.dm-tabs__tab')
108
-
109
- await tabButtons[1].trigger('keydown', { key: 'ArrowLeft' })
110
- expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([0])
111
- })
112
-
113
- it('handles keyboard navigation - Home', async () => {
114
- const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 2 } })
115
- const tabButtons = wrapper.findAll('.dm-tabs__tab')
116
-
117
- await tabButtons[2].trigger('keydown', { key: 'Home' })
118
- expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([0])
119
- })
120
-
121
- it('handles keyboard navigation - End', async () => {
122
- const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 0 } })
123
- const tabButtons = wrapper.findAll('.dm-tabs__tab')
124
-
125
- await tabButtons[0].trigger('keydown', { key: 'End' })
126
- expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([2])
127
- })
128
-
129
- it('wraps around with ArrowRight at last tab', async () => {
130
- const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 2 } })
131
- const tabButtons = wrapper.findAll('.dm-tabs__tab')
132
-
133
- await tabButtons[2].trigger('keydown', { key: 'ArrowRight' })
134
- expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([0])
135
- })
136
-
137
- it('wraps around with ArrowLeft at first tab', async () => {
138
- const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 0 } })
139
- const tabButtons = wrapper.findAll('.dm-tabs__tab')
140
-
141
- await tabButtons[0].trigger('keydown', { key: 'ArrowLeft' })
142
- expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([2])
143
- })
144
-
145
- it('renders tabs with icons', () => {
146
- const tabsWithIcons = [
147
- { label: 'Home', icon: '🏠' },
148
- { label: 'Settings', icon: '⚙️' }
149
- ]
150
- const wrapper = mount(DatametriaTabs, { props: { tabs: tabsWithIcons } })
151
- expect(wrapper.findAll('.dm-tabs__icon')).toHaveLength(2)
152
- expect(wrapper.findAll('.dm-tabs__icon')[0].text()).toBe('🏠')
153
- })
154
-
155
- it('renders tabs with badges', () => {
156
- const tabsWithBadges = [
157
- { label: 'Messages', badge: '5' },
158
- { label: 'Notifications', badge: 10 }
159
- ]
160
- const wrapper = mount(DatametriaTabs, { props: { tabs: tabsWithBadges } })
161
- expect(wrapper.findAll('.dm-tabs__badge')).toHaveLength(2)
162
- expect(wrapper.findAll('.dm-tabs__badge')[0].text()).toBe('5')
163
- expect(wrapper.findAll('.dm-tabs__badge')[1].text()).toBe('10')
164
- })
165
-
166
- it('handles disabled tabs', async () => {
167
- const tabsWithDisabled = [
168
- { label: 'Tab 1' },
169
- { label: 'Tab 2', disabled: true },
170
- { label: 'Tab 3' }
171
- ]
172
- const wrapper = mount(DatametriaTabs, { props: { tabs: tabsWithDisabled } })
173
-
174
- const disabledTab = wrapper.findAll('.dm-tabs__tab')[1]
175
- expect(disabledTab.classes()).toContain('dm-tabs__tab--disabled')
176
- expect(disabledTab.attributes('disabled')).toBeDefined()
177
-
178
- await disabledTab.trigger('click')
179
- expect(wrapper.emitted('update:modelValue')).toBeFalsy()
180
- })
181
-
182
- it('shows indicator by default', () => {
183
- const wrapper = mount(DatametriaTabs, { props: { tabs } })
184
- expect(wrapper.find('.dm-tabs__indicator').exists()).toBe(true)
185
- })
186
-
187
- it('hides indicator when showIndicator is false', () => {
188
- const wrapper = mount(DatametriaTabs, { props: { tabs, showIndicator: false } })
189
- expect(wrapper.find('.dm-tabs__indicator').exists()).toBe(false)
190
- })
191
-
192
- it('has correct aria attributes', () => {
193
- const wrapper = mount(DatametriaTabs, { props: { tabs, ariaLabel: 'Main tabs' } })
194
- const header = wrapper.find('.dm-tabs__header')
195
- expect(header.attributes('role')).toBe('tablist')
196
- expect(header.attributes('aria-label')).toBe('Main tabs')
197
- expect(header.attributes('aria-orientation')).toBe('horizontal')
198
- })
199
-
200
- it('updates aria-orientation for vertical tabs', () => {
201
- const wrapper = mount(DatametriaTabs, { props: { tabs, orientation: 'vertical' } })
202
- const header = wrapper.find('.dm-tabs__header')
203
- expect(header.attributes('aria-orientation')).toBe('vertical')
204
- })
205
-
206
- it('handles vertical keyboard navigation', async () => {
207
- const wrapper = mount(DatametriaTabs, { props: { tabs, orientation: 'vertical' } })
208
- const tabButtons = wrapper.findAll('.dm-tabs__tab')
209
-
210
- await tabButtons[0].trigger('keydown', { key: 'ArrowDown' })
211
- expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([1])
212
-
213
- await tabButtons[1].trigger('keydown', { key: 'ArrowUp' })
214
- expect(wrapper.emitted('update:modelValue')?.[1]).toEqual([0])
215
- })
216
-
217
- it('ignores horizontal keys in vertical mode', async () => {
218
- const wrapper = mount(DatametriaTabs, { props: { tabs, orientation: 'vertical' } })
219
- const tabButtons = wrapper.findAll('.dm-tabs__tab')
220
-
221
- await tabButtons[0].trigger('keydown', { key: 'ArrowRight' })
222
- expect(wrapper.emitted('update:modelValue')).toBeFalsy()
223
- })
224
-
225
- it('updates when modelValue prop changes', async () => {
226
- const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 0 } })
227
- expect(wrapper.findAll('.dm-tabs__tab')[0].classes()).toContain('dm-tabs__tab--active')
228
-
229
- await wrapper.setProps({ modelValue: 2 })
230
- expect(wrapper.findAll('.dm-tabs__tab')[2].classes()).toContain('dm-tabs__tab--active')
231
- })
232
- })
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import DatametriaTabs from '../DatametriaTabs.vue'
4
+
5
+ describe('DatametriaTabs', () => {
6
+ const tabs = ['Tab 1', 'Tab 2', 'Tab 3']
7
+
8
+ it('renders correctly', () => {
9
+ const wrapper = mount(DatametriaTabs, { props: { tabs } })
10
+ expect(wrapper.find('.dm-tabs').exists()).toBe(true)
11
+ })
12
+
13
+ it('renders all tabs', () => {
14
+ const wrapper = mount(DatametriaTabs, { props: { tabs } })
15
+ const tabButtons = wrapper.findAll('.dm-tabs__tab')
16
+ expect(tabButtons).toHaveLength(3)
17
+ expect(tabButtons[0].text()).toBe('Tab 1')
18
+ expect(tabButtons[1].text()).toBe('Tab 2')
19
+ expect(tabButtons[2].text()).toBe('Tab 3')
20
+ })
21
+
22
+ it('applies variant classes', () => {
23
+ const variants = ['default', 'pills', 'underline'] as const
24
+ variants.forEach(variant => {
25
+ const wrapper = mount(DatametriaTabs, { props: { tabs, variant } })
26
+ expect(wrapper.find(`.dm-tabs--${variant}`).exists()).toBe(true)
27
+ })
28
+ })
29
+
30
+ it('applies orientation classes', () => {
31
+ const horizontal = mount(DatametriaTabs, { props: { tabs, orientation: 'horizontal' } })
32
+ expect(horizontal.find('.dm-tabs--horizontal').exists()).toBe(true)
33
+
34
+ const vertical = mount(DatametriaTabs, { props: { tabs, orientation: 'vertical' } })
35
+ expect(vertical.find('.dm-tabs--vertical').exists()).toBe(true)
36
+ })
37
+
38
+ it('sets first tab as active by default', () => {
39
+ const wrapper = mount(DatametriaTabs, { props: { tabs } })
40
+ expect(wrapper.findAll('.dm-tabs__tab')[0].classes()).toContain('dm-tabs__tab--active')
41
+ })
42
+
43
+ it('respects modelValue prop', () => {
44
+ const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 1 } })
45
+ expect(wrapper.findAll('.dm-tabs__tab')[1].classes()).toContain('dm-tabs__tab--active')
46
+ })
47
+
48
+ it('changes active tab on click', async () => {
49
+ const wrapper = mount(DatametriaTabs, { props: { tabs } })
50
+ await wrapper.findAll('.dm-tabs__tab')[1].trigger('click')
51
+ expect(wrapper.findAll('.dm-tabs__tab')[1].classes()).toContain('dm-tabs__tab--active')
52
+ })
53
+
54
+ it('emits update:modelValue on tab click', async () => {
55
+ const wrapper = mount(DatametriaTabs, { props: { tabs } })
56
+ await wrapper.findAll('.dm-tabs__tab')[2].trigger('click')
57
+ expect(wrapper.emitted('update:modelValue')).toBeTruthy()
58
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([2])
59
+ })
60
+
61
+ it('emits change event on tab click', async () => {
62
+ const wrapper = mount(DatametriaTabs, { props: { tabs } })
63
+ await wrapper.findAll('.dm-tabs__tab')[1].trigger('click')
64
+ expect(wrapper.emitted('change')).toBeTruthy()
65
+ expect(wrapper.emitted('change')?.[0]).toEqual([1])
66
+ })
67
+
68
+ it('renders tab panels', () => {
69
+ const wrapper = mount(DatametriaTabs, {
70
+ props: { tabs },
71
+ slots: {
72
+ 'panel-0': '<div class="panel-0">Panel 1</div>',
73
+ 'panel-1': '<div class="panel-1">Panel 2</div>',
74
+ 'panel-2': '<div class="panel-2">Panel 3</div>'
75
+ }
76
+ })
77
+ expect(wrapper.find('.panel-0').exists()).toBe(true)
78
+ expect(wrapper.find('.panel-1').exists()).toBe(true)
79
+ expect(wrapper.find('.panel-2').exists()).toBe(true)
80
+ })
81
+
82
+ it('shows only active panel', () => {
83
+ const wrapper = mount(DatametriaTabs, {
84
+ props: { tabs, modelValue: 1 },
85
+ slots: {
86
+ 'panel-0': '<div class="panel-0">Panel 1</div>',
87
+ 'panel-1': '<div class="panel-1">Panel 2</div>',
88
+ 'panel-2': '<div class="panel-2">Panel 3</div>'
89
+ }
90
+ })
91
+ const panels = wrapper.findAll('.dm-tabs__panel')
92
+ expect(panels[0].classes()).not.toContain('dm-tabs__panel--active')
93
+ expect(panels[1].classes()).toContain('dm-tabs__panel--active')
94
+ expect(panels[2].classes()).not.toContain('dm-tabs__panel--active')
95
+ })
96
+
97
+ it('handles keyboard navigation - ArrowRight', async () => {
98
+ const wrapper = mount(DatametriaTabs, { props: { tabs } })
99
+ const tabButtons = wrapper.findAll('.dm-tabs__tab')
100
+
101
+ await tabButtons[0].trigger('keydown', { key: 'ArrowRight' })
102
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([1])
103
+ })
104
+
105
+ it('handles keyboard navigation - ArrowLeft', async () => {
106
+ const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 1 } })
107
+ const tabButtons = wrapper.findAll('.dm-tabs__tab')
108
+
109
+ await tabButtons[1].trigger('keydown', { key: 'ArrowLeft' })
110
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([0])
111
+ })
112
+
113
+ it('handles keyboard navigation - Home', async () => {
114
+ const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 2 } })
115
+ const tabButtons = wrapper.findAll('.dm-tabs__tab')
116
+
117
+ await tabButtons[2].trigger('keydown', { key: 'Home' })
118
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([0])
119
+ })
120
+
121
+ it('handles keyboard navigation - End', async () => {
122
+ const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 0 } })
123
+ const tabButtons = wrapper.findAll('.dm-tabs__tab')
124
+
125
+ await tabButtons[0].trigger('keydown', { key: 'End' })
126
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([2])
127
+ })
128
+
129
+ it('wraps around with ArrowRight at last tab', async () => {
130
+ const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 2 } })
131
+ const tabButtons = wrapper.findAll('.dm-tabs__tab')
132
+
133
+ await tabButtons[2].trigger('keydown', { key: 'ArrowRight' })
134
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([0])
135
+ })
136
+
137
+ it('wraps around with ArrowLeft at first tab', async () => {
138
+ const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 0 } })
139
+ const tabButtons = wrapper.findAll('.dm-tabs__tab')
140
+
141
+ await tabButtons[0].trigger('keydown', { key: 'ArrowLeft' })
142
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([2])
143
+ })
144
+
145
+ it('renders tabs with icons', () => {
146
+ const tabsWithIcons = [
147
+ { label: 'Home', icon: '🏠' },
148
+ { label: 'Settings', icon: '⚙️' }
149
+ ]
150
+ const wrapper = mount(DatametriaTabs, { props: { tabs: tabsWithIcons } })
151
+ expect(wrapper.findAll('.dm-tabs__icon')).toHaveLength(2)
152
+ expect(wrapper.findAll('.dm-tabs__icon')[0].text()).toBe('🏠')
153
+ })
154
+
155
+ it('renders tabs with badges', () => {
156
+ const tabsWithBadges = [
157
+ { label: 'Messages', badge: '5' },
158
+ { label: 'Notifications', badge: 10 }
159
+ ]
160
+ const wrapper = mount(DatametriaTabs, { props: { tabs: tabsWithBadges } })
161
+ expect(wrapper.findAll('.dm-tabs__badge')).toHaveLength(2)
162
+ expect(wrapper.findAll('.dm-tabs__badge')[0].text()).toBe('5')
163
+ expect(wrapper.findAll('.dm-tabs__badge')[1].text()).toBe('10')
164
+ })
165
+
166
+ it('handles disabled tabs', async () => {
167
+ const tabsWithDisabled = [
168
+ { label: 'Tab 1' },
169
+ { label: 'Tab 2', disabled: true },
170
+ { label: 'Tab 3' }
171
+ ]
172
+ const wrapper = mount(DatametriaTabs, { props: { tabs: tabsWithDisabled } })
173
+
174
+ const disabledTab = wrapper.findAll('.dm-tabs__tab')[1]
175
+ expect(disabledTab.classes()).toContain('dm-tabs__tab--disabled')
176
+ expect(disabledTab.attributes('disabled')).toBeDefined()
177
+
178
+ await disabledTab.trigger('click')
179
+ expect(wrapper.emitted('update:modelValue')).toBeFalsy()
180
+ })
181
+
182
+ it('shows indicator by default', () => {
183
+ const wrapper = mount(DatametriaTabs, { props: { tabs } })
184
+ expect(wrapper.find('.dm-tabs__indicator').exists()).toBe(true)
185
+ })
186
+
187
+ it('hides indicator when showIndicator is false', () => {
188
+ const wrapper = mount(DatametriaTabs, { props: { tabs, showIndicator: false } })
189
+ expect(wrapper.find('.dm-tabs__indicator').exists()).toBe(false)
190
+ })
191
+
192
+ it('has correct aria attributes', () => {
193
+ const wrapper = mount(DatametriaTabs, { props: { tabs, ariaLabel: 'Main tabs' } })
194
+ const header = wrapper.find('.dm-tabs__header')
195
+ expect(header.attributes('role')).toBe('tablist')
196
+ expect(header.attributes('aria-label')).toBe('Main tabs')
197
+ expect(header.attributes('aria-orientation')).toBe('horizontal')
198
+ })
199
+
200
+ it('updates aria-orientation for vertical tabs', () => {
201
+ const wrapper = mount(DatametriaTabs, { props: { tabs, orientation: 'vertical' } })
202
+ const header = wrapper.find('.dm-tabs__header')
203
+ expect(header.attributes('aria-orientation')).toBe('vertical')
204
+ })
205
+
206
+ it('handles vertical keyboard navigation', async () => {
207
+ const wrapper = mount(DatametriaTabs, { props: { tabs, orientation: 'vertical' } })
208
+ const tabButtons = wrapper.findAll('.dm-tabs__tab')
209
+
210
+ await tabButtons[0].trigger('keydown', { key: 'ArrowDown' })
211
+ expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([1])
212
+
213
+ await tabButtons[1].trigger('keydown', { key: 'ArrowUp' })
214
+ expect(wrapper.emitted('update:modelValue')?.[1]).toEqual([0])
215
+ })
216
+
217
+ it('ignores horizontal keys in vertical mode', async () => {
218
+ const wrapper = mount(DatametriaTabs, { props: { tabs, orientation: 'vertical' } })
219
+ const tabButtons = wrapper.findAll('.dm-tabs__tab')
220
+
221
+ await tabButtons[0].trigger('keydown', { key: 'ArrowRight' })
222
+ expect(wrapper.emitted('update:modelValue')).toBeFalsy()
223
+ })
224
+
225
+ it('updates when modelValue prop changes', async () => {
226
+ const wrapper = mount(DatametriaTabs, { props: { tabs, modelValue: 0 } })
227
+ expect(wrapper.findAll('.dm-tabs__tab')[0].classes()).toContain('dm-tabs__tab--active')
228
+
229
+ await wrapper.setProps({ modelValue: 2 })
230
+ expect(wrapper.findAll('.dm-tabs__tab')[2].classes()).toContain('dm-tabs__tab--active')
231
+ })
232
+ })