@zap-wunschlachen/wl-shared-components 1.0.76 → 1.0.78

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 (227) hide show
  1. package/.github/workflows/playwright.yml +229 -229
  2. package/.github/workflows/static.yml +61 -61
  3. package/.github/workflows/update-snapshots.yml +37 -37
  4. package/.prettierrc.json +8 -8
  5. package/.storybook/main.ts +18 -18
  6. package/.storybook/preview.ts +37 -37
  7. package/.storybook/storyWrapper.vue +18 -18
  8. package/.storybook/withVuetifyTheme.decorator.ts +21 -21
  9. package/App.vue +139 -139
  10. package/README.md +56 -56
  11. package/docs/assets.md +62 -62
  12. package/heroicons.ts +75 -75
  13. package/index.html +19 -19
  14. package/package.json +71 -71
  15. package/playwright.config.ts +48 -48
  16. package/public/background.svg +60 -60
  17. package/public/style.css +187 -187
  18. package/public/technologies.svg +22 -22
  19. package/scripts/check-translations.ts +352 -352
  20. package/src/assets/css/base.css +242 -242
  21. package/src/assets/css/variables.css +176 -176
  22. package/src/components/Accordion/Accordion.css +65 -65
  23. package/src/components/Accordion/AccordionGroup.vue +88 -88
  24. package/src/components/Accordion/AccordionItem.vue +272 -272
  25. package/src/components/Accordion/presets/default.css +4 -4
  26. package/src/components/Accordion/presets/elevated.css +25 -25
  27. package/src/components/Accordion/presets/filled.css +26 -26
  28. package/src/components/Accordion/presets/index.css +5 -5
  29. package/src/components/Accordion/presets/plain.css +34 -34
  30. package/src/components/Appointment/Card/Actions.css +54 -54
  31. package/src/components/Appointment/Card/Actions.vue +99 -99
  32. package/src/components/Appointment/Card/AnamneseNotification.css +20 -20
  33. package/src/components/Appointment/Card/AnamneseNotification.vue +23 -23
  34. package/src/components/Appointment/Card/Card.css +99 -99
  35. package/src/components/Appointment/Card/Card.vue +97 -97
  36. package/src/components/Appointment/Card/Details.css +62 -62
  37. package/src/components/Appointment/Card/Details.vue +44 -44
  38. package/src/components/Audio/Audio.vue +187 -187
  39. package/src/components/Audio/Waveform.vue +118 -118
  40. package/src/components/Banner/Banner.css +29 -29
  41. package/src/components/Banner/Banner.vue +89 -89
  42. package/src/components/Button/Button.vue +257 -257
  43. package/src/components/CheckBox/CheckBox.css +234 -234
  44. package/src/components/CheckBox/Checkbox.vue +184 -184
  45. package/src/components/DateInput/DateInput.css +2 -2
  46. package/src/components/DateInput/DateInput.vue +376 -370
  47. package/src/components/Dialog/Dialog.css +6 -6
  48. package/src/components/Dialog/Dialog.vue +46 -46
  49. package/src/components/EditField/EditField.css +19 -19
  50. package/src/components/EditField/EditField.vue +211 -211
  51. package/src/components/ErrorPage/ErrorPage.css +172 -172
  52. package/src/components/IconBullet/IconBullet.vue +104 -104
  53. package/src/components/IconBullet/IconBulletList.vue +55 -55
  54. package/src/components/Icons/AdvanceAppointments.vue +161 -161
  55. package/src/components/Icons/Audio/CloudFailed.vue +27 -27
  56. package/src/components/Icons/Audio/CloudSaved.vue +28 -28
  57. package/src/components/Icons/Audio/Delete.vue +22 -22
  58. package/src/components/Icons/Audio/Pause.vue +25 -25
  59. package/src/components/Icons/Audio/Play.vue +22 -22
  60. package/src/components/Icons/Calendar.vue +28 -28
  61. package/src/components/Icons/CalendarNotification.vue +137 -137
  62. package/src/components/Icons/Chair.vue +43 -43
  63. package/src/components/Icons/ChairNotification.vue +46 -46
  64. package/src/components/Icons/Circle.vue +66 -66
  65. package/src/components/Icons/FavIcon.vue +69 -69
  66. package/src/components/Icons/FilledCircle.vue +11 -11
  67. package/src/components/Icons/Group3.vue +57 -57
  68. package/src/components/Icons/Play.vue +16 -16
  69. package/src/components/Icons/RingNotification.vue +65 -65
  70. package/src/components/Icons/SolidArrowRight.vue +14 -14
  71. package/src/components/Icons/checkbox.vue +19 -19
  72. package/src/components/Icons/outlineChecked.vue +38 -38
  73. package/src/components/Input/Input.css +234 -234
  74. package/src/components/Input/Input.vue +281 -281
  75. package/src/components/Laboratory/AppointmentCard/AppointmentCard.css +7 -7
  76. package/src/components/Laboratory/AppointmentCard/AppointmentCard.vue +116 -116
  77. package/src/components/Laboratory/ChatBoxImage/ChatBoxImage.vue +81 -81
  78. package/src/components/Laboratory/ChatMessage/ChatMessage.vue +113 -113
  79. package/src/components/Laboratory/ChatMessage/ChatMessageBadge.css +4 -4
  80. package/src/components/Laboratory/ChatMessage/ChatMessageBadge.vue +99 -99
  81. package/src/components/Laboratory/ChatNotification/ChatNotification.vue +130 -130
  82. package/src/components/Laboratory/DocumentCard/DocumentCard.css +3 -3
  83. package/src/components/Laboratory/DocumentCard/DocumentCard.vue +50 -50
  84. package/src/components/Laboratory/DocumentCard/DocumentCardItem.vue +53 -53
  85. package/src/components/Laboratory/InfoCard/InfoCard.vue +162 -162
  86. package/src/components/Laboratory/MainColumnsBar/MainColumnsBar.vue +102 -102
  87. package/src/components/Laboratory/ProgressCircle/ProgressCircle.vue +152 -152
  88. package/src/components/Laboratory/ProgressLinear/ProgressLinear.css +33 -33
  89. package/src/components/Laboratory/ProgressLinear/ProgressLinear.vue +75 -75
  90. package/src/components/Laboratory/SelectionColumnBar/SelectionColumnBar.vue +92 -92
  91. package/src/components/Laboratory/StatusNotification/StatusNotification.vue +49 -49
  92. package/src/components/Laboratory/TagLabel/TagLabel.vue +126 -126
  93. package/src/components/Laboratory/TagLabelGroup/TagLabelGroup.vue +97 -97
  94. package/src/components/Laboratory/TicketCard/TicketCard.css +3 -3
  95. package/src/components/Laboratory/TicketCard/TicketCard.vue +143 -143
  96. package/src/components/Laboratory/TimeLine/TimeLineEvent.css +18 -18
  97. package/src/components/Laboratory/TimeLine/TimeLineEvent.vue +119 -119
  98. package/src/components/Laboratory/TimeLine/Timeline.css +4 -4
  99. package/src/components/Laboratory/TimeLine/Timeline.vue +30 -30
  100. package/src/components/Loader/Loader.css +78 -78
  101. package/src/components/MaintenanceBanner/MaintenanceBanner.css +353 -353
  102. package/src/components/MaintenanceBanner/MaintenanceBanner.vue +140 -140
  103. package/src/components/MaintenanceBanner/MaintenanceIllustration.vue +54 -54
  104. package/src/components/Modal/Modal.css +5 -5
  105. package/src/components/Modal/Modal.vue +29 -29
  106. package/src/components/NotificationBubble/NotificationBubble.css +4 -4
  107. package/src/components/NotificationBubble/NotificationBubble.vue +90 -90
  108. package/src/components/OtpInput/OtpInput.css +43 -43
  109. package/src/components/OtpInput/OtpInput.vue +181 -181
  110. package/src/components/PhoneInput/PhoneInput.css +151 -126
  111. package/src/components/PhoneInput/PhoneInput.vue +230 -139
  112. package/src/components/RadioGroup/RadioGroup.css +65 -0
  113. package/src/components/RadioGroup/RadioGroup.vue +134 -0
  114. package/src/components/Select/Select.css +172 -172
  115. package/src/components/Select/Select.vue +377 -377
  116. package/src/components/SelectAutocomplete/SelectAutocomplete.css +172 -172
  117. package/src/components/SelectAutocomplete/SelectAutocomplete.vue +414 -414
  118. package/src/components/TextArea/TextArea.css +269 -269
  119. package/src/components/TextArea/TextArea.vue +207 -207
  120. package/src/components/TickBox/TickBox.css +116 -116
  121. package/src/components/TickBox/TickBox.vue +172 -172
  122. package/src/components/Tile/Tile.css +106 -106
  123. package/src/components/Tile/Tile.vue +173 -173
  124. package/src/components/accessibility.css +218 -218
  125. package/src/components/index.ts +110 -109
  126. package/src/constants/iconEnums.ts +3 -3
  127. package/src/i18n/i18n.ts +15 -15
  128. package/src/i18n/locales/de.json +30 -30
  129. package/src/i18n/locales/en.json +30 -30
  130. package/src/index.ts +43 -43
  131. package/src/main.ts +11 -11
  132. package/src/pages/AccordionGroupPage.vue +873 -873
  133. package/src/pages/AllPage.vue +2483 -2365
  134. package/src/pages/SelectPage.vue +1302 -1302
  135. package/src/pages/TilePage.vue +902 -902
  136. package/src/plugins/vuetify.ts +54 -54
  137. package/src/shims-vue.d.ts +30 -30
  138. package/src/utils/index.ts +733 -733
  139. package/src/vite-env.d.ts +1 -1
  140. package/tests/unit/accessibility/component-a11y.spec.ts +657 -657
  141. package/tests/unit/components/Accordion/AccordionGroup.spec.ts +228 -228
  142. package/tests/unit/components/Accordion/AccordionItem.spec.ts +257 -257
  143. package/tests/unit/components/Appointment/AnamneseNotification.spec.ts +176 -176
  144. package/tests/unit/components/Appointment/Card/Actions.spec.ts +436 -436
  145. package/tests/unit/components/Appointment/Card/Card.spec.ts +531 -531
  146. package/tests/unit/components/Appointment/Card/Details.spec.ts +395 -395
  147. package/tests/unit/components/Audio/Audio.spec.ts +403 -403
  148. package/tests/unit/components/Audio/Waveform.spec.ts +483 -483
  149. package/tests/unit/components/Background/Background.spec.ts +177 -177
  150. package/tests/unit/components/Core/AnamneseAnswerDialog.spec.ts +344 -0
  151. package/tests/unit/components/Core/Banner.spec.ts +187 -0
  152. package/tests/unit/components/Core/Button.spec.ts +346 -346
  153. package/tests/unit/components/Core/Checkbox.spec.ts +544 -544
  154. package/tests/unit/components/Core/DateInput.spec.ts +702 -702
  155. package/tests/unit/components/Core/Dialog.spec.ts +448 -448
  156. package/tests/unit/components/Core/EditField.spec.ts +541 -541
  157. package/tests/unit/components/Core/Input.spec.ts +512 -512
  158. package/tests/unit/components/Core/List.spec.ts +163 -0
  159. package/tests/unit/components/Core/ListItem.spec.ts +205 -0
  160. package/tests/unit/components/Core/Modal.spec.ts +518 -518
  161. package/tests/unit/components/Core/NotificationBubble.spec.ts +606 -606
  162. package/tests/unit/components/Core/OtpInput.spec.ts +708 -708
  163. package/tests/unit/components/Core/PhoneInput.spec.ts +757 -619
  164. package/tests/unit/components/Core/RadioGroup.spec.ts +318 -0
  165. package/tests/unit/components/Core/Select.spec.ts +712 -712
  166. package/tests/unit/components/Core/SelectAutocomplete.spec.ts +361 -0
  167. package/tests/unit/components/Core/TextArea.spec.ts +565 -565
  168. package/tests/unit/components/Core/TickBox.spec.ts +836 -836
  169. package/tests/unit/components/Core/Tile.spec.ts +286 -0
  170. package/tests/unit/components/DateInput/DateInput.spec.ts +128 -0
  171. package/tests/unit/components/ErrorPage/ErrorPage.spec.ts +313 -313
  172. package/tests/unit/components/ErrorPage/ErrorPageLogo.spec.ts +153 -153
  173. package/tests/unit/components/IconBullet/IconBullet.spec.ts +356 -356
  174. package/tests/unit/components/IconBullet/IconBulletList.spec.ts +371 -371
  175. package/tests/unit/components/Icons/AdvanceAppointments.spec.ts +186 -186
  176. package/tests/unit/components/Icons/Audio/CloudFailed.spec.ts +108 -108
  177. package/tests/unit/components/Icons/Audio/CloudSaved.spec.ts +149 -149
  178. package/tests/unit/components/Icons/Audio/Delete.spec.ts +158 -158
  179. package/tests/unit/components/Icons/Audio/Pause.spec.ts +208 -208
  180. package/tests/unit/components/Icons/Audio/Play.spec.ts +217 -217
  181. package/tests/unit/components/Icons/CalendarNotification.spec.ts +193 -193
  182. package/tests/unit/components/Icons/Chair.spec.ts +241 -241
  183. package/tests/unit/components/Icons/ChairNotification.spec.ts +318 -318
  184. package/tests/unit/components/Icons/Circle.spec.ts +255 -255
  185. package/tests/unit/components/Icons/FavIcon.spec.ts +259 -259
  186. package/tests/unit/components/Icons/FilledCircle.spec.ts +274 -274
  187. package/tests/unit/components/Icons/Group3.spec.ts +362 -362
  188. package/tests/unit/components/Icons/Logo.spec.ts +229 -229
  189. package/tests/unit/components/Icons/MiniLogo.spec.ts +38 -38
  190. package/tests/unit/components/Icons/RingNotification.spec.ts +400 -400
  191. package/tests/unit/components/Icons/SolidArrowRight.spec.ts +49 -49
  192. package/tests/unit/components/Icons/calendar.spec.ts +293 -293
  193. package/tests/unit/components/Icons/checkbox.spec.ts +315 -315
  194. package/tests/unit/components/Icons/outlineChecked.spec.ts +441 -441
  195. package/tests/unit/components/Icons/play.spec.ts +315 -315
  196. package/tests/unit/components/Laboratory/AppointmentCard.spec.ts +167 -167
  197. package/tests/unit/components/Laboratory/ChatBoxImage.spec.ts +179 -179
  198. package/tests/unit/components/Laboratory/ChatMessage.spec.ts +263 -263
  199. package/tests/unit/components/Laboratory/ChatMessageBadge.spec.ts +282 -282
  200. package/tests/unit/components/Laboratory/ChatNotification.spec.ts +256 -256
  201. package/tests/unit/components/Laboratory/DocumentCard.spec.ts +228 -228
  202. package/tests/unit/components/Laboratory/DocumentCardItem.spec.ts +236 -236
  203. package/tests/unit/components/Laboratory/InfoCard.spec.ts +308 -308
  204. package/tests/unit/components/Laboratory/MainColumnsBar.spec.ts +251 -251
  205. package/tests/unit/components/Laboratory/ProgressCircle.spec.ts +290 -290
  206. package/tests/unit/components/Laboratory/ProgressLinear.spec.ts +275 -275
  207. package/tests/unit/components/Laboratory/SelectionColumnBar.spec.ts +288 -288
  208. package/tests/unit/components/Laboratory/StatusNotification.spec.ts +296 -296
  209. package/tests/unit/components/Laboratory/TagLabel.spec.ts +353 -353
  210. package/tests/unit/components/Laboratory/TagLabelGroup.spec.ts +377 -377
  211. package/tests/unit/components/Laboratory/TicketCard.spec.ts +351 -351
  212. package/tests/unit/components/Laboratory/TimeLineEvent.spec.ts +381 -381
  213. package/tests/unit/components/Laboratory/Timeline.spec.ts +419 -419
  214. package/tests/unit/components/Loader/Loader.spec.ts +197 -197
  215. package/tests/unit/components/MaintenanceBanner/MaintenanceBanner.spec.ts +302 -302
  216. package/tests/unit/constants/iconEnums.spec.ts +39 -39
  217. package/tests/unit/i18n/i18n.spec.ts +88 -88
  218. package/tests/unit/plugins/vuetify.spec.ts +182 -182
  219. package/tests/unit/setup.ts +237 -237
  220. package/tests/unit/src/components/index.spec.ts.skip +192 -192
  221. package/tests/unit/src/index.spec.ts.skip +182 -182
  222. package/tests/unit/src/main.spec.ts +111 -111
  223. package/tests/unit/utils/accessibility.spec.ts +318 -318
  224. package/tests/unit/utils/anamnese.spec.ts +531 -0
  225. package/tsconfig.json +26 -26
  226. package/vite.config.ts +29 -29
  227. package/vitest.config.ts +91 -91
@@ -1,703 +1,703 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { mount, flushPromises } from '@vue/test-utils';
3
- import { nextTick } from 'vue';
4
- import DateInput from '@components/DateInput/DateInput.vue';
5
- import { parse, format, isValid } from 'date-fns';
6
-
7
- // Mock vue-i18n
8
- const mockT = vi.fn().mockImplementation((key: string, defaultValue?: string | { date: string }) => {
9
- const translations: Record<string, string> = {
10
- 'wl.date_input.placeholder': 'DD.MM.YYYY',
11
- 'wl.date_input.invalid_date': 'Please enter a valid date',
12
- 'wl.date_input.max_date_error': 'Date must be before {{date}}',
13
- 'wl.date_input.min_date_error': 'Date must be after {{date}}'
14
- };
15
-
16
- if (typeof defaultValue === 'object' && defaultValue.date) {
17
- return translations[key]?.replace('{{date}}', defaultValue.date) || key;
18
- }
19
-
20
- return translations[key] || defaultValue || key;
21
- });
22
-
23
- vi.mock('vue-i18n', () => ({
24
- useI18n: () => ({
25
- t: mockT
26
- })
27
- }));
28
-
29
- describe('DateInput', () => {
30
- beforeEach(() => {
31
- vi.clearAllMocks();
32
- });
33
-
34
- // Test default behavior and rendering
35
- describe('Default Behavior', () => {
36
- it('renders with default props', () => {
37
- const wrapper = mount(DateInput);
38
-
39
- expect(wrapper.find('[data-testid="root"]').exists()).toBe(true);
40
- expect(wrapper.find('.wl-date-input').exists()).toBe(true);
41
- expect(wrapper.vm.layout).toBe('default');
42
- expect(wrapper.vm.variant).toBe('outlined');
43
- expect(wrapper.vm.modelValue).toBeNull();
44
- expect(wrapper.vm.formattedDate).toBe('');
45
- expect(wrapper.vm.inputState).toBe('idle');
46
- expect(wrapper.vm.inputMessage).toBe('');
47
- });
48
-
49
- it('uses i18n placeholder when no placeholder prop provided', () => {
50
- const wrapper = mount(DateInput);
51
- expect(mockT).toHaveBeenCalledWith('wl.date_input.placeholder', 'TT.MM.JJJJ');
52
- expect(wrapper.vm.placeholder).toBe('DD.MM.YYYY');
53
- });
54
-
55
- it('uses provided placeholder over i18n default', () => {
56
- const wrapper = mount(DateInput, {
57
- props: {
58
- placeholder: 'Custom placeholder'
59
- }
60
- });
61
-
62
- expect(wrapper.vm.placeholder).toBe('Custom placeholder');
63
- });
64
-
65
- it('applies edit-field layout class', () => {
66
- const wrapper = mount(DateInput, {
67
- props: {
68
- layout: 'edit-field'
69
- }
70
- });
71
-
72
- expect(wrapper.find('.edit-layout').exists()).toBe(true);
73
- expect(wrapper.vm.layout).toBe('edit-field');
74
- });
75
- });
76
-
77
- // Test v-model functionality
78
- describe('v-model', () => {
79
- it('initializes formattedDate with valid ISO date', () => {
80
- const isoDate = '2023-12-25T10:30:00.000Z';
81
- const wrapper = mount(DateInput, {
82
- props: {
83
- modelValue: isoDate
84
- }
85
- });
86
-
87
- expect(wrapper.vm.formattedDate).toBe('25.12.2023');
88
- });
89
-
90
- it('handles null modelValue', () => {
91
- const wrapper = mount(DateInput, {
92
- props: {
93
- modelValue: null
94
- }
95
- });
96
-
97
- expect(wrapper.vm.formattedDate).toBe('');
98
- });
99
-
100
- it('handles invalid ISO date string', () => {
101
- const wrapper = mount(DateInput, {
102
- props: {
103
- modelValue: 'invalid-date'
104
- }
105
- });
106
-
107
- expect(wrapper.vm.formattedDate).toBe('');
108
- });
109
-
110
- it('updates formattedDate when modelValue prop changes', async () => {
111
- const wrapper = mount(DateInput, {
112
- props: {
113
- modelValue: '2023-01-15T00:00:00.000Z'
114
- }
115
- });
116
-
117
- expect(wrapper.vm.formattedDate).toBe('15.01.2023');
118
-
119
- await wrapper.setProps({ modelValue: '2023-12-25T00:00:00.000Z' });
120
-
121
- expect(wrapper.vm.formattedDate).toBe('25.12.2023');
122
- });
123
-
124
- it('emits update:modelValue with ISO string when valid date entered', async () => {
125
- const wrapper = mount(DateInput);
126
-
127
- // Mock the onDateInput method to simulate user input
128
- const mockEvent = {
129
- target: { value: '25122023' }
130
- } as unknown as Event;
131
-
132
- wrapper.vm.onDateInput(mockEvent);
133
-
134
- expect(wrapper.emitted('update:modelValue')).toBeTruthy();
135
- const emittedValue = wrapper.emitted('update:modelValue')?.[0]?.[0];
136
- expect(emittedValue).toContain('2023-12-25');
137
- });
138
- });
139
-
140
- // Test date formatting and parsing
141
- describe('Date Formatting', () => {
142
- it('formats date input correctly as user types', async () => {
143
- const wrapper = mount(DateInput);
144
-
145
- // Test progressive input formatting
146
- let mockEvent = { target: { value: '25' } } as unknown as Event;
147
- wrapper.vm.onDateInput(mockEvent);
148
- expect(wrapper.vm.formattedDate).toBe('25');
149
-
150
- mockEvent = { target: { value: '251' } } as unknown as Event;
151
- wrapper.vm.onDateInput(mockEvent);
152
- expect(wrapper.vm.formattedDate).toBe('25.1');
153
-
154
- mockEvent = { target: { value: '2512' } } as unknown as Event;
155
- wrapper.vm.onDateInput(mockEvent);
156
- expect(wrapper.vm.formattedDate).toBe('25.12');
157
-
158
- mockEvent = { target: { value: '25122' } } as unknown as Event;
159
- wrapper.vm.onDateInput(mockEvent);
160
- expect(wrapper.vm.formattedDate).toBe('25.12.2');
161
-
162
- mockEvent = { target: { value: '251220' } } as unknown as Event;
163
- wrapper.vm.onDateInput(mockEvent);
164
- expect(wrapper.vm.formattedDate).toBe('25.12.20');
165
-
166
- mockEvent = { target: { value: '25122023' } } as unknown as Event;
167
- wrapper.vm.onDateInput(mockEvent);
168
- expect(wrapper.vm.formattedDate).toBe('25.12.2023');
169
- });
170
-
171
- it('removes non-digit characters', async () => {
172
- vi.useFakeTimers();
173
- const wrapper = mount(DateInput);
174
-
175
- const mockEvent = {
176
- target: { value: '2a5b.1c2d.2e0f2g3h' }
177
- } as unknown as Event;
178
-
179
- wrapper.vm.onDateInput(mockEvent);
180
- // After 500ms, invalid characters should be removed
181
- vi.advanceTimersByTime(500);
182
- expect(wrapper.vm.formattedDate).toBe('25.12.2023');
183
-
184
- vi.useRealTimers();
185
- wrapper.unmount();
186
- });
187
-
188
- it('limits input to 10 characters', async () => {
189
- vi.useFakeTimers();
190
- const wrapper = mount(DateInput);
191
-
192
- const mockEvent = {
193
- target: { value: '25.12.202312345' }
194
- } as unknown as Event;
195
-
196
- wrapper.vm.onDateInput(mockEvent);
197
- // After 500ms, excess characters should be removed
198
- vi.advanceTimersByTime(500);
199
- expect(wrapper.vm.formattedDate).toBe('25.12.2023');
200
-
201
- vi.useRealTimers();
202
- wrapper.unmount();
203
- });
204
-
205
- it('computes isoValue correctly from formatted date', () => {
206
- const wrapper = mount(DateInput);
207
- wrapper.vm.formattedDate = '25.12.2023';
208
-
209
- expect(wrapper.vm.isoValue).toBe('2023-12-25');
210
- });
211
-
212
- it('returns empty isoValue for invalid formatted date', () => {
213
- const wrapper = mount(DateInput);
214
- wrapper.vm.formattedDate = '32.13.2023'; // Invalid date
215
-
216
- expect(wrapper.vm.isoValue).toBe('');
217
- });
218
- });
219
-
220
- // Test date validation
221
- describe('Date Validation', () => {
222
- it('sets error state for invalid date', async () => {
223
- const wrapper = mount(DateInput);
224
-
225
- const mockEvent = {
226
- target: { value: '32122023' } // Invalid day
227
- } as unknown as Event;
228
-
229
- wrapper.vm.onDateInput(mockEvent);
230
-
231
- expect(wrapper.vm.inputState).toBe('error');
232
- expect(wrapper.vm.inputMessage).toBe('Please enter a valid date');
233
- });
234
-
235
- it('sets success state for valid date', async () => {
236
- const wrapper = mount(DateInput);
237
-
238
- const mockEvent = {
239
- target: { value: '25122023' }
240
- } as unknown as Event;
241
-
242
- wrapper.vm.onDateInput(mockEvent);
243
-
244
- expect(wrapper.vm.inputState).toBe('success');
245
- expect(wrapper.vm.inputMessage).toBe('');
246
- });
247
-
248
- it('resets state for incomplete date', async () => {
249
- const wrapper = mount(DateInput);
250
-
251
- // First enter complete date
252
- let mockEvent = {
253
- target: { value: '25122023' }
254
- } as unknown as Event;
255
- wrapper.vm.onDateInput(mockEvent);
256
- expect(wrapper.vm.inputState).toBe('success');
257
-
258
- // Then enter incomplete date
259
- mockEvent = {
260
- target: { value: '251220' }
261
- } as unknown as Event;
262
- wrapper.vm.onDateInput(mockEvent);
263
-
264
- expect(wrapper.vm.inputState).toBe('idle');
265
- expect(wrapper.vm.inputMessage).toBe('');
266
- });
267
- });
268
-
269
- // Test min/max date validation
270
- describe('Min/Max Date Validation', () => {
271
- it('validates against minDate', async () => {
272
- const minDate = new Date('2023-12-20');
273
- const wrapper = mount(DateInput, {
274
- props: {
275
- minDate,
276
- minDateErrorMessage: 'Date must be after minimum'
277
- }
278
- });
279
-
280
- // Try to enter date before minDate
281
- const mockEvent = {
282
- target: { value: '15122023' } // 15.12.2023 is before 20.12.2023
283
- } as unknown as Event;
284
-
285
- wrapper.vm.onDateInput(mockEvent);
286
-
287
- expect(wrapper.vm.inputState).toBe('error');
288
- expect(wrapper.vm.inputMessage).toBe('Date must be after minimum');
289
- });
290
-
291
- it('validates against maxDate', async () => {
292
- const maxDate = new Date('2023-12-20');
293
- const wrapper = mount(DateInput, {
294
- props: {
295
- maxDate,
296
- maxDateErrorMessage: 'Date must be before maximum'
297
- }
298
- });
299
-
300
- // Try to enter date after maxDate
301
- const mockEvent = {
302
- target: { value: '25122023' } // 25.12.2023 is after 20.12.2023
303
- } as unknown as Event;
304
-
305
- wrapper.vm.onDateInput(mockEvent);
306
-
307
- expect(wrapper.vm.inputState).toBe('error');
308
- expect(wrapper.vm.inputMessage).toBe('Date must be before maximum');
309
- });
310
-
311
- it('accepts date within min/max range', async () => {
312
- const minDate = new Date('2023-12-15');
313
- const maxDate = new Date('2023-12-25');
314
- const wrapper = mount(DateInput, {
315
- props: {
316
- minDate,
317
- maxDate
318
- }
319
- });
320
-
321
- const mockEvent = {
322
- target: { value: '20122023' } // 20.12.2023 is between min and max
323
- } as unknown as Event;
324
-
325
- wrapper.vm.onDateInput(mockEvent);
326
-
327
- expect(wrapper.vm.inputState).toBe('success');
328
- expect(wrapper.vm.inputMessage).toBe('');
329
- });
330
-
331
- it('computes nativeMin and nativeMax correctly', () => {
332
- const minDate = new Date('2023-12-15');
333
- const maxDate = new Date('2023-12-25');
334
- const wrapper = mount(DateInput, {
335
- props: {
336
- minDate,
337
- maxDate
338
- }
339
- });
340
-
341
- expect(wrapper.vm.nativeMin).toBe('2023-12-15');
342
- expect(wrapper.vm.nativeMax).toBe('2023-12-25');
343
- });
344
-
345
- it('handles invalid min/max dates', () => {
346
- const wrapper = mount(DateInput, {
347
- props: {
348
- minDate: new Date('invalid'),
349
- maxDate: new Date('invalid')
350
- }
351
- });
352
-
353
- expect(wrapper.vm.nativeMin).toBe('');
354
- expect(wrapper.vm.nativeMax).toBe('');
355
- });
356
- });
357
-
358
- // Test native date picker integration
359
- describe('Native Date Picker', () => {
360
- it('renders native date input', () => {
361
- const wrapper = mount(DateInput);
362
-
363
- expect(wrapper.find('input[type="date"]').exists()).toBe(true);
364
- expect(wrapper.find('.native-date').exists()).toBe(true);
365
- expect(wrapper.find('.date-wrapper').exists()).toBe(true);
366
- expect(wrapper.find('.date-icon').exists()).toBe(true);
367
- });
368
-
369
- it('handles native date change', async () => {
370
- const wrapper = mount(DateInput);
371
-
372
- // Mock the native input element
373
- const mockNativeDate = {
374
- value: '2023-12-25'
375
- };
376
- wrapper.vm.nativeDate = mockNativeDate as any;
377
-
378
- const mockEvent = {} as Event;
379
- wrapper.vm.onNativeDateChange(mockEvent);
380
-
381
- expect(wrapper.vm.formattedDate).toBe('25.12.2023');
382
- });
383
-
384
- it('handles native date change with edit-field layout', async () => {
385
- const wrapper = mount(DateInput, {
386
- props: {
387
- layout: 'edit-field'
388
- }
389
- });
390
-
391
- // Get the real inputRef methods and spy on them
392
- const inputRef = wrapper.vm.inputRef;
393
- const focusSpy = vi.spyOn(inputRef, 'focus');
394
- const blurSpy = vi.spyOn(inputRef, 'blur');
395
-
396
- // Mock the native input element
397
- const mockNativeDate = {
398
- value: '2023-12-25'
399
- };
400
- wrapper.vm.nativeDate = mockNativeDate as any;
401
-
402
- const mockEvent = {} as Event;
403
- wrapper.vm.onNativeDateChange(mockEvent);
404
-
405
- await nextTick();
406
-
407
- expect(focusSpy).toHaveBeenCalled();
408
- expect(blurSpy).toHaveBeenCalled();
409
- });
410
-
411
- it('sets native input attributes correctly', () => {
412
- const minDate = new Date('2023-12-01');
413
- const maxDate = new Date('2023-12-31');
414
- const wrapper = mount(DateInput, {
415
- props: {
416
- minDate,
417
- maxDate,
418
- modelValue: '2023-12-15T10:30:00.000Z'
419
- }
420
- });
421
-
422
- const nativeInput = wrapper.find('input[type="date"]');
423
- expect(nativeInput.attributes('min')).toBe('2023-12-01');
424
- expect(nativeInput.attributes('max')).toBe('2023-12-31');
425
- expect(nativeInput.attributes('value')).toBe('2023-12-15');
426
- });
427
- });
428
-
429
- // Test parseDateWithCurrentTime function
430
- describe('Date Parsing with Current Time', () => {
431
- it('preserves current time when parsing date', () => {
432
- const wrapper = mount(DateInput);
433
- const now = new Date();
434
-
435
- // Use today's date to avoid large time differences
436
- const todayFormatted = `${now.getDate().toString().padStart(2, '0')}.${(now.getMonth() + 1).toString().padStart(2, '0')}.${now.getFullYear()}`;
437
- const result = wrapper.vm.parseDateWithCurrentTime(todayFormatted);
438
-
439
- expect(result.getDate()).toBe(now.getDate());
440
- expect(result.getMonth()).toBe(now.getMonth());
441
- expect(result.getFullYear()).toBe(now.getFullYear());
442
-
443
- // Time should be close to current time (within a few seconds)
444
- const timeDiff = Math.abs(result.getTime() - now.getTime());
445
- expect(timeDiff).toBeLessThan(5000); // Less than 5 seconds difference
446
- });
447
- });
448
-
449
- // Test layout-specific behavior
450
- describe('Layout Behavior', () => {
451
- it('shows success state and messages in default layout', () => {
452
- const wrapper = mount(DateInput, {
453
- props: {
454
- layout: 'default'
455
- }
456
- });
457
-
458
- expect(wrapper.vm.isDefaultLayout).toBe(true);
459
-
460
- // Set success state
461
- wrapper.vm.inputState = 'success';
462
- wrapper.vm.inputMessage = 'Success message';
463
-
464
- expect(wrapper.vm.isDefaultLayout).toBe(true);
465
- });
466
-
467
- it('hides success state in edit-field layout', () => {
468
- const wrapper = mount(DateInput, {
469
- props: {
470
- layout: 'edit-field'
471
- }
472
- });
473
-
474
- expect(wrapper.vm.isDefaultLayout).toBe(false);
475
- });
476
- });
477
-
478
- // Test exposed methods
479
- describe('Exposed Methods', () => {
480
- it('exposes focus, blur, and select methods', () => {
481
- const wrapper = mount(DateInput);
482
-
483
- expect(wrapper.vm.focus).toBeDefined();
484
- expect(wrapper.vm.blur).toBeDefined();
485
- expect(wrapper.vm.select).toBeDefined();
486
- expect(typeof wrapper.vm.focus).toBe('function');
487
- expect(typeof wrapper.vm.blur).toBe('function');
488
- expect(typeof wrapper.vm.select).toBe('function');
489
- });
490
-
491
- it('calls inputRef methods when exposed methods are called', () => {
492
- const wrapper = mount(DateInput);
493
-
494
- const mockInputRef = {
495
- focus: vi.fn(),
496
- blur: vi.fn(),
497
- select: vi.fn()
498
- };
499
- wrapper.vm.inputRef = mockInputRef as any;
500
-
501
- wrapper.vm.focus();
502
- wrapper.vm.blur();
503
- wrapper.vm.select();
504
-
505
- expect(mockInputRef.focus).toHaveBeenCalled();
506
- expect(mockInputRef.blur).toHaveBeenCalled();
507
- expect(mockInputRef.select).toHaveBeenCalled();
508
- });
509
- });
510
-
511
- // Test computed properties
512
- describe('Computed Properties', () => {
513
- it('computes error messages correctly with i18n', () => {
514
- const wrapper = mount(DateInput, {
515
- props: {
516
- invalidDateErrorMessage: 'Custom invalid message'
517
- }
518
- });
519
-
520
- expect(wrapper.vm.invalidDateMessage).toBe('Custom invalid message');
521
- });
522
-
523
- it('uses i18n for error messages when not provided', () => {
524
- mockT.mockClear();
525
- const wrapper = mount(DateInput);
526
-
527
- // The component will call multiple i18n keys, let's verify invalidDateMessage works
528
- expect(wrapper.vm.invalidDateMessage).toBe('Please enter a valid date');
529
- expect(mockT).toHaveBeenCalledWith('wl.date_input.invalid_date', 'Bitte ein gültiges Datum eingeben');
530
- });
531
-
532
- it('computes min/max date messages with formatted dates', () => {
533
- const minDate = new Date('2023-12-01');
534
- const maxDate = new Date('2023-12-31');
535
-
536
- const wrapper = mount(DateInput, {
537
- props: {
538
- minDate,
539
- maxDate
540
- }
541
- });
542
-
543
- expect(wrapper.vm.minDateMessage).toContain('01.12.2023');
544
- expect(wrapper.vm.maxDateMessage).toContain('31.12.2023');
545
- });
546
- });
547
-
548
- // Test accessibility
549
- describe('Accessibility', () => {
550
- it('has proper input attributes', () => {
551
- const wrapper = mount(DateInput);
552
-
553
- expect(wrapper.find('[data-testid="root"]').exists()).toBe(true);
554
- expect(wrapper.find('input[type="tel"]').exists()).toBe(true);
555
- expect(wrapper.find('input[id="date-input"]').exists()).toBe(true);
556
- });
557
-
558
- it('has keyboard navigation for date picker', () => {
559
- const wrapper = mount(DateInput);
560
-
561
- const dateWrapper = wrapper.find('.date-wrapper');
562
- expect(dateWrapper.attributes('tabindex')).toBe('0');
563
- });
564
-
565
- it('shows calendar icon', () => {
566
- const wrapper = mount(DateInput);
567
-
568
- const calendarIcon = wrapper.find('[icon="heroicons:calendar"]');
569
- expect(calendarIcon.exists()).toBe(true);
570
- });
571
- });
572
-
573
- // Test edge cases
574
- describe('Edge Cases', () => {
575
- it('handles leap year dates', async () => {
576
- const wrapper = mount(DateInput);
577
-
578
- const mockEvent = {
579
- target: { value: '29022024' } // Feb 29, 2024 (leap year)
580
- } as unknown as Event;
581
-
582
- wrapper.vm.onDateInput(mockEvent);
583
-
584
- expect(wrapper.vm.inputState).toBe('success');
585
- expect(wrapper.vm.formattedDate).toBe('29.02.2024');
586
- });
587
-
588
- it('handles invalid leap year dates', async () => {
589
- const wrapper = mount(DateInput);
590
-
591
- const mockEvent = {
592
- target: { value: '29022023' } // Feb 29, 2023 (not a leap year)
593
- } as unknown as Event;
594
-
595
- wrapper.vm.onDateInput(mockEvent);
596
-
597
- expect(wrapper.vm.inputState).toBe('error');
598
- });
599
-
600
- it('handles edge case dates like December 31', async () => {
601
- const wrapper = mount(DateInput);
602
-
603
- const mockEvent = {
604
- target: { value: '31122023' }
605
- } as unknown as Event;
606
-
607
- wrapper.vm.onDateInput(mockEvent);
608
-
609
- expect(wrapper.vm.inputState).toBe('success');
610
- expect(wrapper.vm.formattedDate).toBe('31.12.2023');
611
- });
612
-
613
- it('handles year 2000 (Y2K)', async () => {
614
- const wrapper = mount(DateInput);
615
-
616
- const mockEvent = {
617
- target: { value: '01012000' }
618
- } as unknown as Event;
619
-
620
- wrapper.vm.onDateInput(mockEvent);
621
-
622
- expect(wrapper.vm.inputState).toBe('success');
623
- expect(wrapper.vm.formattedDate).toBe('01.01.2000');
624
- });
625
-
626
- it('handles various invalid dates', async () => {
627
- const wrapper = mount(DateInput);
628
-
629
- // Use formatted invalid dates that would actually be input by users
630
- const invalidDates = [
631
- '32.01.2023', // Invalid day
632
- '01.13.2023', // Invalid month
633
- '30.02.2023', // Invalid date (February 30th)
634
- '00.01.2023', // Invalid day (0)
635
- '01.00.2023' // Invalid month (0)
636
- ];
637
-
638
- for (const invalidDate of invalidDates) {
639
- const mockEvent = {
640
- target: { value: invalidDate }
641
- } as unknown as Event;
642
-
643
- wrapper.vm.onDateInput(mockEvent);
644
- expect(wrapper.vm.inputState).toBe('error');
645
- }
646
- });
647
- });
648
-
649
- // Test complex scenarios
650
- describe('Complex Scenarios', () => {
651
- it('works with all props combined', () => {
652
- const minDate = new Date('2023-01-01');
653
- const maxDate = new Date('2023-12-31');
654
-
655
- const wrapper = mount(DateInput, {
656
- props: {
657
- modelValue: '2023-06-15T10:30:00.000Z',
658
- layout: 'edit-field',
659
- minDate,
660
- maxDate,
661
- variant: 'filled',
662
- placeholder: 'Enter date here',
663
- invalidDateErrorMessage: 'Custom invalid message',
664
- minDateErrorMessage: 'Custom min error',
665
- maxDateErrorMessage: 'Custom max error'
666
- }
667
- });
668
-
669
- expect(wrapper.vm.formattedDate).toBe('15.06.2023');
670
- expect(wrapper.vm.layout).toBe('edit-field');
671
- expect(wrapper.vm.variant).toBe('filled');
672
- expect(wrapper.vm.placeholder).toBe('Enter date here');
673
- expect(wrapper.vm.nativeMin).toBe('2023-01-01');
674
- expect(wrapper.vm.nativeMax).toBe('2023-12-31');
675
- expect(wrapper.find('.edit-layout').exists()).toBe(true);
676
- });
677
-
678
- it('handles switching between valid and invalid states', async () => {
679
- const wrapper = mount(DateInput);
680
-
681
- // Start with valid date
682
- let mockEvent = {
683
- target: { value: '15062023' }
684
- } as unknown as Event;
685
- wrapper.vm.onDateInput(mockEvent);
686
- expect(wrapper.vm.inputState).toBe('success');
687
-
688
- // Change to invalid date
689
- mockEvent = {
690
- target: { value: '32062023' }
691
- } as unknown as Event;
692
- wrapper.vm.onDateInput(mockEvent);
693
- expect(wrapper.vm.inputState).toBe('error');
694
-
695
- // Back to valid date
696
- mockEvent = {
697
- target: { value: '15062023' }
698
- } as unknown as Event;
699
- wrapper.vm.onDateInput(mockEvent);
700
- expect(wrapper.vm.inputState).toBe('success');
701
- });
702
- });
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { mount, flushPromises } from '@vue/test-utils';
3
+ import { nextTick } from 'vue';
4
+ import DateInput from '@components/DateInput/DateInput.vue';
5
+ import { parse, format, isValid } from 'date-fns';
6
+
7
+ // Mock vue-i18n
8
+ const mockT = vi.fn().mockImplementation((key: string, defaultValue?: string | { date: string }) => {
9
+ const translations: Record<string, string> = {
10
+ 'wl.date_input.placeholder': 'DD.MM.YYYY',
11
+ 'wl.date_input.invalid_date': 'Please enter a valid date',
12
+ 'wl.date_input.max_date_error': 'Date must be before {{date}}',
13
+ 'wl.date_input.min_date_error': 'Date must be after {{date}}'
14
+ };
15
+
16
+ if (typeof defaultValue === 'object' && defaultValue.date) {
17
+ return translations[key]?.replace('{{date}}', defaultValue.date) || key;
18
+ }
19
+
20
+ return translations[key] || defaultValue || key;
21
+ });
22
+
23
+ vi.mock('vue-i18n', () => ({
24
+ useI18n: () => ({
25
+ t: mockT
26
+ })
27
+ }));
28
+
29
+ describe('DateInput', () => {
30
+ beforeEach(() => {
31
+ vi.clearAllMocks();
32
+ });
33
+
34
+ // Test default behavior and rendering
35
+ describe('Default Behavior', () => {
36
+ it('renders with default props', () => {
37
+ const wrapper = mount(DateInput);
38
+
39
+ expect(wrapper.find('[data-testid="root"]').exists()).toBe(true);
40
+ expect(wrapper.find('.wl-date-input').exists()).toBe(true);
41
+ expect(wrapper.vm.layout).toBe('default');
42
+ expect(wrapper.vm.variant).toBe('outlined');
43
+ expect(wrapper.vm.modelValue).toBeNull();
44
+ expect(wrapper.vm.formattedDate).toBe('');
45
+ expect(wrapper.vm.inputState).toBe('idle');
46
+ expect(wrapper.vm.inputMessage).toBe('');
47
+ });
48
+
49
+ it('uses i18n placeholder when no placeholder prop provided', () => {
50
+ const wrapper = mount(DateInput);
51
+ expect(mockT).toHaveBeenCalledWith('wl.date_input.placeholder', 'TT.MM.JJJJ');
52
+ expect(wrapper.vm.placeholder).toBe('DD.MM.YYYY');
53
+ });
54
+
55
+ it('uses provided placeholder over i18n default', () => {
56
+ const wrapper = mount(DateInput, {
57
+ props: {
58
+ placeholder: 'Custom placeholder'
59
+ }
60
+ });
61
+
62
+ expect(wrapper.vm.placeholder).toBe('Custom placeholder');
63
+ });
64
+
65
+ it('applies edit-field layout class', () => {
66
+ const wrapper = mount(DateInput, {
67
+ props: {
68
+ layout: 'edit-field'
69
+ }
70
+ });
71
+
72
+ expect(wrapper.find('.edit-layout').exists()).toBe(true);
73
+ expect(wrapper.vm.layout).toBe('edit-field');
74
+ });
75
+ });
76
+
77
+ // Test v-model functionality
78
+ describe('v-model', () => {
79
+ it('initializes formattedDate with valid ISO date', () => {
80
+ const isoDate = '2023-12-25T10:30:00.000Z';
81
+ const wrapper = mount(DateInput, {
82
+ props: {
83
+ modelValue: isoDate
84
+ }
85
+ });
86
+
87
+ expect(wrapper.vm.formattedDate).toBe('25.12.2023');
88
+ });
89
+
90
+ it('handles null modelValue', () => {
91
+ const wrapper = mount(DateInput, {
92
+ props: {
93
+ modelValue: null
94
+ }
95
+ });
96
+
97
+ expect(wrapper.vm.formattedDate).toBe('');
98
+ });
99
+
100
+ it('handles invalid ISO date string', () => {
101
+ const wrapper = mount(DateInput, {
102
+ props: {
103
+ modelValue: 'invalid-date'
104
+ }
105
+ });
106
+
107
+ expect(wrapper.vm.formattedDate).toBe('');
108
+ });
109
+
110
+ it('updates formattedDate when modelValue prop changes', async () => {
111
+ const wrapper = mount(DateInput, {
112
+ props: {
113
+ modelValue: '2023-01-15T00:00:00.000Z'
114
+ }
115
+ });
116
+
117
+ expect(wrapper.vm.formattedDate).toBe('15.01.2023');
118
+
119
+ await wrapper.setProps({ modelValue: '2023-12-25T00:00:00.000Z' });
120
+
121
+ expect(wrapper.vm.formattedDate).toBe('25.12.2023');
122
+ });
123
+
124
+ it('emits update:modelValue with ISO string when valid date entered', async () => {
125
+ const wrapper = mount(DateInput);
126
+
127
+ // Mock the onDateInput method to simulate user input
128
+ const mockEvent = {
129
+ target: { value: '25122023' }
130
+ } as unknown as Event;
131
+
132
+ wrapper.vm.onDateInput(mockEvent);
133
+
134
+ expect(wrapper.emitted('update:modelValue')).toBeTruthy();
135
+ const emittedValue = wrapper.emitted('update:modelValue')?.[0]?.[0];
136
+ expect(emittedValue).toContain('2023-12-25');
137
+ });
138
+ });
139
+
140
+ // Test date formatting and parsing
141
+ describe('Date Formatting', () => {
142
+ it('formats date input correctly as user types', async () => {
143
+ const wrapper = mount(DateInput);
144
+
145
+ // Test progressive input formatting
146
+ let mockEvent = { target: { value: '25' } } as unknown as Event;
147
+ wrapper.vm.onDateInput(mockEvent);
148
+ expect(wrapper.vm.formattedDate).toBe('25');
149
+
150
+ mockEvent = { target: { value: '251' } } as unknown as Event;
151
+ wrapper.vm.onDateInput(mockEvent);
152
+ expect(wrapper.vm.formattedDate).toBe('25.1');
153
+
154
+ mockEvent = { target: { value: '2512' } } as unknown as Event;
155
+ wrapper.vm.onDateInput(mockEvent);
156
+ expect(wrapper.vm.formattedDate).toBe('25.12');
157
+
158
+ mockEvent = { target: { value: '25122' } } as unknown as Event;
159
+ wrapper.vm.onDateInput(mockEvent);
160
+ expect(wrapper.vm.formattedDate).toBe('25.12.2');
161
+
162
+ mockEvent = { target: { value: '251220' } } as unknown as Event;
163
+ wrapper.vm.onDateInput(mockEvent);
164
+ expect(wrapper.vm.formattedDate).toBe('25.12.20');
165
+
166
+ mockEvent = { target: { value: '25122023' } } as unknown as Event;
167
+ wrapper.vm.onDateInput(mockEvent);
168
+ expect(wrapper.vm.formattedDate).toBe('25.12.2023');
169
+ });
170
+
171
+ it('removes non-digit characters', async () => {
172
+ vi.useFakeTimers();
173
+ const wrapper = mount(DateInput);
174
+
175
+ const mockEvent = {
176
+ target: { value: '2a5b.1c2d.2e0f2g3h' }
177
+ } as unknown as Event;
178
+
179
+ wrapper.vm.onDateInput(mockEvent);
180
+ // After 500ms, invalid characters should be removed
181
+ vi.advanceTimersByTime(500);
182
+ expect(wrapper.vm.formattedDate).toBe('25.12.2023');
183
+
184
+ vi.useRealTimers();
185
+ wrapper.unmount();
186
+ });
187
+
188
+ it('limits input to 10 characters', async () => {
189
+ vi.useFakeTimers();
190
+ const wrapper = mount(DateInput);
191
+
192
+ const mockEvent = {
193
+ target: { value: '25.12.202312345' }
194
+ } as unknown as Event;
195
+
196
+ wrapper.vm.onDateInput(mockEvent);
197
+ // After 500ms, excess characters should be removed
198
+ vi.advanceTimersByTime(500);
199
+ expect(wrapper.vm.formattedDate).toBe('25.12.2023');
200
+
201
+ vi.useRealTimers();
202
+ wrapper.unmount();
203
+ });
204
+
205
+ it('computes isoValue correctly from formatted date', () => {
206
+ const wrapper = mount(DateInput);
207
+ wrapper.vm.formattedDate = '25.12.2023';
208
+
209
+ expect(wrapper.vm.isoValue).toBe('2023-12-25');
210
+ });
211
+
212
+ it('returns empty isoValue for invalid formatted date', () => {
213
+ const wrapper = mount(DateInput);
214
+ wrapper.vm.formattedDate = '32.13.2023'; // Invalid date
215
+
216
+ expect(wrapper.vm.isoValue).toBe('');
217
+ });
218
+ });
219
+
220
+ // Test date validation
221
+ describe('Date Validation', () => {
222
+ it('sets error state for invalid date', async () => {
223
+ const wrapper = mount(DateInput);
224
+
225
+ const mockEvent = {
226
+ target: { value: '32122023' } // Invalid day
227
+ } as unknown as Event;
228
+
229
+ wrapper.vm.onDateInput(mockEvent);
230
+
231
+ expect(wrapper.vm.inputState).toBe('error');
232
+ expect(wrapper.vm.inputMessage).toBe('Please enter a valid date');
233
+ });
234
+
235
+ it('sets success state for valid date', async () => {
236
+ const wrapper = mount(DateInput);
237
+
238
+ const mockEvent = {
239
+ target: { value: '25122023' }
240
+ } as unknown as Event;
241
+
242
+ wrapper.vm.onDateInput(mockEvent);
243
+
244
+ expect(wrapper.vm.inputState).toBe('success');
245
+ expect(wrapper.vm.inputMessage).toBe('');
246
+ });
247
+
248
+ it('resets state for incomplete date', async () => {
249
+ const wrapper = mount(DateInput);
250
+
251
+ // First enter complete date
252
+ let mockEvent = {
253
+ target: { value: '25122023' }
254
+ } as unknown as Event;
255
+ wrapper.vm.onDateInput(mockEvent);
256
+ expect(wrapper.vm.inputState).toBe('success');
257
+
258
+ // Then enter incomplete date
259
+ mockEvent = {
260
+ target: { value: '251220' }
261
+ } as unknown as Event;
262
+ wrapper.vm.onDateInput(mockEvent);
263
+
264
+ expect(wrapper.vm.inputState).toBe('idle');
265
+ expect(wrapper.vm.inputMessage).toBe('');
266
+ });
267
+ });
268
+
269
+ // Test min/max date validation
270
+ describe('Min/Max Date Validation', () => {
271
+ it('validates against minDate', async () => {
272
+ const minDate = new Date('2023-12-20');
273
+ const wrapper = mount(DateInput, {
274
+ props: {
275
+ minDate,
276
+ minDateErrorMessage: 'Date must be after minimum'
277
+ }
278
+ });
279
+
280
+ // Try to enter date before minDate
281
+ const mockEvent = {
282
+ target: { value: '15122023' } // 15.12.2023 is before 20.12.2023
283
+ } as unknown as Event;
284
+
285
+ wrapper.vm.onDateInput(mockEvent);
286
+
287
+ expect(wrapper.vm.inputState).toBe('error');
288
+ expect(wrapper.vm.inputMessage).toBe('Date must be after minimum');
289
+ });
290
+
291
+ it('validates against maxDate', async () => {
292
+ const maxDate = new Date('2023-12-20');
293
+ const wrapper = mount(DateInput, {
294
+ props: {
295
+ maxDate,
296
+ maxDateErrorMessage: 'Date must be before maximum'
297
+ }
298
+ });
299
+
300
+ // Try to enter date after maxDate
301
+ const mockEvent = {
302
+ target: { value: '25122023' } // 25.12.2023 is after 20.12.2023
303
+ } as unknown as Event;
304
+
305
+ wrapper.vm.onDateInput(mockEvent);
306
+
307
+ expect(wrapper.vm.inputState).toBe('error');
308
+ expect(wrapper.vm.inputMessage).toBe('Date must be before maximum');
309
+ });
310
+
311
+ it('accepts date within min/max range', async () => {
312
+ const minDate = new Date('2023-12-15');
313
+ const maxDate = new Date('2023-12-25');
314
+ const wrapper = mount(DateInput, {
315
+ props: {
316
+ minDate,
317
+ maxDate
318
+ }
319
+ });
320
+
321
+ const mockEvent = {
322
+ target: { value: '20122023' } // 20.12.2023 is between min and max
323
+ } as unknown as Event;
324
+
325
+ wrapper.vm.onDateInput(mockEvent);
326
+
327
+ expect(wrapper.vm.inputState).toBe('success');
328
+ expect(wrapper.vm.inputMessage).toBe('');
329
+ });
330
+
331
+ it('computes nativeMin and nativeMax correctly', () => {
332
+ const minDate = new Date('2023-12-15');
333
+ const maxDate = new Date('2023-12-25');
334
+ const wrapper = mount(DateInput, {
335
+ props: {
336
+ minDate,
337
+ maxDate
338
+ }
339
+ });
340
+
341
+ expect(wrapper.vm.nativeMin).toBe('2023-12-15');
342
+ expect(wrapper.vm.nativeMax).toBe('2023-12-25');
343
+ });
344
+
345
+ it('handles invalid min/max dates', () => {
346
+ const wrapper = mount(DateInput, {
347
+ props: {
348
+ minDate: new Date('invalid'),
349
+ maxDate: new Date('invalid')
350
+ }
351
+ });
352
+
353
+ expect(wrapper.vm.nativeMin).toBe('');
354
+ expect(wrapper.vm.nativeMax).toBe('');
355
+ });
356
+ });
357
+
358
+ // Test native date picker integration
359
+ describe('Native Date Picker', () => {
360
+ it('renders native date input', () => {
361
+ const wrapper = mount(DateInput);
362
+
363
+ expect(wrapper.find('input[type="date"]').exists()).toBe(true);
364
+ expect(wrapper.find('.native-date').exists()).toBe(true);
365
+ expect(wrapper.find('.date-wrapper').exists()).toBe(true);
366
+ expect(wrapper.find('.date-icon').exists()).toBe(true);
367
+ });
368
+
369
+ it('handles native date change', async () => {
370
+ const wrapper = mount(DateInput);
371
+
372
+ // Mock the native input element
373
+ const mockNativeDate = {
374
+ value: '2023-12-25'
375
+ };
376
+ wrapper.vm.nativeDate = mockNativeDate as any;
377
+
378
+ const mockEvent = {} as Event;
379
+ wrapper.vm.onNativeDateChange(mockEvent);
380
+
381
+ expect(wrapper.vm.formattedDate).toBe('25.12.2023');
382
+ });
383
+
384
+ it('handles native date change with edit-field layout', async () => {
385
+ const wrapper = mount(DateInput, {
386
+ props: {
387
+ layout: 'edit-field'
388
+ }
389
+ });
390
+
391
+ // Get the real inputRef methods and spy on them
392
+ const inputRef = wrapper.vm.inputRef;
393
+ const focusSpy = vi.spyOn(inputRef, 'focus');
394
+ const blurSpy = vi.spyOn(inputRef, 'blur');
395
+
396
+ // Mock the native input element
397
+ const mockNativeDate = {
398
+ value: '2023-12-25'
399
+ };
400
+ wrapper.vm.nativeDate = mockNativeDate as any;
401
+
402
+ const mockEvent = {} as Event;
403
+ wrapper.vm.onNativeDateChange(mockEvent);
404
+
405
+ await nextTick();
406
+
407
+ expect(focusSpy).toHaveBeenCalled();
408
+ expect(blurSpy).toHaveBeenCalled();
409
+ });
410
+
411
+ it('sets native input attributes correctly', () => {
412
+ const minDate = new Date('2023-12-01');
413
+ const maxDate = new Date('2023-12-31');
414
+ const wrapper = mount(DateInput, {
415
+ props: {
416
+ minDate,
417
+ maxDate,
418
+ modelValue: '2023-12-15T10:30:00.000Z'
419
+ }
420
+ });
421
+
422
+ const nativeInput = wrapper.find('input[type="date"]');
423
+ expect(nativeInput.attributes('min')).toBe('2023-12-01');
424
+ expect(nativeInput.attributes('max')).toBe('2023-12-31');
425
+ expect(nativeInput.attributes('value')).toBe('2023-12-15');
426
+ });
427
+ });
428
+
429
+ // Test parseDateWithCurrentTime function
430
+ describe('Date Parsing with Current Time', () => {
431
+ it('preserves current time when parsing date', () => {
432
+ const wrapper = mount(DateInput);
433
+ const now = new Date();
434
+
435
+ // Use today's date to avoid large time differences
436
+ const todayFormatted = `${now.getDate().toString().padStart(2, '0')}.${(now.getMonth() + 1).toString().padStart(2, '0')}.${now.getFullYear()}`;
437
+ const result = wrapper.vm.parseDateWithCurrentTime(todayFormatted);
438
+
439
+ expect(result.getDate()).toBe(now.getDate());
440
+ expect(result.getMonth()).toBe(now.getMonth());
441
+ expect(result.getFullYear()).toBe(now.getFullYear());
442
+
443
+ // Time should be close to current time (within a few seconds)
444
+ const timeDiff = Math.abs(result.getTime() - now.getTime());
445
+ expect(timeDiff).toBeLessThan(5000); // Less than 5 seconds difference
446
+ });
447
+ });
448
+
449
+ // Test layout-specific behavior
450
+ describe('Layout Behavior', () => {
451
+ it('shows success state and messages in default layout', () => {
452
+ const wrapper = mount(DateInput, {
453
+ props: {
454
+ layout: 'default'
455
+ }
456
+ });
457
+
458
+ expect(wrapper.vm.isDefaultLayout).toBe(true);
459
+
460
+ // Set success state
461
+ wrapper.vm.inputState = 'success';
462
+ wrapper.vm.inputMessage = 'Success message';
463
+
464
+ expect(wrapper.vm.isDefaultLayout).toBe(true);
465
+ });
466
+
467
+ it('hides success state in edit-field layout', () => {
468
+ const wrapper = mount(DateInput, {
469
+ props: {
470
+ layout: 'edit-field'
471
+ }
472
+ });
473
+
474
+ expect(wrapper.vm.isDefaultLayout).toBe(false);
475
+ });
476
+ });
477
+
478
+ // Test exposed methods
479
+ describe('Exposed Methods', () => {
480
+ it('exposes focus, blur, and select methods', () => {
481
+ const wrapper = mount(DateInput);
482
+
483
+ expect(wrapper.vm.focus).toBeDefined();
484
+ expect(wrapper.vm.blur).toBeDefined();
485
+ expect(wrapper.vm.select).toBeDefined();
486
+ expect(typeof wrapper.vm.focus).toBe('function');
487
+ expect(typeof wrapper.vm.blur).toBe('function');
488
+ expect(typeof wrapper.vm.select).toBe('function');
489
+ });
490
+
491
+ it('calls inputRef methods when exposed methods are called', () => {
492
+ const wrapper = mount(DateInput);
493
+
494
+ const mockInputRef = {
495
+ focus: vi.fn(),
496
+ blur: vi.fn(),
497
+ select: vi.fn()
498
+ };
499
+ wrapper.vm.inputRef = mockInputRef as any;
500
+
501
+ wrapper.vm.focus();
502
+ wrapper.vm.blur();
503
+ wrapper.vm.select();
504
+
505
+ expect(mockInputRef.focus).toHaveBeenCalled();
506
+ expect(mockInputRef.blur).toHaveBeenCalled();
507
+ expect(mockInputRef.select).toHaveBeenCalled();
508
+ });
509
+ });
510
+
511
+ // Test computed properties
512
+ describe('Computed Properties', () => {
513
+ it('computes error messages correctly with i18n', () => {
514
+ const wrapper = mount(DateInput, {
515
+ props: {
516
+ invalidDateErrorMessage: 'Custom invalid message'
517
+ }
518
+ });
519
+
520
+ expect(wrapper.vm.invalidDateMessage).toBe('Custom invalid message');
521
+ });
522
+
523
+ it('uses i18n for error messages when not provided', () => {
524
+ mockT.mockClear();
525
+ const wrapper = mount(DateInput);
526
+
527
+ // The component will call multiple i18n keys, let's verify invalidDateMessage works
528
+ expect(wrapper.vm.invalidDateMessage).toBe('Please enter a valid date');
529
+ expect(mockT).toHaveBeenCalledWith('wl.date_input.invalid_date', 'Bitte ein gültiges Datum eingeben');
530
+ });
531
+
532
+ it('computes min/max date messages with formatted dates', () => {
533
+ const minDate = new Date('2023-12-01');
534
+ const maxDate = new Date('2023-12-31');
535
+
536
+ const wrapper = mount(DateInput, {
537
+ props: {
538
+ minDate,
539
+ maxDate
540
+ }
541
+ });
542
+
543
+ expect(wrapper.vm.minDateMessage).toContain('01.12.2023');
544
+ expect(wrapper.vm.maxDateMessage).toContain('31.12.2023');
545
+ });
546
+ });
547
+
548
+ // Test accessibility
549
+ describe('Accessibility', () => {
550
+ it('has proper input attributes', () => {
551
+ const wrapper = mount(DateInput);
552
+
553
+ expect(wrapper.find('[data-testid="root"]').exists()).toBe(true);
554
+ expect(wrapper.find('input[type="tel"]').exists()).toBe(true);
555
+ expect(wrapper.find('input[id="date-input"]').exists()).toBe(true);
556
+ });
557
+
558
+ it('has keyboard navigation for date picker', () => {
559
+ const wrapper = mount(DateInput);
560
+
561
+ const dateWrapper = wrapper.find('.date-wrapper');
562
+ expect(dateWrapper.attributes('tabindex')).toBe('0');
563
+ });
564
+
565
+ it('shows calendar icon', () => {
566
+ const wrapper = mount(DateInput);
567
+
568
+ const calendarIcon = wrapper.find('[icon="heroicons:calendar"]');
569
+ expect(calendarIcon.exists()).toBe(true);
570
+ });
571
+ });
572
+
573
+ // Test edge cases
574
+ describe('Edge Cases', () => {
575
+ it('handles leap year dates', async () => {
576
+ const wrapper = mount(DateInput);
577
+
578
+ const mockEvent = {
579
+ target: { value: '29022024' } // Feb 29, 2024 (leap year)
580
+ } as unknown as Event;
581
+
582
+ wrapper.vm.onDateInput(mockEvent);
583
+
584
+ expect(wrapper.vm.inputState).toBe('success');
585
+ expect(wrapper.vm.formattedDate).toBe('29.02.2024');
586
+ });
587
+
588
+ it('handles invalid leap year dates', async () => {
589
+ const wrapper = mount(DateInput);
590
+
591
+ const mockEvent = {
592
+ target: { value: '29022023' } // Feb 29, 2023 (not a leap year)
593
+ } as unknown as Event;
594
+
595
+ wrapper.vm.onDateInput(mockEvent);
596
+
597
+ expect(wrapper.vm.inputState).toBe('error');
598
+ });
599
+
600
+ it('handles edge case dates like December 31', async () => {
601
+ const wrapper = mount(DateInput);
602
+
603
+ const mockEvent = {
604
+ target: { value: '31122023' }
605
+ } as unknown as Event;
606
+
607
+ wrapper.vm.onDateInput(mockEvent);
608
+
609
+ expect(wrapper.vm.inputState).toBe('success');
610
+ expect(wrapper.vm.formattedDate).toBe('31.12.2023');
611
+ });
612
+
613
+ it('handles year 2000 (Y2K)', async () => {
614
+ const wrapper = mount(DateInput);
615
+
616
+ const mockEvent = {
617
+ target: { value: '01012000' }
618
+ } as unknown as Event;
619
+
620
+ wrapper.vm.onDateInput(mockEvent);
621
+
622
+ expect(wrapper.vm.inputState).toBe('success');
623
+ expect(wrapper.vm.formattedDate).toBe('01.01.2000');
624
+ });
625
+
626
+ it('handles various invalid dates', async () => {
627
+ const wrapper = mount(DateInput);
628
+
629
+ // Use formatted invalid dates that would actually be input by users
630
+ const invalidDates = [
631
+ '32.01.2023', // Invalid day
632
+ '01.13.2023', // Invalid month
633
+ '30.02.2023', // Invalid date (February 30th)
634
+ '00.01.2023', // Invalid day (0)
635
+ '01.00.2023' // Invalid month (0)
636
+ ];
637
+
638
+ for (const invalidDate of invalidDates) {
639
+ const mockEvent = {
640
+ target: { value: invalidDate }
641
+ } as unknown as Event;
642
+
643
+ wrapper.vm.onDateInput(mockEvent);
644
+ expect(wrapper.vm.inputState).toBe('error');
645
+ }
646
+ });
647
+ });
648
+
649
+ // Test complex scenarios
650
+ describe('Complex Scenarios', () => {
651
+ it('works with all props combined', () => {
652
+ const minDate = new Date('2023-01-01');
653
+ const maxDate = new Date('2023-12-31');
654
+
655
+ const wrapper = mount(DateInput, {
656
+ props: {
657
+ modelValue: '2023-06-15T10:30:00.000Z',
658
+ layout: 'edit-field',
659
+ minDate,
660
+ maxDate,
661
+ variant: 'filled',
662
+ placeholder: 'Enter date here',
663
+ invalidDateErrorMessage: 'Custom invalid message',
664
+ minDateErrorMessage: 'Custom min error',
665
+ maxDateErrorMessage: 'Custom max error'
666
+ }
667
+ });
668
+
669
+ expect(wrapper.vm.formattedDate).toBe('15.06.2023');
670
+ expect(wrapper.vm.layout).toBe('edit-field');
671
+ expect(wrapper.vm.variant).toBe('filled');
672
+ expect(wrapper.vm.placeholder).toBe('Enter date here');
673
+ expect(wrapper.vm.nativeMin).toBe('2023-01-01');
674
+ expect(wrapper.vm.nativeMax).toBe('2023-12-31');
675
+ expect(wrapper.find('.edit-layout').exists()).toBe(true);
676
+ });
677
+
678
+ it('handles switching between valid and invalid states', async () => {
679
+ const wrapper = mount(DateInput);
680
+
681
+ // Start with valid date
682
+ let mockEvent = {
683
+ target: { value: '15062023' }
684
+ } as unknown as Event;
685
+ wrapper.vm.onDateInput(mockEvent);
686
+ expect(wrapper.vm.inputState).toBe('success');
687
+
688
+ // Change to invalid date
689
+ mockEvent = {
690
+ target: { value: '32062023' }
691
+ } as unknown as Event;
692
+ wrapper.vm.onDateInput(mockEvent);
693
+ expect(wrapper.vm.inputState).toBe('error');
694
+
695
+ // Back to valid date
696
+ mockEvent = {
697
+ target: { value: '15062023' }
698
+ } as unknown as Event;
699
+ wrapper.vm.onDateInput(mockEvent);
700
+ expect(wrapper.vm.inputState).toBe('success');
701
+ });
702
+ });
703
703
  });