@datametria/vue-components 2.0.1 → 2.1.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.
@@ -0,0 +1,169 @@
1
+ import { describe, it, expect, vi } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import DatametriaSidebar from '../DatametriaSidebar.vue'
4
+
5
+ describe('DatametriaSidebar', () => {
6
+ it('renders correctly', () => {
7
+ const wrapper = mount(DatametriaSidebar)
8
+ expect(wrapper.find('.dm-sidebar').exists()).toBe(true)
9
+ })
10
+
11
+ it('applies position classes', () => {
12
+ const wrapperLeft = mount(DatametriaSidebar, { props: { position: 'left' } })
13
+ expect(wrapperLeft.find('.dm-sidebar--left').exists()).toBe(true)
14
+
15
+ const wrapperRight = mount(DatametriaSidebar, { props: { position: 'right' } })
16
+ expect(wrapperRight.find('.dm-sidebar--right').exists()).toBe(true)
17
+ })
18
+
19
+ it('applies variant classes', () => {
20
+ const variants = ['light', 'dark', 'primary'] as const
21
+ variants.forEach(variant => {
22
+ const wrapper = mount(DatametriaSidebar, { props: { variant } })
23
+ expect(wrapper.find(`.dm-sidebar--${variant}`).exists()).toBe(true)
24
+ })
25
+ })
26
+
27
+ it('renders header slot', () => {
28
+ const wrapper = mount(DatametriaSidebar, {
29
+ slots: { header: '<div class="test-header">Header</div>' }
30
+ })
31
+ expect(wrapper.find('.test-header').exists()).toBe(true)
32
+ expect(wrapper.find('.dm-sidebar__header').exists()).toBe(true)
33
+ })
34
+
35
+ it('renders default slot content', () => {
36
+ const wrapper = mount(DatametriaSidebar, {
37
+ slots: { default: '<div class="test-content">Content</div>' }
38
+ })
39
+ expect(wrapper.find('.test-content').exists()).toBe(true)
40
+ expect(wrapper.find('.dm-sidebar__content').exists()).toBe(true)
41
+ })
42
+
43
+ it('renders footer slot', () => {
44
+ const wrapper = mount(DatametriaSidebar, {
45
+ slots: { footer: '<div class="test-footer">Footer</div>' }
46
+ })
47
+ expect(wrapper.find('.test-footer').exists()).toBe(true)
48
+ expect(wrapper.find('.dm-sidebar__footer').exists()).toBe(true)
49
+ })
50
+
51
+ it('shows toggle button when collapsible', () => {
52
+ const wrapper = mount(DatametriaSidebar, {
53
+ props: { collapsible: true },
54
+ slots: { header: 'Header' }
55
+ })
56
+ expect(wrapper.find('.dm-sidebar__toggle').exists()).toBe(true)
57
+ })
58
+
59
+ it('hides toggle button when not collapsible', () => {
60
+ const wrapper = mount(DatametriaSidebar, {
61
+ props: { collapsible: false },
62
+ slots: { header: 'Header' }
63
+ })
64
+ expect(wrapper.find('.dm-sidebar__toggle').exists()).toBe(false)
65
+ })
66
+
67
+ it('toggles open state when toggle button clicked', async () => {
68
+ const wrapper = mount(DatametriaSidebar, {
69
+ props: { collapsible: true, defaultOpen: true },
70
+ slots: { header: 'Header' }
71
+ })
72
+
73
+ expect(wrapper.vm.isOpen).toBe(true)
74
+ expect(wrapper.find('.dm-sidebar--collapsed').exists()).toBe(false)
75
+
76
+ await wrapper.find('.dm-sidebar__toggle').trigger('click')
77
+ expect(wrapper.vm.isOpen).toBe(false)
78
+ expect(wrapper.find('.dm-sidebar--collapsed').exists()).toBe(true)
79
+
80
+ await wrapper.find('.dm-sidebar__toggle').trigger('click')
81
+ expect(wrapper.vm.isOpen).toBe(true)
82
+ })
83
+
84
+ it('emits toggle event with correct value', async () => {
85
+ const wrapper = mount(DatametriaSidebar, {
86
+ props: { collapsible: true, defaultOpen: true },
87
+ slots: { header: 'Header' }
88
+ })
89
+
90
+ await wrapper.find('.dm-sidebar__toggle').trigger('click')
91
+ expect(wrapper.emitted('toggle')).toBeTruthy()
92
+ expect(wrapper.emitted('toggle')?.[0]).toEqual([false])
93
+
94
+ await wrapper.find('.dm-sidebar__toggle').trigger('click')
95
+ expect(wrapper.emitted('toggle')?.[1]).toEqual([true])
96
+ })
97
+
98
+ it('emits open event when opening', async () => {
99
+ const wrapper = mount(DatametriaSidebar, {
100
+ props: { collapsible: true, defaultOpen: false },
101
+ slots: { header: 'Header' }
102
+ })
103
+
104
+ await wrapper.find('.dm-sidebar__toggle').trigger('click')
105
+ expect(wrapper.emitted('open')).toBeTruthy()
106
+ })
107
+
108
+ it('emits close event when closing', async () => {
109
+ const wrapper = mount(DatametriaSidebar, {
110
+ props: { collapsible: true, defaultOpen: true },
111
+ slots: { header: 'Header' }
112
+ })
113
+
114
+ await wrapper.find('.dm-sidebar__toggle').trigger('click')
115
+ expect(wrapper.emitted('close')).toBeTruthy()
116
+ })
117
+
118
+ it('respects defaultOpen prop', () => {
119
+ const wrapperOpen = mount(DatametriaSidebar, { props: { defaultOpen: true } })
120
+ expect(wrapperOpen.vm.isOpen).toBe(true)
121
+
122
+ const wrapperClosed = mount(DatametriaSidebar, { props: { defaultOpen: false } })
123
+ expect(wrapperClosed.vm.isOpen).toBe(false)
124
+ })
125
+
126
+ it('updates isOpen when defaultOpen prop changes', async () => {
127
+ const wrapper = mount(DatametriaSidebar, { props: { defaultOpen: true } })
128
+ expect(wrapper.vm.isOpen).toBe(true)
129
+
130
+ await wrapper.setProps({ defaultOpen: false })
131
+ expect(wrapper.vm.isOpen).toBe(false)
132
+ })
133
+
134
+ it('has correct aria attributes', () => {
135
+ const wrapper = mount(DatametriaSidebar, {
136
+ props: { ariaLabel: 'Test sidebar', defaultOpen: true }
137
+ })
138
+ const sidebar = wrapper.find('.dm-sidebar')
139
+ expect(sidebar.attributes('role')).toBe('complementary')
140
+ expect(sidebar.attributes('aria-label')).toBe('Test sidebar')
141
+ expect(sidebar.attributes('aria-expanded')).toBe('true')
142
+ })
143
+
144
+ it('exposes toggle method', () => {
145
+ const wrapper = mount(DatametriaSidebar, {
146
+ props: { collapsible: true, defaultOpen: true }
147
+ })
148
+
149
+ expect(wrapper.vm.isOpen).toBe(true)
150
+ wrapper.vm.toggle()
151
+ expect(wrapper.vm.isOpen).toBe(false)
152
+ wrapper.vm.toggle()
153
+ expect(wrapper.vm.isOpen).toBe(true)
154
+ })
155
+
156
+ it('applies collapsed class when closed and collapsible', () => {
157
+ const wrapper = mount(DatametriaSidebar, {
158
+ props: { collapsible: true, defaultOpen: false }
159
+ })
160
+ expect(wrapper.find('.dm-sidebar--collapsed').exists()).toBe(true)
161
+ })
162
+
163
+ it('does not apply collapsed class when open', () => {
164
+ const wrapper = mount(DatametriaSidebar, {
165
+ props: { collapsible: true, defaultOpen: true }
166
+ })
167
+ expect(wrapper.find('.dm-sidebar--collapsed').exists()).toBe(false)
168
+ })
169
+ })
@@ -0,0 +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
+ })
package/src/index.ts CHANGED
@@ -37,6 +37,8 @@ export { default as DatametriaChip } from './components/DatametriaChip.vue'
37
37
 
38
38
  // Components - Navigation
39
39
  export { default as DatametriaNavbar } from './components/DatametriaNavbar.vue'
40
+ export { default as DatametriaSidebar } from './components/DatametriaSidebar.vue'
41
+ export { default as DatametriaFloatingBar } from './components/DatametriaFloatingBar.vue'
40
42
  export { default as DatametriaMenu } from './components/DatametriaMenu.vue'
41
43
  export { default as DatametriaBreadcrumb } from './components/DatametriaBreadcrumb.vue'
42
44
  export { default as DatametriaTabs } from './components/DatametriaTabs.vue'