@datametria/vue-components 1.2.0 → 2.0.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/README.md +548 -657
- package/dist/index.es.js +2353 -1364
- package/dist/index.umd.js +10 -10
- package/dist/vue-components.css +1 -1
- package/package.json +102 -98
- package/src/components/DatametriaAlert.vue +137 -137
- package/src/components/DatametriaAutocomplete.vue +184 -138
- package/src/components/DatametriaAvatar.vue +177 -33
- package/src/components/DatametriaBadge.vue +98 -98
- package/src/components/DatametriaBreadcrumb.vue +21 -21
- package/src/components/DatametriaButton.vue +177 -165
- package/src/components/DatametriaCard.vue +12 -12
- package/src/components/DatametriaCheckbox.vue +8 -8
- package/src/components/DatametriaChip.vue +145 -149
- package/src/components/DatametriaContainer.vue +4 -4
- package/src/components/DatametriaDatePicker.vue +686 -68
- package/src/components/DatametriaDivider.vue +13 -13
- package/src/components/DatametriaFileUpload.vue +272 -140
- package/src/components/DatametriaGrid.vue +3 -3
- package/src/components/DatametriaInput.vue +15 -15
- package/src/components/DatametriaMenu.vue +604 -619
- package/src/components/DatametriaModal.vue +16 -16
- package/src/components/DatametriaNavbar.vue +230 -252
- package/src/components/DatametriaPasswordInput.vue +430 -0
- package/src/components/DatametriaProgress.vue +18 -18
- package/src/components/DatametriaRadio.vue +20 -20
- package/src/components/DatametriaSelect.vue +15 -15
- package/src/components/DatametriaSkeleton.vue +243 -239
- package/src/components/DatametriaSlider.vue +395 -407
- package/src/components/DatametriaSortableTable.vue +585 -0
- package/src/components/DatametriaSpinner.vue +7 -7
- package/src/components/DatametriaSwitch.vue +16 -16
- package/src/components/DatametriaTable.vue +14 -14
- package/src/components/DatametriaTextarea.vue +28 -28
- package/src/components/DatametriaTimePicker.vue +285 -285
- package/src/components/DatametriaToast.vue +176 -176
- package/src/components/DatametriaTooltip.vue +408 -408
- package/src/components/__tests__/DatametriaAlert.test.js +35 -35
- package/src/components/__tests__/DatametriaAlert.test.ts +190 -0
- package/src/components/__tests__/DatametriaAutocomplete.test.ts +180 -0
- package/src/components/__tests__/DatametriaAvatar.test.ts +152 -0
- package/src/components/__tests__/DatametriaBadge.test.js +29 -29
- package/src/components/__tests__/DatametriaBadge.test.ts +167 -0
- package/src/components/__tests__/DatametriaBreadcrumb.test.ts +75 -0
- package/src/components/__tests__/DatametriaButton.test.js +30 -30
- package/src/components/__tests__/DatametriaButton.test.ts +283 -0
- package/src/components/__tests__/DatametriaCard.test.ts +201 -0
- package/src/components/__tests__/DatametriaCheckbox.test.ts +47 -0
- package/src/components/__tests__/DatametriaChip.test.js +38 -38
- package/src/components/__tests__/DatametriaContainer.test.ts +52 -0
- package/src/components/__tests__/DatametriaDatePicker.test.ts +234 -0
- package/src/components/__tests__/DatametriaDivider.test.ts +54 -0
- package/src/components/__tests__/DatametriaFileUpload.test.ts +291 -0
- package/src/components/__tests__/DatametriaGrid.test.ts +31 -0
- package/src/components/__tests__/DatametriaInput.test.ts +72 -0
- package/src/components/__tests__/DatametriaMenu.test.ts +366 -0
- package/src/components/__tests__/DatametriaModal.test.ts +86 -0
- package/src/components/__tests__/DatametriaNavbar.test.js +48 -48
- package/src/components/__tests__/DatametriaNavbar.test.ts +203 -0
- package/src/components/__tests__/DatametriaPasswordInput.test.js +305 -0
- package/src/components/__tests__/DatametriaProgress.test.ts +90 -0
- package/src/components/__tests__/DatametriaRadio.test.ts +77 -0
- package/src/components/__tests__/DatametriaSelect.test.ts +77 -0
- package/src/components/__tests__/DatametriaSlider.test.ts +261 -0
- package/src/components/__tests__/DatametriaSortableTable.test.js +168 -0
- package/src/components/__tests__/DatametriaSpinner.test.ts +156 -0
- package/src/components/__tests__/DatametriaSwitch.test.ts +64 -0
- package/src/components/__tests__/DatametriaTable.test.ts +97 -0
- package/src/components/__tests__/DatametriaTextarea.test.ts +66 -0
- package/src/components/__tests__/DatametriaToast.test.js +48 -48
- package/src/components/__tests__/DatametriaToast.test.ts +99 -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/index.ts +68 -61
- package/src/stories/Variants.stories.js +95 -95
- package/src/styles/design-tokens.css +623 -623
- package/src/theme/ThemeProvider.vue +96 -0
- package/src/theme/__tests__/ThemeProvider.test.ts +208 -0
- package/src/theme/__tests__/constants.test.ts +31 -0
- package/src/theme/__tests__/presets.test.ts +166 -0
- package/src/theme/__tests__/tokens.test.ts +155 -0
- package/src/theme/__tests__/types.test.ts +153 -0
- package/src/theme/__tests__/useTheme.test.ts +146 -0
- package/src/theme/constants.ts +14 -0
- package/src/theme/index.ts +12 -0
- package/src/theme/presets/datametria.ts +94 -0
- package/src/theme/presets/default.ts +94 -0
- package/src/theme/presets/index.ts +8 -0
- package/src/theme/tokens/colors.ts +28 -0
- package/src/theme/tokens/index.ts +47 -0
- package/src/theme/tokens/spacing.ts +21 -0
- package/src/theme/tokens/typography.ts +35 -0
- package/src/theme/types.ts +111 -0
- package/src/theme/useTheme.ts +28 -0
- package/src/types/index.ts +19 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import DatametriaBadge from '../DatametriaBadge.vue'
|
|
4
|
+
|
|
5
|
+
describe('DatametriaBadge', () => {
|
|
6
|
+
// Rendering tests
|
|
7
|
+
it('renders with default props', () => {
|
|
8
|
+
const wrapper = mount(DatametriaBadge)
|
|
9
|
+
expect(wrapper.find('.dm-badge').exists()).toBe(true)
|
|
10
|
+
expect(wrapper.find('.dm-badge--primary').exists()).toBe(true)
|
|
11
|
+
expect(wrapper.find('.dm-badge--md').exists()).toBe(true)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('renders with label prop', () => {
|
|
15
|
+
const wrapper = mount(DatametriaBadge, {
|
|
16
|
+
props: { label: 'Test Badge' }
|
|
17
|
+
})
|
|
18
|
+
expect(wrapper.text()).toBe('Test Badge')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('renders slot content', () => {
|
|
22
|
+
const wrapper = mount(DatametriaBadge, {
|
|
23
|
+
slots: {
|
|
24
|
+
default: '<strong>Custom Badge</strong>'
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
expect(wrapper.html()).toContain('<strong>Custom Badge</strong>')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('renders with aria-label', () => {
|
|
31
|
+
const wrapper = mount(DatametriaBadge, {
|
|
32
|
+
props: { ariaLabel: 'Status badge' }
|
|
33
|
+
})
|
|
34
|
+
expect(wrapper.attributes('aria-label')).toBe('Status badge')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// Variant tests
|
|
38
|
+
it('renders primary variant', () => {
|
|
39
|
+
const wrapper = mount(DatametriaBadge, {
|
|
40
|
+
props: { variant: 'primary' }
|
|
41
|
+
})
|
|
42
|
+
expect(wrapper.find('.dm-badge--primary').exists()).toBe(true)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('renders secondary variant', () => {
|
|
46
|
+
const wrapper = mount(DatametriaBadge, {
|
|
47
|
+
props: { variant: 'secondary' }
|
|
48
|
+
})
|
|
49
|
+
expect(wrapper.find('.dm-badge--secondary').exists()).toBe(true)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('renders success variant', () => {
|
|
53
|
+
const wrapper = mount(DatametriaBadge, {
|
|
54
|
+
props: { variant: 'success' }
|
|
55
|
+
})
|
|
56
|
+
expect(wrapper.find('.dm-badge--success').exists()).toBe(true)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('renders warning variant', () => {
|
|
60
|
+
const wrapper = mount(DatametriaBadge, {
|
|
61
|
+
props: { variant: 'warning' }
|
|
62
|
+
})
|
|
63
|
+
expect(wrapper.find('.dm-badge--warning').exists()).toBe(true)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('renders error variant', () => {
|
|
67
|
+
const wrapper = mount(DatametriaBadge, {
|
|
68
|
+
props: { variant: 'error' }
|
|
69
|
+
})
|
|
70
|
+
expect(wrapper.find('.dm-badge--error').exists()).toBe(true)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('renders info variant', () => {
|
|
74
|
+
const wrapper = mount(DatametriaBadge, {
|
|
75
|
+
props: { variant: 'info' }
|
|
76
|
+
})
|
|
77
|
+
expect(wrapper.find('.dm-badge--info').exists()).toBe(true)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
// Size tests
|
|
81
|
+
it('renders small size', () => {
|
|
82
|
+
const wrapper = mount(DatametriaBadge, {
|
|
83
|
+
props: { size: 'sm' }
|
|
84
|
+
})
|
|
85
|
+
expect(wrapper.find('.dm-badge--sm').exists()).toBe(true)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('renders medium size', () => {
|
|
89
|
+
const wrapper = mount(DatametriaBadge, {
|
|
90
|
+
props: { size: 'md' }
|
|
91
|
+
})
|
|
92
|
+
expect(wrapper.find('.dm-badge--md').exists()).toBe(true)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('renders large size', () => {
|
|
96
|
+
const wrapper = mount(DatametriaBadge, {
|
|
97
|
+
props: { size: 'lg' }
|
|
98
|
+
})
|
|
99
|
+
expect(wrapper.find('.dm-badge--lg').exists()).toBe(true)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// CSS Variables tests
|
|
103
|
+
it('uses CSS variables for colors', () => {
|
|
104
|
+
const variants: Array<'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info'> = [
|
|
105
|
+
'primary', 'secondary', 'success', 'warning', 'error', 'info'
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
variants.forEach(variant => {
|
|
109
|
+
const wrapper = mount(DatametriaBadge, {
|
|
110
|
+
props: { variant }
|
|
111
|
+
})
|
|
112
|
+
expect(wrapper.find(`.dm-badge--${variant}`).exists()).toBe(true)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('uses CSS variables for typography', () => {
|
|
117
|
+
const wrapper = mount(DatametriaBadge, {
|
|
118
|
+
props: { label: 'Test' }
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// Verifica estrutura
|
|
122
|
+
expect(wrapper.find('.dm-badge').exists()).toBe(true)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('uses CSS variables for spacing', () => {
|
|
126
|
+
const sizes: Array<'sm' | 'md' | 'lg'> = ['sm', 'md', 'lg']
|
|
127
|
+
|
|
128
|
+
sizes.forEach(size => {
|
|
129
|
+
const wrapper = mount(DatametriaBadge, {
|
|
130
|
+
props: { size }
|
|
131
|
+
})
|
|
132
|
+
expect(wrapper.find(`.dm-badge--${size}`).exists()).toBe(true)
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
// Backward compatibility tests
|
|
137
|
+
it('works without ThemeProvider (fallback values)', () => {
|
|
138
|
+
const wrapper = mount(DatametriaBadge, {
|
|
139
|
+
props: {
|
|
140
|
+
variant: 'success',
|
|
141
|
+
size: 'md',
|
|
142
|
+
label: 'Success'
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
expect(wrapper.find('.dm-badge--success').exists()).toBe(true)
|
|
147
|
+
expect(wrapper.find('.dm-badge--md').exists()).toBe(true)
|
|
148
|
+
expect(wrapper.text()).toBe('Success')
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('maintains visual consistency across variants and sizes', () => {
|
|
152
|
+
const variants: Array<'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info'> = [
|
|
153
|
+
'primary', 'secondary', 'success', 'warning', 'error', 'info'
|
|
154
|
+
]
|
|
155
|
+
const sizes: Array<'sm' | 'md' | 'lg'> = ['sm', 'md', 'lg']
|
|
156
|
+
|
|
157
|
+
variants.forEach(variant => {
|
|
158
|
+
sizes.forEach(size => {
|
|
159
|
+
const wrapper = mount(DatametriaBadge, {
|
|
160
|
+
props: { variant, size, label: 'Test' }
|
|
161
|
+
})
|
|
162
|
+
expect(wrapper.find(`.dm-badge--${variant}`).exists()).toBe(true)
|
|
163
|
+
expect(wrapper.find(`.dm-badge--${size}`).exists()).toBe(true)
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
})
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import DatametriaBreadcrumb from '../DatametriaBreadcrumb.vue'
|
|
4
|
+
|
|
5
|
+
describe('DatametriaBreadcrumb', () => {
|
|
6
|
+
const items = [
|
|
7
|
+
{ label: 'Home', href: '/' },
|
|
8
|
+
{ label: 'Products', href: '/products' },
|
|
9
|
+
{ label: 'Details' }
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
it('renders correctly', () => {
|
|
13
|
+
const wrapper = mount(DatametriaBreadcrumb, {
|
|
14
|
+
props: { items }
|
|
15
|
+
})
|
|
16
|
+
expect(wrapper.find('.dm-breadcrumb').exists()).toBe(true)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('renders all items', () => {
|
|
20
|
+
const wrapper = mount(DatametriaBreadcrumb, {
|
|
21
|
+
props: { items }
|
|
22
|
+
})
|
|
23
|
+
const itemElements = wrapper.findAll('.dm-breadcrumb__item')
|
|
24
|
+
expect(itemElements).toHaveLength(3)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('renders links for items with href', () => {
|
|
28
|
+
const wrapper = mount(DatametriaBreadcrumb, {
|
|
29
|
+
props: { items }
|
|
30
|
+
})
|
|
31
|
+
const links = wrapper.findAll('.dm-breadcrumb__link')
|
|
32
|
+
expect(links).toHaveLength(2)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('renders current item without link', () => {
|
|
36
|
+
const wrapper = mount(DatametriaBreadcrumb, {
|
|
37
|
+
props: { items }
|
|
38
|
+
})
|
|
39
|
+
const current = wrapper.find('.dm-breadcrumb__current')
|
|
40
|
+
expect(current.exists()).toBe(true)
|
|
41
|
+
expect(current.text()).toBe('Details')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('renders separators', () => {
|
|
45
|
+
const wrapper = mount(DatametriaBreadcrumb, {
|
|
46
|
+
props: { items }
|
|
47
|
+
})
|
|
48
|
+
const separators = wrapper.findAll('.dm-breadcrumb__separator')
|
|
49
|
+
expect(separators).toHaveLength(2)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('uses custom separator', () => {
|
|
53
|
+
const wrapper = mount(DatametriaBreadcrumb, {
|
|
54
|
+
props: { items, separator: '>' }
|
|
55
|
+
})
|
|
56
|
+
const separator = wrapper.find('.dm-breadcrumb__separator')
|
|
57
|
+
expect(separator.text()).toBe('>')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('emits click event', async () => {
|
|
61
|
+
const wrapper = mount(DatametriaBreadcrumb, {
|
|
62
|
+
props: { items }
|
|
63
|
+
})
|
|
64
|
+
await wrapper.find('.dm-breadcrumb__link').trigger('click')
|
|
65
|
+
expect(wrapper.emitted('click')).toBeTruthy()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('applies aria-current to last item', () => {
|
|
69
|
+
const wrapper = mount(DatametriaBreadcrumb, {
|
|
70
|
+
props: { items }
|
|
71
|
+
})
|
|
72
|
+
const current = wrapper.find('.dm-breadcrumb__current')
|
|
73
|
+
expect(current.attributes('aria-current')).toBe('page')
|
|
74
|
+
})
|
|
75
|
+
})
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
-
import { mount } from '@vue/test-utils'
|
|
3
|
-
import DatametriaButton from '../DatametriaButton.vue'
|
|
4
|
-
import { ButtonVariant } from '../../types'
|
|
5
|
-
|
|
6
|
-
describe('DatametriaButton', () => {
|
|
7
|
-
it('validates invalid variant in development', () => {
|
|
8
|
-
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
9
|
-
const originalEnv = process.env.NODE_ENV
|
|
10
|
-
process.env.NODE_ENV = 'development'
|
|
11
|
-
|
|
12
|
-
mount(DatametriaButton, {
|
|
13
|
-
props: { variant: 'invalid' }
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
17
|
-
expect.stringContaining('[DatametriaButton] Invalid variant "invalid"')
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
process.env.NODE_ENV = originalEnv
|
|
21
|
-
consoleSpy.mockRestore()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('renders with primary variant', () => {
|
|
25
|
-
const wrapper = mount(DatametriaButton, {
|
|
26
|
-
props: { variant: ButtonVariant.PRIMARY }
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
expect(wrapper.classes()).toContain('datametria-button--primary')
|
|
30
|
-
})
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import DatametriaButton from '../DatametriaButton.vue'
|
|
4
|
+
import { ButtonVariant } from '../../types'
|
|
5
|
+
|
|
6
|
+
describe('DatametriaButton', () => {
|
|
7
|
+
it('validates invalid variant in development', () => {
|
|
8
|
+
const consoleSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
9
|
+
const originalEnv = process.env.NODE_ENV
|
|
10
|
+
process.env.NODE_ENV = 'development'
|
|
11
|
+
|
|
12
|
+
mount(DatametriaButton, {
|
|
13
|
+
props: { variant: 'invalid' }
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
17
|
+
expect.stringContaining('[DatametriaButton] Invalid variant "invalid"')
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
process.env.NODE_ENV = originalEnv
|
|
21
|
+
consoleSpy.mockRestore()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('renders with primary variant', () => {
|
|
25
|
+
const wrapper = mount(DatametriaButton, {
|
|
26
|
+
props: { variant: ButtonVariant.PRIMARY }
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
expect(wrapper.classes()).toContain('datametria-button--primary')
|
|
30
|
+
})
|
|
31
31
|
})
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DatametriaButton Tests
|
|
3
|
+
* @author Vander Loto - CTO DATAMETRIA
|
|
4
|
+
* @date 13/11/2025
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect } from 'vitest'
|
|
8
|
+
import { mount } from '@vue/test-utils'
|
|
9
|
+
import DatametriaButton from '../DatametriaButton.vue'
|
|
10
|
+
import { ButtonVariant, ButtonSize } from '../../types'
|
|
11
|
+
|
|
12
|
+
describe('DatametriaButton', () => {
|
|
13
|
+
describe('Rendering', () => {
|
|
14
|
+
it('should render button with text', () => {
|
|
15
|
+
const wrapper = mount(DatametriaButton, {
|
|
16
|
+
slots: { default: 'Click me' }
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
expect(wrapper.text()).toContain('Click me')
|
|
20
|
+
expect(wrapper.find('button').exists()).toBe(true)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('should render with default variant and size', () => {
|
|
24
|
+
const wrapper = mount(DatametriaButton, {
|
|
25
|
+
slots: { default: 'Button' }
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
expect(wrapper.classes()).toContain('datametria-button--primary')
|
|
29
|
+
expect(wrapper.classes()).toContain('datametria-button--md')
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('Variants', () => {
|
|
34
|
+
it('should render primary variant', () => {
|
|
35
|
+
const wrapper = mount(DatametriaButton, {
|
|
36
|
+
props: { variant: ButtonVariant.PRIMARY },
|
|
37
|
+
slots: { default: 'Primary' }
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
expect(wrapper.classes()).toContain('datametria-button--primary')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('should render secondary variant', () => {
|
|
44
|
+
const wrapper = mount(DatametriaButton, {
|
|
45
|
+
props: { variant: ButtonVariant.SECONDARY },
|
|
46
|
+
slots: { default: 'Secondary' }
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
expect(wrapper.classes()).toContain('datametria-button--secondary')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should render outline variant', () => {
|
|
53
|
+
const wrapper = mount(DatametriaButton, {
|
|
54
|
+
props: { variant: ButtonVariant.OUTLINE },
|
|
55
|
+
slots: { default: 'Outline' }
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
expect(wrapper.classes()).toContain('datametria-button--outline')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should render ghost variant', () => {
|
|
62
|
+
const wrapper = mount(DatametriaButton, {
|
|
63
|
+
props: { variant: ButtonVariant.GHOST },
|
|
64
|
+
slots: { default: 'Ghost' }
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
expect(wrapper.classes()).toContain('datametria-button--ghost')
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('Sizes', () => {
|
|
72
|
+
it('should render small size', () => {
|
|
73
|
+
const wrapper = mount(DatametriaButton, {
|
|
74
|
+
props: { size: ButtonSize.SM },
|
|
75
|
+
slots: { default: 'Small' }
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
expect(wrapper.classes()).toContain('datametria-button--sm')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('should render medium size', () => {
|
|
82
|
+
const wrapper = mount(DatametriaButton, {
|
|
83
|
+
props: { size: ButtonSize.MD },
|
|
84
|
+
slots: { default: 'Medium' }
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
expect(wrapper.classes()).toContain('datametria-button--md')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('should render large size', () => {
|
|
91
|
+
const wrapper = mount(DatametriaButton, {
|
|
92
|
+
props: { size: ButtonSize.LG },
|
|
93
|
+
slots: { default: 'Large' }
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
expect(wrapper.classes()).toContain('datametria-button--lg')
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
describe('States', () => {
|
|
101
|
+
it('should be disabled when disabled prop is true', () => {
|
|
102
|
+
const wrapper = mount(DatametriaButton, {
|
|
103
|
+
props: { disabled: true },
|
|
104
|
+
slots: { default: 'Disabled' }
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
expect(wrapper.attributes('disabled')).toBeDefined()
|
|
108
|
+
expect(wrapper.classes()).toContain('datametria-button--disabled')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('should show loading spinner', () => {
|
|
112
|
+
const wrapper = mount(DatametriaButton, {
|
|
113
|
+
props: { loading: true },
|
|
114
|
+
slots: { default: 'Loading' }
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
expect(wrapper.find('.spinner').exists()).toBe(true)
|
|
118
|
+
expect(wrapper.attributes('aria-busy')).toBe('true')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('should be disabled when loading', () => {
|
|
122
|
+
const wrapper = mount(DatametriaButton, {
|
|
123
|
+
props: { loading: true },
|
|
124
|
+
slots: { default: 'Loading' }
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
expect(wrapper.attributes('disabled')).toBeDefined()
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('should render full width', () => {
|
|
131
|
+
const wrapper = mount(DatametriaButton, {
|
|
132
|
+
props: { fullWidth: true },
|
|
133
|
+
slots: { default: 'Full Width' }
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
expect(wrapper.classes()).toContain('datametria-button--full-width')
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
describe('Button Types', () => {
|
|
141
|
+
it('should render as button type by default', () => {
|
|
142
|
+
const wrapper = mount(DatametriaButton, {
|
|
143
|
+
slots: { default: 'Button' }
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
expect(wrapper.attributes('type')).toBe('button')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('should render as submit type', () => {
|
|
150
|
+
const wrapper = mount(DatametriaButton, {
|
|
151
|
+
props: { type: 'submit' },
|
|
152
|
+
slots: { default: 'Submit' }
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
expect(wrapper.attributes('type')).toBe('submit')
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('should render as reset type', () => {
|
|
159
|
+
const wrapper = mount(DatametriaButton, {
|
|
160
|
+
props: { type: 'reset' },
|
|
161
|
+
slots: { default: 'Reset' }
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
expect(wrapper.attributes('type')).toBe('reset')
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
describe('Events', () => {
|
|
169
|
+
it('should emit click event', async () => {
|
|
170
|
+
const wrapper = mount(DatametriaButton, {
|
|
171
|
+
slots: { default: 'Click' }
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
await wrapper.trigger('click')
|
|
175
|
+
|
|
176
|
+
expect(wrapper.emitted('click')).toBeTruthy()
|
|
177
|
+
expect(wrapper.emitted('click')?.[0]).toBeDefined()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('should not emit click when disabled', async () => {
|
|
181
|
+
const wrapper = mount(DatametriaButton, {
|
|
182
|
+
props: { disabled: true },
|
|
183
|
+
slots: { default: 'Disabled' }
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
await wrapper.trigger('click')
|
|
187
|
+
|
|
188
|
+
expect(wrapper.emitted('click')).toBeFalsy()
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('should not emit click when loading', async () => {
|
|
192
|
+
const wrapper = mount(DatametriaButton, {
|
|
193
|
+
props: { loading: true },
|
|
194
|
+
slots: { default: 'Loading' }
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
await wrapper.trigger('click')
|
|
198
|
+
|
|
199
|
+
expect(wrapper.emitted('click')).toBeFalsy()
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
describe('Accessibility', () => {
|
|
204
|
+
it('should have aria-disabled when disabled', () => {
|
|
205
|
+
const wrapper = mount(DatametriaButton, {
|
|
206
|
+
props: { disabled: true },
|
|
207
|
+
slots: { default: 'Disabled' }
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
expect(wrapper.attributes('aria-disabled')).toBe('true')
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
it('should have aria-busy when loading', () => {
|
|
214
|
+
const wrapper = mount(DatametriaButton, {
|
|
215
|
+
props: { loading: true },
|
|
216
|
+
slots: { default: 'Loading' }
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
expect(wrapper.attributes('aria-busy')).toBe('true')
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('should have spinner with role and label', () => {
|
|
223
|
+
const wrapper = mount(DatametriaButton, {
|
|
224
|
+
props: { loading: true },
|
|
225
|
+
slots: { default: 'Loading' }
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
const spinner = wrapper.find('.spinner')
|
|
229
|
+
expect(spinner.attributes('role')).toBe('status')
|
|
230
|
+
expect(spinner.attributes('aria-label')).toBe('Carregando')
|
|
231
|
+
})
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
describe('CSS Variables Integration', () => {
|
|
235
|
+
it('should use CSS variables for styling', () => {
|
|
236
|
+
const wrapper = mount(DatametriaButton, {
|
|
237
|
+
slots: { default: 'Button' }
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
const button = wrapper.find('button')
|
|
241
|
+
const style = getComputedStyle(button.element)
|
|
242
|
+
|
|
243
|
+
// Verifica que o componente está pronto para usar CSS variables
|
|
244
|
+
expect(button.classes()).toContain('datametria-button')
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
it('should apply variant classes for theming', () => {
|
|
248
|
+
const wrapper = mount(DatametriaButton, {
|
|
249
|
+
props: { variant: ButtonVariant.PRIMARY },
|
|
250
|
+
slots: { default: 'Primary' }
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
expect(wrapper.classes()).toContain('datametria-button--primary')
|
|
254
|
+
})
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
describe('Backward Compatibility', () => {
|
|
258
|
+
it('should maintain existing API', () => {
|
|
259
|
+
const wrapper = mount(DatametriaButton, {
|
|
260
|
+
props: {
|
|
261
|
+
variant: ButtonVariant.PRIMARY,
|
|
262
|
+
size: ButtonSize.MD,
|
|
263
|
+
disabled: false,
|
|
264
|
+
loading: false,
|
|
265
|
+
fullWidth: false,
|
|
266
|
+
type: 'button'
|
|
267
|
+
},
|
|
268
|
+
slots: { default: 'Button' }
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
expect(wrapper.exists()).toBe(true)
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('should work without ThemeProvider (fallback values)', () => {
|
|
275
|
+
const wrapper = mount(DatametriaButton, {
|
|
276
|
+
slots: { default: 'Button' }
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
expect(wrapper.find('button').exists()).toBe(true)
|
|
280
|
+
expect(wrapper.classes()).toContain('datametria-button--primary')
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
})
|