@m3ui-vue/m3ui-vue 1.6.2 → 1.8.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.
Files changed (191) hide show
  1. package/dist/API.md +1224 -28
  2. package/dist/{MColorPickerModal-NtkihoK6.js → MColorPickerModal-H8nuX0Wu.js} +3 -4
  3. package/dist/{MColorPickerModal-NtkihoK6.js.map → MColorPickerModal-H8nuX0Wu.js.map} +1 -1
  4. package/dist/MDialog-B42Mhn8W.js +331 -0
  5. package/dist/MDialog-B42Mhn8W.js.map +1 -0
  6. package/dist/{MListItem-D2cNUyzP.js → MListItem-DiOAxaN7.js} +431 -325
  7. package/dist/MListItem-DiOAxaN7.js.map +1 -0
  8. package/dist/{MLoadingIndicator-DWUj0BAB.js → MLoadingIndicator-CuTZYFFj.js} +2 -2
  9. package/dist/{MLoadingIndicator-DWUj0BAB.js.map → MLoadingIndicator-CuTZYFFj.js.map} +1 -1
  10. package/dist/{MSeekBar-C4cn9RIF.js → MSeekBar-BCDQTx2t.js} +2 -2
  11. package/dist/{MSeekBar-C4cn9RIF.js.map → MSeekBar-BCDQTx2t.js.map} +1 -1
  12. package/dist/MSegmentedButton-BXzRsg1S.js +105 -0
  13. package/dist/MSegmentedButton-BXzRsg1S.js.map +1 -0
  14. package/dist/MSignaturePad-BTqGaPXA.js +313 -0
  15. package/dist/MSignaturePad-BTqGaPXA.js.map +1 -0
  16. package/dist/MSlider-D_O8J9YH.js +739 -0
  17. package/dist/MSlider-D_O8J9YH.js.map +1 -0
  18. package/dist/{MSpinner-DZkXZJpc.js → MSpinner-UCdtSOHP.js} +2 -2
  19. package/dist/{MSpinner-DZkXZJpc.js.map → MSpinner-UCdtSOHP.js.map} +1 -1
  20. package/dist/{MTextField-CNH-byir.js → MTextField-CYk9yFvi.js} +162 -115
  21. package/dist/MTextField-CYk9yFvi.js.map +1 -0
  22. package/dist/_useFieldValidation-B0B44M_t.js +191 -0
  23. package/dist/_useFieldValidation-B0B44M_t.js.map +1 -0
  24. package/dist/api.json +1 -1
  25. package/dist/code-editor.js +184 -103
  26. package/dist/code-editor.js.map +1 -1
  27. package/dist/components/MAddressField.vue.d.ts +18 -3
  28. package/dist/components/MAppBarWithSearch.vue.d.ts +1 -1
  29. package/dist/components/MAudioRecorder.vue.d.ts +2 -2
  30. package/dist/components/MAutocomplete.vue.d.ts +22 -3
  31. package/dist/components/MCheckbox.vue.d.ts +23 -1
  32. package/dist/components/MCodeEditor.vue.d.ts +23 -1
  33. package/dist/components/MColorPicker.vue.d.ts +24 -3
  34. package/dist/components/MConfirmDialog.vue.d.ts +2 -2
  35. package/dist/components/MCountrySelect.vue.d.ts +13 -2
  36. package/dist/components/MCreditCardInput.vue.d.ts +33 -0
  37. package/dist/components/MCronField.vue.d.ts +23 -1
  38. package/dist/components/MDataTable.vue.d.ts +1 -1
  39. package/dist/components/MDatePicker.vue.d.ts +24 -3
  40. package/dist/components/MDateRangePicker.vue.d.ts +24 -3
  41. package/dist/components/MFileUpload.vue.d.ts +23 -2
  42. package/dist/components/MForm.vue.d.ts +61 -0
  43. package/dist/components/MFormBuilder.vue.d.ts +22 -0
  44. package/dist/components/MFormRenderer.vue.d.ts +151 -0
  45. package/dist/components/MJsonEditor.vue.d.ts +23 -1
  46. package/dist/components/MMapRoute.vue.d.ts +176 -0
  47. package/dist/components/MMaskField.vue.d.ts +20 -2
  48. package/dist/components/MMentionField.vue.d.ts +13 -2
  49. package/dist/components/MMultiAutocomplete.vue.d.ts +22 -3
  50. package/dist/components/MMultiSelect.vue.d.ts +22 -3
  51. package/dist/components/MNavigationRail.vue.d.ts +1 -1
  52. package/dist/components/MNotificationCenter.vue.d.ts +2 -2
  53. package/dist/components/MNumberField.vue.d.ts +20 -2
  54. package/dist/components/MPdfSigner.vue.d.ts +499 -0
  55. package/dist/components/MPdfViewer.vue.d.ts +12 -0
  56. package/dist/components/MPhoneInput.vue.d.ts +19 -4
  57. package/dist/components/MPinInput.vue.d.ts +24 -3
  58. package/dist/components/MPosKeypad.vue.d.ts +3 -3
  59. package/dist/components/MRadioGroup.vue.d.ts +23 -1
  60. package/dist/components/MRating.vue.d.ts +23 -1
  61. package/dist/components/MRichTextEditor.vue.d.ts +23 -1
  62. package/dist/components/MSearchBar.vue.d.ts +1 -1
  63. package/dist/components/MSegmentedButton.vue.d.ts +23 -2
  64. package/dist/components/MSelect.vue.d.ts +22 -3
  65. package/dist/components/MSignaturePad.vue.d.ts +19 -0
  66. package/dist/components/MSlider.vue.d.ts +23 -1
  67. package/dist/components/MSpreadsheet.vue.d.ts +137 -0
  68. package/dist/components/MStack.vue.d.ts +1 -1
  69. package/dist/components/MSwitch.vue.d.ts +23 -1
  70. package/dist/components/MTable.vue.d.ts +1 -1
  71. package/dist/components/MTagInput.vue.d.ts +20 -2
  72. package/dist/components/MText.vue.d.ts +1 -1
  73. package/dist/components/MTextField.vue.d.ts +26 -3
  74. package/dist/components/MTimePicker.vue.d.ts +24 -3
  75. package/dist/components/MTimezoneSelect.vue.d.ts +13 -2
  76. package/dist/components/MTour.vue.d.ts +2 -2
  77. package/dist/components/MTrackingTimeline.vue.d.ts +75 -0
  78. package/dist/components/MWindow.vue.d.ts +2 -2
  79. package/dist/composables/_routeGeometry.d.ts +26 -0
  80. package/dist/composables/_useFieldValidation.d.ts +91 -0
  81. package/dist/composables/mapRouting.d.ts +35 -0
  82. package/dist/composables/pdfSign.d.ts +52 -0
  83. package/dist/composables/spreadsheetFormula.d.ts +55 -0
  84. package/dist/composables/useLocale.d.ts +177 -0
  85. package/dist/composables/validation.d.ts +82 -0
  86. package/dist/draw.js +2 -2
  87. package/dist/flow.js +1 -1
  88. package/dist/gantt.js +2 -2
  89. package/dist/index.d.ts +12 -0
  90. package/dist/locales/index.js +693 -7
  91. package/dist/locales/index.js.map +1 -1
  92. package/dist/m3ui-vue.css +1 -1
  93. package/dist/m3ui.js +15507 -12417
  94. package/dist/m3ui.js.map +1 -1
  95. package/dist/map.d.ts +4 -0
  96. package/dist/map.js +1207 -745
  97. package/dist/map.js.map +1 -1
  98. package/dist/media.js +4 -4
  99. package/dist/pdf.d.ts +3 -0
  100. package/dist/pdf.js +1228 -687
  101. package/dist/pdf.js.map +1 -1
  102. package/dist/rich-text-editor.js +188 -146
  103. package/dist/rich-text-editor.js.map +1 -1
  104. package/dist/styles.css +1 -1
  105. package/dist/{useLocale-DaVSTdm0.js → useLocale-DL96OFgr.js} +99 -1
  106. package/dist/useLocale-DL96OFgr.js.map +1 -0
  107. package/package.json +5 -1
  108. package/src/__tests__/MForm.test.ts +325 -0
  109. package/src/__tests__/MFormRenderer.test.ts +157 -0
  110. package/src/__tests__/MMapRoute.test.ts +418 -0
  111. package/src/__tests__/MPdfSigner.test.ts +175 -0
  112. package/src/__tests__/MPhoneInput.test.ts +5 -2
  113. package/src/__tests__/MRichTextEditor.test.ts +2 -1
  114. package/src/__tests__/MSpreadsheet.test.ts +223 -0
  115. package/src/__tests__/MTrackingTimeline.test.ts +66 -0
  116. package/src/__tests__/_fakeMaplibre.ts +4 -1
  117. package/src/__tests__/_osrmRoutes.ts +10 -0
  118. package/src/__tests__/attrsFallthrough.test.ts +11 -0
  119. package/src/__tests__/fieldsValidation.test.ts +229 -0
  120. package/src/__tests__/spreadsheetFormula.test.ts +77 -0
  121. package/src/__tests__/ssr.test.ts +4 -0
  122. package/src/__tests__/validation.test.ts +77 -0
  123. package/src/components/MAddressField.vue +45 -8
  124. package/src/components/MAutocomplete.vue +69 -23
  125. package/src/components/MCheckbox.vue +80 -17
  126. package/src/components/MCodeEditor.vue +59 -2
  127. package/src/components/MColorPicker.vue +65 -16
  128. package/src/components/MCountrySelect.vue +17 -3
  129. package/src/components/MCreditCardInput.vue +76 -7
  130. package/src/components/MCronField.vue +60 -10
  131. package/src/components/MDatePicker.vue +65 -16
  132. package/src/components/MDateRangePicker.vue +66 -16
  133. package/src/components/MFileUpload.vue +71 -8
  134. package/src/components/MForm.vue +208 -0
  135. package/src/components/MFormBuilder.vue +417 -0
  136. package/src/components/MFormRenderer.vue +324 -0
  137. package/src/components/MJsonEditor.vue +57 -3
  138. package/src/components/MMapRoute.vue +523 -0
  139. package/src/components/MMaskField.vue +55 -13
  140. package/src/components/MMentionField.vue +17 -2
  141. package/src/components/MMultiAutocomplete.vue +70 -23
  142. package/src/components/MMultiSelect.vue +70 -23
  143. package/src/components/MNumberField.vue +58 -16
  144. package/src/components/MPdfSigner.vue +433 -0
  145. package/src/components/MPdfViewer.vue +12 -0
  146. package/src/components/MPhoneInput.vue +60 -18
  147. package/src/components/MPinInput.vue +58 -10
  148. package/src/components/MRadioGroup.vue +65 -4
  149. package/src/components/MRating.vue +62 -6
  150. package/src/components/MRichTextEditor.vue +64 -4
  151. package/src/components/MSegmentedButton.vue +59 -2
  152. package/src/components/MSelect.vue +72 -26
  153. package/src/components/MSignaturePad.vue +71 -6
  154. package/src/components/MSlider.vue +61 -10
  155. package/src/components/MSpreadsheet.vue +992 -0
  156. package/src/components/MSwitch.vue +63 -8
  157. package/src/components/MTagInput.vue +67 -25
  158. package/src/components/MTextField.vue +68 -14
  159. package/src/components/MTimePicker.vue +65 -16
  160. package/src/components/MTimezoneSelect.vue +17 -3
  161. package/src/components/MTrackingTimeline.vue +257 -0
  162. package/src/composables/_routeGeometry.ts +140 -0
  163. package/src/composables/_useFieldValidation.ts +287 -0
  164. package/src/composables/mapRouting.ts +55 -0
  165. package/src/composables/pdfSign.ts +141 -0
  166. package/src/composables/spreadsheetFormula.ts +459 -0
  167. package/src/composables/useLocale.ts +277 -0
  168. package/src/composables/validation.ts +178 -0
  169. package/src/index.ts +12 -0
  170. package/src/locales/de.ts +98 -0
  171. package/src/locales/es.ts +105 -7
  172. package/src/locales/fr.ts +98 -0
  173. package/src/locales/ja.ts +98 -0
  174. package/src/locales/ko.ts +98 -0
  175. package/src/locales/pt.ts +98 -0
  176. package/src/locales/zh.ts +98 -0
  177. package/src/map.ts +4 -0
  178. package/src/pdf.ts +3 -0
  179. package/dist/MButton-OQ4wIERQ.js +0 -171
  180. package/dist/MButton-OQ4wIERQ.js.map +0 -1
  181. package/dist/MDialog-DYMnaBlt.js +0 -167
  182. package/dist/MDialog-DYMnaBlt.js.map +0 -1
  183. package/dist/MListItem-D2cNUyzP.js.map +0 -1
  184. package/dist/MProgressBar-BWly1UKN.js +0 -179
  185. package/dist/MProgressBar-BWly1UKN.js.map +0 -1
  186. package/dist/MSegmentedButton-BEB4gXLA.js +0 -64
  187. package/dist/MSegmentedButton-BEB4gXLA.js.map +0 -1
  188. package/dist/MSlider-BIkA6DiE.js +0 -690
  189. package/dist/MSlider-BIkA6DiE.js.map +0 -1
  190. package/dist/MTextField-CNH-byir.js.map +0 -1
  191. package/dist/useLocale-DaVSTdm0.js.map +0 -1
@@ -0,0 +1,223 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { h, nextTick, ref } from 'vue'
4
+ import MSpreadsheet from '../components/MSpreadsheet.vue'
5
+ import type { SpreadsheetCell } from '../composables/spreadsheetFormula'
6
+
7
+ afterEach(() => {
8
+ document.body.innerHTML = ''
9
+ })
10
+
11
+ function setup(initial: SpreadsheetCell[][], props: Record<string, unknown> = {}) {
12
+ const cells = ref<SpreadsheetCell[][]>(initial)
13
+ const changes: unknown[] = []
14
+ const wrapper = mount(() => h(MSpreadsheet, {
15
+ modelValue: cells.value,
16
+ 'onUpdate:modelValue': (v: SpreadsheetCell[][]) => (cells.value = v),
17
+ onChange: (c: unknown) => changes.push(c),
18
+ rows: 20,
19
+ cols: 6,
20
+ ...props,
21
+ }), { attachTo: document.body })
22
+ const grid = () => wrapper.find('[role="grid"]')
23
+ const cell = (r: number, c: number) => wrapper.find(`[data-row="${r}"][data-col="${c}"]`)
24
+ const text = (r: number, c: number) => cell(r, c).find('span').text()
25
+ const key = async (k: string, opts: Record<string, unknown> = {}) => { await grid().trigger('keydown', { key: k, ...opts }); await nextTick() }
26
+ const click = async (r: number, c: number, opts: Record<string, unknown> = {}) => {
27
+ cell(r, c).element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0, pointerType: 'mouse', ...opts }))
28
+ window.dispatchEvent(new PointerEvent('pointerup'))
29
+ await nextTick()
30
+ }
31
+ const name = () => wrapper.find('[role="status"]').text()
32
+ return { wrapper, cells, changes, grid, cell, text, key, click, name }
33
+ }
34
+
35
+ function clipboardEvent(type: string, text = '') {
36
+ const data = new Map<string, string>([['text/plain', text]])
37
+ const e = new Event(type, { bubbles: true, cancelable: true }) as ClipboardEvent
38
+ Object.defineProperty(e, 'clipboardData', { value: { getData: (t: string) => data.get(t) ?? '', setData: (t: string, v: string) => data.set(t, v) } })
39
+ return { e, data }
40
+ }
41
+
42
+ describe('MSpreadsheet', () => {
43
+ it('shows values and works out formulas; numbers right-aligned, errors in the error color', () => {
44
+ const { text, cell } = setup([[1, 2, '=A1+B1', '=1/0', 'hi']])
45
+ expect(text(0, 2)).toBe('3')
46
+ expect(cell(0, 0).classes()).toContain('text-right')
47
+ expect(text(0, 3)).toBe('#DIV/0!')
48
+ expect(cell(0, 3).classes()).toContain('text-error')
49
+ expect(cell(0, 4).classes()).toContain('text-left')
50
+ })
51
+
52
+ it('typing replaces the cell; Enter stores it (a number as a number) and moves down', async () => {
53
+ const { key, cells, wrapper, name, changes } = setup([[5]])
54
+ ;(wrapper.find('[role="grid"]').element as HTMLElement).focus()
55
+ await key('4')
56
+ const input = wrapper.find('input[spellcheck="false"]:not([aria-label])')
57
+ expect((input.element as HTMLInputElement).value).toBe('4')
58
+ await input.setValue('42')
59
+ await input.trigger('keydown', { key: 'Enter' })
60
+ expect(cells.value[0]![0]).toBe(42)
61
+ expect(name()).toBe('A2')
62
+ expect(changes[0]).toEqual([{ row: 0, col: 0, value: 42, oldValue: 5 }])
63
+ })
64
+
65
+ it('a formula typed in recomputes the cells that read it', async () => {
66
+ const { key, wrapper, text, click } = setup([[1, 2, '=A1*B1']])
67
+ await click(0, 0)
68
+ await key('7')
69
+ const input = wrapper.find('input[spellcheck="false"]:not([aria-label])')
70
+ await input.trigger('keydown', { key: 'Enter' })
71
+ expect(text(0, 2)).toBe('14')
72
+ })
73
+
74
+ it('Escape cancels an edit; F2 edits keeping the contents', async () => {
75
+ const { key, wrapper, cells, click } = setup([['abc']])
76
+ await click(0, 0)
77
+ await key('F2')
78
+ const input = () => wrapper.find('input[spellcheck="false"]:not([aria-label])')
79
+ expect((input().element as HTMLInputElement).value).toBe('abc')
80
+ await input().setValue('zzz')
81
+ await input().trigger('keydown', { key: 'Escape' })
82
+ expect(cells.value[0]![0]).toBe('abc')
83
+ expect(input().exists()).toBe(false)
84
+ })
85
+
86
+ it('arrows move, Shift+arrows extend the range, Delete clears it', async () => {
87
+ const { key, click, name, cells } = setup([[1, 2], [3, 4]])
88
+ await click(0, 0)
89
+ await key('ArrowRight')
90
+ expect(name()).toBe('B1')
91
+ await key('ArrowLeft')
92
+ await key('ArrowDown', { shiftKey: true })
93
+ await key('ArrowRight', { shiftKey: true })
94
+ expect(name()).toBe('A1:B2')
95
+ await key('Delete')
96
+ expect(cells.value.flat().every((v) => v == null)).toBe(true)
97
+ })
98
+
99
+ it('Ctrl+Z undoes and Ctrl+Shift+Z redoes', async () => {
100
+ const { key, click, cells } = setup([[1]])
101
+ await click(0, 0)
102
+ await key('Delete')
103
+ expect(cells.value[0]![0]).toBeNull()
104
+ await key('z', { ctrlKey: true })
105
+ expect(cells.value[0]![0]).toBe(1)
106
+ await key('z', { ctrlKey: true, shiftKey: true })
107
+ expect(cells.value[0]![0]).toBeNull()
108
+ })
109
+
110
+ it('copies the selection as tab-separated values and pastes Excel text, quoted cells included', async () => {
111
+ const { click, grid, cells } = setup([[1, '=A1*2'], ['a', 'b']])
112
+ await click(0, 0)
113
+ await click(1, 1, { shiftKey: true })
114
+ ;(grid().element as HTMLElement).focus()
115
+ const copy = clipboardEvent('copy')
116
+ document.dispatchEvent(copy.e)
117
+ expect(copy.data.get('text/plain')).toBe('1\t2\na\tb')
118
+ await click(4, 0)
119
+ ;(grid().element as HTMLElement).focus()
120
+ document.dispatchEvent(clipboardEvent('paste', 'x\t"two\nlines"\r\n3\t4.5\r\n').e)
121
+ await nextTick()
122
+ expect(cells.value[4]).toEqual(['x', 'two\nlines'])
123
+ expect(cells.value[5]).toEqual([3, 4.5])
124
+ })
125
+
126
+ it('pasting its own copy moves the formulas references', async () => {
127
+ const { click, grid, cells } = setup([[1, '=A1*2'], [5]])
128
+ await click(0, 1)
129
+ ;(grid().element as HTMLElement).focus()
130
+ const copy = clipboardEvent('copy')
131
+ document.dispatchEvent(copy.e)
132
+ await click(1, 1)
133
+ ;(grid().element as HTMLElement).focus()
134
+ document.dispatchEvent(clipboardEvent('paste', copy.data.get('text/plain')).e)
135
+ await nextTick()
136
+ expect(cells.value[1]![1]).toBe('=A2*2')
137
+ })
138
+
139
+ it('the fill handle continues a series, repeats text, counts "Item 1" on and moves formulas', async () => {
140
+ const { wrapper, click, cells } = setup([[1, 'x', 'Item 1', '=A1*10'], [2]])
141
+ const grid = wrapper.find('[role="grid"]').element as HTMLElement
142
+ grid.getBoundingClientRect = () => ({ left: 0, top: 0, right: 600, bottom: 400, width: 600, height: 400, x: 0, y: 0, toJSON() {} })
143
+ // Select A1:A2 and drag the handle down to row 5
144
+ await click(0, 0)
145
+ await click(1, 0, { shiftKey: true })
146
+ const handle = () => wrapper.find('.m3-spreadsheet-fill').element
147
+ const rowHeader = 44
148
+ const at = (row: number, col: number) => ({ clientX: rowHeader + col * 100 + 50, clientY: 32 + row * 32 + 16 })
149
+ handle().dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }))
150
+ window.dispatchEvent(new PointerEvent('pointermove', at(4, 0)))
151
+ window.dispatchEvent(new PointerEvent('pointerup'))
152
+ await nextTick()
153
+ expect(cells.value.slice(0, 5).map((r) => r[0])).toEqual([1, 2, 3, 4, 5])
154
+ // B1:D1 down to row 3
155
+ await click(0, 1)
156
+ await click(0, 3, { shiftKey: true })
157
+ handle().dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }))
158
+ window.dispatchEvent(new PointerEvent('pointermove', at(2, 2)))
159
+ window.dispatchEvent(new PointerEvent('pointerup'))
160
+ await nextTick()
161
+ expect(cells.value.slice(0, 3).map((r) => r[1])).toEqual(['x', 'x', 'x'])
162
+ expect(cells.value.slice(0, 3).map((r) => r[2])).toEqual(['Item 1', 'Item 2', 'Item 3'])
163
+ expect(cells.value.slice(0, 3).map((r) => r[3])).toEqual(['=A1*10', '=A2*10', '=A3*10'])
164
+ })
165
+
166
+ it('readonly: nothing is written', async () => {
167
+ const { key, click, cells, wrapper } = setup([[1]], { readonly: true })
168
+ await click(0, 0)
169
+ await key('5')
170
+ await key('Delete')
171
+ expect(cells.value[0]![0]).toBe(1)
172
+ expect(wrapper.find('[role="grid"]').attributes('aria-readonly')).toBe('true')
173
+ })
174
+
175
+ it('renders only the rows in view, plus frozen ones that stick', async () => {
176
+ const { wrapper } = setup([], { rows: 1000, frozenRows: 1, frozenColumns: 1 })
177
+ const rows = wrapper.findAll('[role="row"]')
178
+ expect(rows.length).toBeLessThan(40)
179
+ const frozenCell = wrapper.find('[data-row="5"][data-col="0"]')
180
+ expect((frozenCell.element as HTMLElement).style.position).toBe('sticky')
181
+ expect(wrapper.find('[data-row="0"][data-col="2"]').exists()).toBe(true)
182
+ })
183
+
184
+ it('clicking a cell while typing a formula inserts its reference', async () => {
185
+ const { key, click, wrapper, cells } = setup([[3, 4]])
186
+ await click(0, 2)
187
+ await key('=')
188
+ const input = () => wrapper.find('input[spellcheck="false"]:not([aria-label])')
189
+ await input().setValue('=SUM(')
190
+ await click(0, 0)
191
+ expect((input().element as HTMLInputElement).value).toBe('=SUM(A1')
192
+ await input().setValue('=SUM(A1,B1)')
193
+ await input().trigger('keydown', { key: 'Enter' })
194
+ expect(cells.value[0]![2]).toBe('=SUM(A1,B1)')
195
+ })
196
+
197
+ it('the formula bar shows the raw contents and edits the cell', async () => {
198
+ const { click, wrapper, cells } = setup([['=1+1']])
199
+ await click(0, 0)
200
+ const bar = wrapper.find('input[aria-label="Formula"]')
201
+ expect((bar.element as HTMLInputElement).value).toBe('=1+1')
202
+ await bar.trigger('focus')
203
+ await bar.setValue('=2+2')
204
+ await bar.trigger('keydown', { key: 'Enter' })
205
+ expect(cells.value[0]![0]).toBe('=2+2')
206
+ })
207
+
208
+ it('column header click selects the column; resizing emits widths', async () => {
209
+ const widths: number[][] = []
210
+ const { wrapper, name } = setup([], { 'onUpdate:columnWidths': (w: number[]) => widths.push(w) })
211
+ const header = wrapper.findAll('[role="columnheader"]')[2]!
212
+ header.element.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, button: 0 }))
213
+ await nextTick()
214
+ expect(name()).toBe('B1:B20')
215
+ const grip = header.find('span').element
216
+ grip.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, clientX: 100 }))
217
+ grip.dispatchEvent(new PointerEvent('pointermove', { bubbles: true, clientX: 160 }))
218
+ grip.dispatchEvent(new PointerEvent('pointerup', { bubbles: true }))
219
+ expect(widths.at(-1)![1]).toBe(160)
220
+ })
221
+
222
+ vi.restoreAllMocks()
223
+ })
@@ -0,0 +1,66 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
+ import { flushPromises, mount } from '@vue/test-utils'
3
+ import MTrackingTimeline from '../components/MTrackingTimeline.vue'
4
+ import { defaultLocale } from '../composables/useLocale'
5
+
6
+ const steps = [
7
+ { label: 'Order placed', icon: 'receipt_long', time: '2026-11-27T14:00:00' },
8
+ { label: 'Preparing', icon: 'skillet', time: '2026-11-27T14:05:00' },
9
+ { label: 'On the way', icon: 'two_wheeler' },
10
+ { label: 'Delivered', icon: 'home', time: '2026-11-27T14:41:00' },
11
+ ]
12
+
13
+ beforeEach(() => {
14
+ vi.useFakeTimers()
15
+ vi.setSystemTime(new Date('2026-11-27T14:20:00'))
16
+ document.documentElement.lang = 'en'
17
+ })
18
+ afterEach(() => vi.useRealTimers())
19
+
20
+ const legs = (w: ReturnType<typeof mount>) => w.findAll('li[aria-hidden="true"] > span').map((s) => (s.element as HTMLElement).style.width)
21
+
22
+ describe('MTrackingTimeline', () => {
23
+ it('titles the current stage, marks it, and fills the legs up to it', () => {
24
+ const w = mount(MTrackingTimeline, { props: { steps, current: 2, stepProgress: 0.4 } })
25
+ expect(w.find('h3').text()).toBe('On the way')
26
+ expect(w.find('[aria-current="step"]').attributes('title')).toBe('On the way')
27
+ expect(legs(w)).toEqual(['100%', '100%', '40%'])
28
+ })
29
+
30
+ it('shows the minutes left and the arrival time, and keeps counting down', async () => {
31
+ const w = mount(MTrackingTimeline, { props: { steps, current: 2, eta: new Date('2026-11-27T14:32:00') } })
32
+ expect(w.text()).toContain('12 min')
33
+ expect(w.text()).toContain('Arrives 2:32')
34
+ vi.advanceTimersByTime(11 * 60_000)
35
+ await flushPromises()
36
+ expect(w.text()).toContain(defaultLocale.trackingArrivingNow)
37
+ })
38
+
39
+ it('all done: Delivered with the last stage time, every leg full, no current step', () => {
40
+ const w = mount(MTrackingTimeline, { props: { steps, current: 3, eta: new Date('2026-11-27T14:32:00') } })
41
+ expect(w.text()).toContain('Delivered · 2:41')
42
+ expect(w.text()).not.toContain('min')
43
+ expect(legs(w)).toEqual(['100%', '100%', '100%'])
44
+ expect(w.find('[aria-current="step"]').exists()).toBe(false)
45
+ })
46
+
47
+ it('delayed and canceled states', () => {
48
+ const late = mount(MTrackingTimeline, { props: { steps, current: 1, status: 'delayed' } })
49
+ expect(late.text()).toContain(defaultLocale.trackingDelayed)
50
+ expect(late.find('[aria-current="step"] span.relative').classes()).toContain('bg-tertiary-container')
51
+ const off = mount(MTrackingTimeline, { props: { steps, current: 1, status: 'canceled', stepProgress: 0.5 } })
52
+ expect(off.text()).toContain(defaultLocale.trackingCanceled)
53
+ expect(legs(off)[1]).toBe('0%') // nothing moves once canceled
54
+ expect(off.find('[aria-current="step"]').text()).toContain('close')
55
+ })
56
+
57
+ it('opens the stages with their times (v-model:expanded)', async () => {
58
+ const w = mount(MTrackingTimeline, { props: { steps, current: 2 } })
59
+ const button = w.find('button[aria-expanded]')
60
+ expect(button.attributes('aria-expanded')).toBe('false')
61
+ await button.trigger('click')
62
+ expect(w.emitted('update:expanded')![0]).toEqual([true])
63
+ expect(button.attributes('aria-expanded')).toBe('true')
64
+ expect(w.text()).toContain('2:05')
65
+ })
66
+ })
@@ -141,7 +141,10 @@ export class FakeMarker extends Evented {
141
141
  setPopup(p: FakePopup) { this.popup = p; return this }
142
142
  getPopup() { return this.popup }
143
143
  setDraggable() { return this }
144
- setRotation() { return this }
144
+ rotation = 0
145
+ rotationAlignment: unknown
146
+ setRotation(r = 0) { this.rotation = r; return this }
147
+ setRotationAlignment(a: unknown) { this.rotationAlignment = a; return this }
145
148
  setOffset() { return this }
146
149
  remove() { this.map = undefined; return this }
147
150
  }
@@ -0,0 +1,10 @@
1
+ // Real routes in Córdoba from the OSRM demo server (car profile), kept here so tests need no network.
2
+ // roundabout: Patio Olmos → Parque Sarmiento through Plaza España's roundabout; costanera: along the river (curves);
3
+ // roundTrip: warehouse → drop → warehouse, back partly by other streets (one-way streets)
4
+
5
+ export const roundabout: [number, number][] = [[-64.189009,-31.419963],[-64.18928,-31.419934],[-64.189473,-31.419896],[-64.189832,-31.419802],[-64.189976,-31.419802],[-64.190263,-31.419718],[-64.191479,-31.419398],[-64.19279,-31.419035],[-64.194047,-31.418698],[-64.194079,-31.418776],[-64.192824,-31.419115],[-64.191511,-31.419475],[-64.190294,-31.419806],[-64.190007,-31.419899],[-64.189885,-31.419937],[-64.189615,-31.420014],[-64.189404,-31.420085],[-64.18918,-31.420189],[-64.189123,-31.420212],[-64.189101,-31.420221],[-64.188948,-31.420282],[-64.18891,-31.4203],[-64.188869,-31.420313],[-64.188847,-31.420318],[-64.188829,-31.420322],[-64.188734,-31.420338],[-64.188686,-31.420476],[-64.188614,-31.420637],[-64.188602,-31.420666],[-64.188216,-31.421509],[-64.188008,-31.421909],[-64.187455,-31.423057],[-64.187282,-31.423421],[-64.187225,-31.42354],[-64.187179,-31.423635],[-64.186727,-31.424578],[-64.18644,-31.425174],[-64.186032,-31.426085],[-64.186005,-31.426146],[-64.185991,-31.426177],[-64.185638,-31.426928],[-64.185591,-31.427033],[-64.185475,-31.427292],[-64.185452,-31.42734],[-64.185317,-31.427621],[-64.185278,-31.427701],[-64.185251,-31.427773],[-64.18524,-31.427801],[-64.185211,-31.427886],[-64.185203,-31.42792],[-64.185197,-31.427969],[-64.185195,-31.427999],[-64.185198,-31.42802],[-64.185201,-31.428042],[-64.185215,-31.428094],[-64.18523,-31.428147],[-64.185282,-31.428181],[-64.18533,-31.428221],[-64.185372,-31.428265],[-64.185414,-31.42832],[-64.185448,-31.42838],[-64.185473,-31.428443],[-64.185488,-31.428508],[-64.185494,-31.428577],[-64.185489,-31.428647],[-64.185473,-31.428715],[-64.185452,-31.428769],[-64.185425,-31.42882],[-64.185392,-31.428868],[-64.185374,-31.42889],[-64.185353,-31.428914],[-64.18529,-31.42897],[-64.185242,-31.429003],[-64.185187,-31.429034],[-64.185128,-31.429059],[-64.185067,-31.429079],[-64.185004,-31.429094],[-64.184939,-31.429102],[-64.184873,-31.429105],[-64.18483,-31.429103],[-64.184758,-31.429095],[-64.184688,-31.42908],[-64.18462,-31.429055],[-64.184557,-31.429028],[-64.184479,-31.428983],[-64.184455,-31.428963],[-64.184435,-31.428946],[-64.184419,-31.428931],[-64.184363,-31.428928],[-64.184253,-31.428923],[-64.184208,-31.42892],[-64.184162,-31.428916],[-64.184097,-31.428914],[-64.184004,-31.428911],[-64.183927,-31.428913],[-64.183864,-31.428916],[-64.183711,-31.428936],[-64.183639,-31.428944],[-64.183507,-31.428957],[-64.183383,-31.428974],[-64.183269,-31.428993],[-64.183175,-31.429012],[-64.183069,-31.429035],[-64.18294,-31.429071],[-64.182833,-31.4291],[-64.182725,-31.42914],[-64.182592,-31.429191],[-64.182491,-31.429238],[-64.182377,-31.429312],[-64.182195,-31.429436],[-64.181951,-31.429592],[-64.181533,-31.429848],[-64.181431,-31.429908],[-64.181276,-31.429997],[-64.181188,-31.430046],[-64.181172,-31.430068],[-64.18115,-31.430085],[-64.18117,-31.430154],[-64.18141,-31.430423],[-64.181495,-31.430531],[-64.181555,-31.430629],[-64.181593,-31.430708],[-64.181607,-31.430751],[-64.181642,-31.430859],[-64.181661,-31.430952],[-64.181661,-31.430971],[-64.18166,-31.43104],[-64.181639,-31.431129],[-64.181621,-31.43119],[-64.181576,-31.431335],[-64.181528,-31.43147],[-64.181455,-31.431636],[-64.181403,-31.431722],[-64.181278,-31.431878],[-64.181169,-31.43198],[-64.18102,-31.432087],[-64.180879,-31.432183],[-64.180626,-31.432314],[-64.180447,-31.432389],[-64.18024,-31.43247],[-64.180053,-31.43253],[-64.17994,-31.432563],[-64.179282,-31.432706],[-64.179092,-31.432741],[-64.178896,-31.432771],[-64.178703,-31.43279],[-64.178303,-31.432803],[-64.178034,-31.432803],[-64.177837,-31.43279],[-64.177509,-31.432761],[-64.177179,-31.432748],[-64.176902,-31.432756],[-64.176674,-31.432783],[-64.176393,-31.432837],[-64.176225,-31.432876],[-64.175955,-31.432965],[-64.175693,-31.433072],[-64.175584,-31.433129],[-64.175394,-31.433241]]
6
+ export const roundaboutMeta = { distance: 3339.7, duration: 381.6 }
7
+ export const costanera: [number, number][] = [[-64.202828,-31.4046],[-64.202603,-31.404671],[-64.202589,-31.404677],[-64.202577,-31.404686],[-64.202508,-31.404762],[-64.202496,-31.404772],[-64.20248,-31.404778],[-64.202397,-31.404802],[-64.202219,-31.404854],[-64.202432,-31.40537],[-64.201194,-31.405757],[-64.201034,-31.405806],[-64.200518,-31.405962],[-64.199872,-31.406155],[-64.199562,-31.405373],[-64.199533,-31.4053],[-64.199504,-31.405233],[-64.199479,-31.40517],[-64.199223,-31.404517],[-64.199214,-31.404496],[-64.199193,-31.404448],[-64.19869,-31.404604],[-64.198191,-31.404761],[-64.198105,-31.404792],[-64.197982,-31.404852],[-64.197905,-31.404894],[-64.197753,-31.404977],[-64.197596,-31.405024],[-64.196823,-31.405211],[-64.195498,-31.40545],[-64.194805,-31.405555],[-64.194195,-31.405628],[-64.193599,-31.405724],[-64.193059,-31.4058],[-64.192812,-31.405821],[-64.192707,-31.405825],[-64.192555,-31.405818],[-64.192494,-31.405757],[-64.192455,-31.405708],[-64.192433,-31.405662],[-64.192426,-31.405597],[-64.192409,-31.40535],[-64.1912,-31.405405],[-64.190023,-31.405451],[-64.189028,-31.405504],[-64.188867,-31.405514],[-64.187857,-31.405569],[-64.187738,-31.405576],[-64.187192,-31.405617],[-64.186937,-31.405566],[-64.186561,-31.405492],[-64.185362,-31.405221],[-64.184239,-31.404954],[-64.184038,-31.404907],[-64.183041,-31.404693],[-64.182941,-31.404705],[-64.182861,-31.404723],[-64.182794,-31.404759],[-64.182701,-31.404839],[-64.182719,-31.40491],[-64.182707,-31.405138],[-64.182699,-31.405207],[-64.182685,-31.405265],[-64.182671,-31.405309],[-64.182649,-31.405339],[-64.182626,-31.405361],[-64.182595,-31.405383],[-64.18255,-31.405402],[-64.182506,-31.405415],[-64.182456,-31.405424],[-64.182382,-31.405421],[-64.181508,-31.405299],[-64.180836,-31.405253],[-64.18055,-31.405252],[-64.180483,-31.405258],[-64.180357,-31.405268],[-64.180142,-31.405304],[-64.179772,-31.40539],[-64.179564,-31.405456],[-64.177419,-31.406158],[-64.177342,-31.406179],[-64.177066,-31.406279],[-64.176988,-31.406308],[-64.176883,-31.406354],[-64.176461,-31.406541],[-64.176066,-31.406755],[-64.175749,-31.40695],[-64.175465,-31.407153],[-64.175403,-31.407211],[-64.175313,-31.407296],[-64.175097,-31.40754],[-64.174983,-31.407682],[-64.174907,-31.407796],[-64.174855,-31.40791],[-64.174827,-31.408021],[-64.174806,-31.408117],[-64.17477,-31.408307],[-64.174751,-31.408412],[-64.174523,-31.409171],[-64.17449,-31.409332],[-64.174471,-31.409471],[-64.174464,-31.40961],[-64.174472,-31.411496],[-64.17411,-31.411446],[-64.173911,-31.41141],[-64.173821,-31.411377],[-64.173746,-31.411337],[-64.173665,-31.411291],[-64.173613,-31.411244],[-64.173515,-31.411128],[-64.173252,-31.4108],[-64.173195,-31.410704],[-64.173239,-31.411119],[-64.172318,-31.410868],[-64.171142,-31.410542],[-64.170737,-31.411583],[-64.170534,-31.412141]]
8
+ export const costaneraMeta = { distance: 4136, duration: 479.3 }
9
+ export const roundTrip: [number, number][] = [[-64.198944,-31.412861],[-64.199314,-31.412753],[-64.199727,-31.413883],[-64.199254,-31.414026],[-64.198305,-31.414312],[-64.19696,-31.414729],[-64.19736,-31.415864],[-64.19773,-31.416882],[-64.197979,-31.417614],[-64.198006,-31.417685],[-64.197377,-31.417859],[-64.196695,-31.418052],[-64.195918,-31.418261],[-64.195368,-31.418412],[-64.194652,-31.418615],[-64.194079,-31.418776],[-64.192824,-31.419115],[-64.191511,-31.419475],[-64.190294,-31.419806],[-64.190007,-31.419899],[-64.189885,-31.419937],[-64.189615,-31.420014],[-64.189404,-31.420085],[-64.18918,-31.420189],[-64.189123,-31.420212],[-64.189101,-31.420221],[-64.188948,-31.420282],[-64.18891,-31.4203],[-64.188869,-31.420313],[-64.188847,-31.420318],[-64.188829,-31.420322],[-64.188734,-31.420338],[-64.188686,-31.420476],[-64.188614,-31.420637],[-64.188602,-31.420666],[-64.188216,-31.421509],[-64.188139,-31.421536],[-64.187971,-31.421596],[-64.187883,-31.421621],[-64.186582,-31.422025],[-64.185253,-31.422438],[-64.185197,-31.422455],[-64.183898,-31.422858],[-64.183052,-31.423121],[-64.182631,-31.423252],[-64.182244,-31.42231],[-64.182096,-31.421946],[-64.182055,-31.421848],[-64.183332,-31.421513],[-64.183646,-31.421431],[-64.184303,-31.421259],[-64.184705,-31.421154],[-64.186053,-31.420801],[-64.186264,-31.420749],[-64.187394,-31.420469],[-64.187439,-31.420456],[-64.187877,-31.420332],[-64.188038,-31.420286],[-64.188169,-31.420245],[-64.188208,-31.420233],[-64.188297,-31.420206],[-64.188431,-31.42015],[-64.188553,-31.4201],[-64.188617,-31.420073],[-64.188664,-31.420053],[-64.188709,-31.420032],[-64.188747,-31.420017],[-64.188791,-31.420004],[-64.188816,-31.419999],[-64.188834,-31.419994],[-64.188873,-31.419986],[-64.188977,-31.419966],[-64.18928,-31.419934],[-64.189473,-31.419896],[-64.189832,-31.419802],[-64.189976,-31.419802],[-64.190263,-31.419718],[-64.191479,-31.419398],[-64.19279,-31.419035],[-64.194047,-31.418698],[-64.195343,-31.418339],[-64.195893,-31.418187],[-64.196665,-31.417972],[-64.197822,-31.417657],[-64.197979,-31.417614],[-64.198433,-31.417486],[-64.198706,-31.4174],[-64.199394,-31.417167],[-64.199011,-31.416135],[-64.198747,-31.415458],[-64.198615,-31.41512],[-64.198305,-31.414312],[-64.197897,-31.413168],[-64.198944,-31.412861]]
10
+ export const roundTripMeta = { distance: 4890.8, duration: 627.9 }
@@ -20,6 +20,11 @@ import MDialog from '../components/MDialog.vue'
20
20
  import MOverlay from '../components/MOverlay.vue'
21
21
  import MAddressField from '../components/MAddressField.vue'
22
22
  import MMentionField from '../components/MMentionField.vue'
23
+ import MRating from '../components/MRating.vue'
24
+ import MSegmentedButton from '../components/MSegmentedButton.vue'
25
+ import MSignaturePad from '../components/MSignaturePad.vue'
26
+ import MRichTextEditor from '../components/MRichTextEditor.vue'
27
+ import MCodeEditor from '../components/MCodeEditor.vue'
23
28
 
24
29
  // These components render more than one root node (an element plus a Teleport, a v-if/v-show
25
30
  // pair, a comment before the root...), which makes Vue drop a consumer's class/attrs silently.
@@ -54,6 +59,12 @@ const cases: [name: string, component: Component, props: Record<string, unknown>
54
59
  ['MDialog (fullscreen)', MDialog, { modelValue: true, title: 'T', fullscreen: true }, 'DIV'],
55
60
  // A Teleport root: the attrs go on the content layer, over the scrim
56
61
  ['MOverlay', MOverlay, { modelValue: true }, 'DIV'],
62
+ // The control plus its validation message: the attrs go on the control
63
+ ['MRating', MRating, { modelValue: 3, error: 'E' }, 'DIV'],
64
+ ['MSegmentedButton', MSegmentedButton, { modelValue: 'a', options: [{ value: 'a', label: 'A' }], error: 'E' }, 'DIV'],
65
+ ['MSignaturePad', MSignaturePad, { error: 'E' }, 'DIV'],
66
+ ['MRichTextEditor', MRichTextEditor, { modelValue: '', error: 'E' }, 'DIV'],
67
+ ['MCodeEditor', MCodeEditor, { modelValue: '', error: 'E' }, 'DIV'],
57
68
  ]
58
69
 
59
70
  describe('consumer attrs reach multi-root components', () => {
@@ -0,0 +1,229 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+ import { flushPromises, mount } from '@vue/test-utils'
3
+ import { h, type Component } from 'vue'
4
+ import MForm from '../components/MForm.vue'
5
+ import MNumberField from '../components/MNumberField.vue'
6
+ import MMaskField from '../components/MMaskField.vue'
7
+ import MTagInput from '../components/MTagInput.vue'
8
+ import MPinInput from '../components/MPinInput.vue'
9
+ import MSelect from '../components/MSelect.vue'
10
+ import MMultiSelect from '../components/MMultiSelect.vue'
11
+ import MAutocomplete from '../components/MAutocomplete.vue'
12
+ import MMultiAutocomplete from '../components/MMultiAutocomplete.vue'
13
+ import MDatePicker from '../components/MDatePicker.vue'
14
+ import MDateRangePicker from '../components/MDateRangePicker.vue'
15
+ import MTimePicker from '../components/MTimePicker.vue'
16
+ import MColorPicker from '../components/MColorPicker.vue'
17
+ import MPhoneInput from '../components/MPhoneInput.vue'
18
+ import MCountrySelect from '../components/MCountrySelect.vue'
19
+ import MTimezoneSelect from '../components/MTimezoneSelect.vue'
20
+ import MMentionField from '../components/MMentionField.vue'
21
+ import MAddressField from '../components/MAddressField.vue'
22
+ import { defaultLocale } from '../composables/useLocale'
23
+
24
+ const options = [{ value: 'a', label: 'A' }, { value: 'b', label: 'B' }]
25
+
26
+ /** Every form field of phase 2, empty, with what it needs to mount */
27
+ const cases: [string, Component, Record<string, unknown>][] = [
28
+ ['MNumberField', MNumberField, { modelValue: null }],
29
+ ['MMaskField', MMaskField, { modelValue: '', mask: '###' }],
30
+ ['MTagInput', MTagInput, { modelValue: [] }],
31
+ ['MPinInput', MPinInput, { modelValue: '12', length: 4 }], // partly filled counts as empty
32
+ ['MSelect', MSelect, { modelValue: undefined, options }],
33
+ ['MMultiSelect', MMultiSelect, { modelValue: [], options }],
34
+ ['MAutocomplete', MAutocomplete, { modelValue: undefined, options }],
35
+ ['MMultiAutocomplete', MMultiAutocomplete, { modelValue: [], options }],
36
+ ['MDatePicker', MDatePicker, { modelValue: null }],
37
+ ['MDateRangePicker', MDateRangePicker, { modelValue: { start: '2026-01-01', end: null } }], // half a range is empty
38
+ ['MTimePicker', MTimePicker, { modelValue: null }],
39
+ ['MColorPicker', MColorPicker, { modelValue: '' }],
40
+ ['MPhoneInput', MPhoneInput, { modelValue: null, country: 'AR' }],
41
+ ['MCountrySelect', MCountrySelect, { modelValue: null }],
42
+ ['MTimezoneSelect', MTimezoneSelect, { modelValue: null }],
43
+ ['MMentionField', MMentionField, { modelValue: '', sources: [] }],
44
+ ['MAddressField', MAddressField, { modelValue: null }],
45
+ ]
46
+
47
+ async function submit(field: Component, props: Record<string, unknown>) {
48
+ const onSubmit = vi.fn()
49
+ const onInvalid = vi.fn()
50
+ const w = mount(() => h(MForm, { onSubmit, onInvalid }, () => h(field, { label: 'Field', name: 'f', ...props })), { attachTo: document.body })
51
+ await flushPromises()
52
+ await w.find('form').trigger('submit')
53
+ await flushPromises()
54
+ return { w, onSubmit, onInvalid }
55
+ }
56
+
57
+ describe('form fields in an MForm', () => {
58
+ it.each(cases)('%s: required blocks submit, shows the message and takes the focus', async (_, field, props) => {
59
+ const { w, onSubmit, onInvalid } = await submit(field, { ...props, required: true })
60
+ expect(onSubmit).not.toHaveBeenCalled()
61
+ expect(onInvalid).toHaveBeenCalledWith({ f: defaultLocale.validationRequired })
62
+ expect(w.findAll('[role="alert"]').map((p) => p.text())).toEqual([defaultLocale.validationRequired])
63
+ expect(w.element.contains(document.activeElement)).toBe(true)
64
+ w.unmount()
65
+ })
66
+
67
+ it.each(cases)('%s: a string error is the message', async (_, field, props) => {
68
+ const w = mount(field, { props: { label: 'Field', ...props, error: 'From the server' } })
69
+ await flushPromises()
70
+ expect(w.findAll('[role="alert"]').map((p) => p.text())).toEqual(['From the server'])
71
+ })
72
+
73
+ it.each(cases)('%s: required outside an MForm keeps quiet', async (_, field, props) => {
74
+ const w = mount(field, { props: { label: 'Field', ...props, required: true }, attachTo: document.body })
75
+ await flushPromises()
76
+ w.element.dispatchEvent?.(new FocusEvent('focusout', { bubbles: true }))
77
+ await new Promise((r) => setTimeout(r))
78
+ await flushPromises()
79
+ expect(w.findAll('[role="alert"]')).toHaveLength(0)
80
+ w.unmount()
81
+ })
82
+ })
83
+
84
+ describe('leaving a field', () => {
85
+ it("MNumberField: the stepper buttons aren't leaving it", async () => {
86
+ const onBlur = vi.fn()
87
+ const w = mount(MNumberField, { props: { label: 'Qty', modelValue: null, rules: [() => 'Bad'], onBlur }, attachTo: document.body })
88
+ const input = w.find('input').element as HTMLInputElement
89
+ const plus = w.findAll('button')[1].element as HTMLButtonElement
90
+ input.focus()
91
+ plus.focus() // focus moves inside the field
92
+ await new Promise((r) => setTimeout(r))
93
+ await flushPromises()
94
+ expect(onBlur).not.toHaveBeenCalled()
95
+ plus.blur() // now it really leaves
96
+ await new Promise((r) => setTimeout(r))
97
+ await flushPromises()
98
+ expect(onBlur).toHaveBeenCalledTimes(1)
99
+ expect(w.find('[role="alert"]').text()).toBe('Bad')
100
+ w.unmount()
101
+ })
102
+
103
+ it("MDatePicker: opening the calendar isn't leaving it; closing it with focus outside is", async () => {
104
+ const onBlur = vi.fn()
105
+ const w = mount(MDatePicker, { props: { label: 'Date', modelValue: null, rules: [() => 'Pick one'], onBlur }, attachTo: document.body })
106
+ const trigger = w.find('button')
107
+ trigger.element.focus()
108
+ await trigger.trigger('click') // opens the teleported panel
109
+ ;(document.activeElement as HTMLElement | null)?.blur()
110
+ w.element.dispatchEvent(new FocusEvent('focusout', { bubbles: true }))
111
+ await new Promise((r) => setTimeout(r))
112
+ expect(onBlur).not.toHaveBeenCalled()
113
+ document.body.dispatchEvent(new MouseEvent('mousedown', { bubbles: true })) // a click outside closes it
114
+ await flushPromises()
115
+ await new Promise((r) => setTimeout(r))
116
+ await flushPromises()
117
+ expect(onBlur).toHaveBeenCalledTimes(1)
118
+ w.unmount()
119
+ })
120
+
121
+ it('MPhoneInput: an incomplete number blocks an MForm submit', async () => {
122
+ const { onSubmit, onInvalid, w } = await submit(MPhoneInput, { modelValue: '+54112', country: 'AR' })
123
+ expect(onSubmit).not.toHaveBeenCalled()
124
+ expect(Object.keys(onInvalid.mock.calls[0][0])).toEqual(['f'])
125
+ w.unmount()
126
+ })
127
+
128
+ it('MAddressField: validates the picked place, and its inner text field stays out of the form', async () => {
129
+ const { onInvalid, w } = await submit(MAddressField, { modelValue: null, required: true })
130
+ // One field in the form (the address), not two
131
+ expect(onInvalid).toHaveBeenCalledWith({ f: defaultLocale.validationRequired })
132
+ expect(w.findAll('[role="alert"]')).toHaveLength(1)
133
+ w.unmount()
134
+ })
135
+ })
136
+
137
+ // ── Phase 3: controls that had no error state ─────────────────────────
138
+ import MCheckbox from '../components/MCheckbox.vue'
139
+ import MSwitch from '../components/MSwitch.vue'
140
+ import MRadioGroup from '../components/MRadioGroup.vue'
141
+ import MRating from '../components/MRating.vue'
142
+ import MSegmentedButton from '../components/MSegmentedButton.vue'
143
+ import MCronField from '../components/MCronField.vue'
144
+ import MFileUpload from '../components/MFileUpload.vue'
145
+ import MSignaturePad from '../components/MSignaturePad.vue'
146
+ import MCreditCardInput from '../components/MCreditCardInput.vue'
147
+ import MJsonEditor from '../components/MJsonEditor.vue'
148
+ import MSlider from '../components/MSlider.vue'
149
+ import { min, required } from '../composables/validation'
150
+
151
+ const blankCard = { number: '', expiry: '', cvc: '' }
152
+ /** [name, component, empty props, can it take focus] */
153
+ const groupB: [string, Component, Record<string, unknown>, boolean][] = [
154
+ ['MCheckbox', MCheckbox, { modelValue: false }, true],
155
+ ['MSwitch', MSwitch, { modelValue: false }, true],
156
+ ['MRadioGroup', MRadioGroup, { modelValue: null, options }, true],
157
+ ['MRating', MRating, { modelValue: 0 }, true],
158
+ ['MSegmentedButton', MSegmentedButton, { modelValue: undefined, options }, true],
159
+ ['MCronField', MCronField, { modelValue: '' }, true],
160
+ ['MFileUpload', MFileUpload, { modelValue: [] }, true],
161
+ ['MSignaturePad', MSignaturePad, {}, false],
162
+ ['MCreditCardInput', MCreditCardInput, { modelValue: blankCard, preview: false }, true],
163
+ ['MJsonEditor', MJsonEditor, { modelValue: null }, false],
164
+ ]
165
+
166
+ describe('group B fields in an MForm', () => {
167
+ it.each(groupB)('%s: required blocks submit and shows the message', async (_, field, props, focusable) => {
168
+ const { w, onSubmit, onInvalid } = await submit(field, { ...props, required: true })
169
+ expect(onSubmit).not.toHaveBeenCalled()
170
+ expect(Object.keys(onInvalid.mock.calls[0][0])).toEqual(['f'])
171
+ const alerts = [...document.body.querySelectorAll('[role="alert"]')].map((p) => p.textContent?.trim())
172
+ // The card shows its fields' own messages instead of a general one
173
+ if (field !== MCreditCardInput) expect(alerts).toEqual([defaultLocale.validationRequired])
174
+ else expect(alerts.length).toBeGreaterThan(0)
175
+ if (focusable) expect(w.element.contains(document.activeElement)).toBe(true)
176
+ w.unmount()
177
+ })
178
+
179
+ it.each(groupB)('%s: a string error is the message', async (_, field, props) => {
180
+ const w = mount(field, { props: { label: 'Field', ...props, error: 'From the server' }, attachTo: document.body })
181
+ await flushPromises()
182
+ expect([...document.body.querySelectorAll('[role="alert"]')].map((p) => p.textContent?.trim())).toEqual(['From the server'])
183
+ w.unmount()
184
+ })
185
+
186
+ it('MCheckbox takes the M3 error colors (Error outline unticked, Error container ticked)', async () => {
187
+ const w = mount(MCheckbox, { props: { modelValue: false, label: 'Terms', error: true } })
188
+ const box = () => w.findAll('span').find((s) => s.classes().includes('h-4.5'))!
189
+ expect(box().classes()).toContain('border-error')
190
+ await w.setProps({ modelValue: true })
191
+ expect(box().classes()).toEqual(expect.arrayContaining(['bg-error', 'text-on-error']))
192
+ })
193
+
194
+ it('MSlider: rules (not required) set its limits', async () => {
195
+ const { onInvalid, w } = await submit(MSlider, { modelValue: 0, rules: [min(10)] })
196
+ expect(onInvalid).toHaveBeenCalledWith({ f: 'Must be at least 10' })
197
+ w.unmount()
198
+ })
199
+
200
+ it('MCreditCardInput: an optional empty card passes, a half-typed one does not', async () => {
201
+ const ok = await submit(MCreditCardInput, { modelValue: blankCard, preview: false })
202
+ expect(ok.onSubmit).toHaveBeenCalled()
203
+ ok.w.unmount()
204
+ const bad = await submit(MCreditCardInput, { modelValue: { number: '4242', expiry: '', cvc: '' }, preview: false })
205
+ expect(bad.onSubmit).not.toHaveBeenCalled()
206
+ expect(bad.onInvalid).toHaveBeenCalledWith({ f: defaultLocale.cardInvalidNumber })
207
+ bad.w.unmount()
208
+ })
209
+
210
+ it("MJsonEditor: required alone (no form, no rules) keeps quiet", async () => {
211
+ const w = mount(MJsonEditor, { props: { modelValue: null, required: true } })
212
+ await flushPromises()
213
+ expect(w.findAll('[role="alert"]')).toHaveLength(0)
214
+ })
215
+
216
+ it('MForm disabled disables div-based fields too (MSelect)', async () => {
217
+ const w = mount(() => h(MForm, { disabled: true }, () => h(MSelect, { label: 'Room', modelValue: undefined, options })))
218
+ await flushPromises()
219
+ expect(w.find('[role="combobox"]').attributes('tabindex')).toBe('-1')
220
+ })
221
+ })
222
+
223
+ describe('required() in rules on a field with its own "empty"', () => {
224
+ it("MDateRangePicker: half a range fails with the rule's message", async () => {
225
+ const { onInvalid, w } = await submit(MDateRangePicker, { modelValue: { start: '2026-01-01', end: null }, required: true, rules: [required('Pick both dates')] })
226
+ expect(onInvalid).toHaveBeenCalledWith({ f: 'Pick both dates' })
227
+ w.unmount()
228
+ })
229
+ })