@m3ui-vue/m3ui-vue 0.8.8 → 0.9.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.
- package/README.md +13 -3
- package/dist/{MMenuItem-5xojJYAL.js → MTextField-B0wGv1Mx.js} +374 -364
- package/dist/MTextField-B0wGv1Mx.js.map +1 -0
- package/dist/barcode.js +9 -11
- package/dist/barcode.js.map +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MCarousel.vue.d.ts +55 -36
- package/dist/components/MDialog.vue.d.ts +4 -2
- package/dist/components/MEmojiSelector.vue.d.ts +21 -5
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +1 -1
- package/dist/components/MLightbox.vue.d.ts +15 -5
- package/dist/components/MScheduler.vue.d.ts +38 -1
- package/dist/components/MShape.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +2 -2
- package/dist/components/MSlider.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MWindow.vue.d.ts +1 -1
- package/dist/composables/_carouselStrategy.d.ts +101 -0
- package/dist/composables/useLocale.d.ts +19 -0
- package/dist/data/emoji-names/emoji-names-de.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-en.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-es.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-fr.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-ja.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-ko.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-pt.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-zh.d.ts +2 -0
- package/dist/data/emojis.d.ts +7 -1
- package/dist/emoji-names-de-BphO5XpV.js +1877 -0
- package/dist/emoji-names-de-BphO5XpV.js.map +1 -0
- package/dist/emoji-names-en-9ZvMRvzi.js +1877 -0
- package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -0
- package/dist/emoji-names-es-DvfWU3Pj.js +1877 -0
- package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -0
- package/dist/emoji-names-fr-B-jhUlsP.js +1877 -0
- package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -0
- package/dist/emoji-names-ja-l8cMFJo1.js +1877 -0
- package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -0
- package/dist/emoji-names-ko-YP-o9G0c.js +1877 -0
- package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -0
- package/dist/emoji-names-pt-DGj_Js4M.js +1877 -0
- package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -0
- package/dist/emoji-names-zh-Dzecwtw_.js +1877 -0
- package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/locales/index.js +140 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +3885 -2400
- package/dist/m3ui.js.map +1 -1
- package/dist/plugin.d.ts +6 -0
- package/dist/rich-text-editor.js +9 -9
- package/dist/styles.css +1 -1
- package/dist/terminal.js +34 -27
- package/dist/terminal.js.map +1 -1
- package/dist/{useLocale-D3ZWZ8jY.js → useLocale-CmI675Ab.js} +21 -2
- package/dist/useLocale-CmI675Ab.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MCarousel.test.ts +183 -21
- package/src/__tests__/MDialog.test.ts +18 -0
- package/src/__tests__/MEmojiSelector.test.ts +138 -0
- package/src/__tests__/MLightbox.test.ts +313 -5
- package/src/__tests__/MScheduler.test.ts +122 -0
- package/src/__tests__/MTerminal.test.ts +63 -0
- package/src/__tests__/attrsFallthrough.test.ts +65 -0
- package/src/__tests__/plugin.test.ts +28 -1
- package/src/components/MBarcode.vue +4 -2
- package/src/components/MBottomSheet.vue +1 -1
- package/src/components/MCarousel.vue +526 -200
- package/src/components/MCodeEditor.vue +3 -2
- package/src/components/MCommandPalette.vue +1 -1
- package/src/components/MContextMenu.vue +3 -1
- package/src/components/MDatePickerModal.vue +1 -1
- package/src/components/MDateRangePickerModal.vue +1 -1
- package/src/components/MDialog.vue +19 -6
- package/src/components/MEmojiSelector.vue +479 -78
- package/src/components/MFab.vue +3 -1
- package/src/components/MLightbox.vue +750 -268
- package/src/components/MLoadingOverlay.vue +6 -1
- package/src/components/MMenu.vue +3 -1
- package/src/components/MNavigationDrawer.vue +5 -1
- package/src/components/MNavigationRail.vue +3 -0
- package/src/components/MOverlay.vue +1 -0
- package/src/components/MScheduler.vue +282 -115
- package/src/components/MSideSheet.vue +1 -1
- package/src/components/MSplitButton.vue +3 -1
- package/src/components/MSpotlightSearch.vue +1 -1
- package/src/components/MTerminal.vue +22 -10
- package/src/components/MTimePickerModal.vue +1 -1
- package/src/components/MTooltip.vue +3 -0
- package/src/components/MTour.vue +2 -2
- package/src/composables/_carouselStrategy.ts +712 -0
- package/src/composables/useLocale.ts +38 -0
- package/src/data/emoji-names/emoji-names-de.ts +1875 -0
- package/src/data/emoji-names/emoji-names-en.ts +1875 -0
- package/src/data/emoji-names/emoji-names-es.ts +1875 -0
- package/src/data/emoji-names/emoji-names-fr.ts +1875 -0
- package/src/data/emoji-names/emoji-names-ja.ts +1875 -0
- package/src/data/emoji-names/emoji-names-ko.ts +1875 -0
- package/src/data/emoji-names/emoji-names-pt.ts +1875 -0
- package/src/data/emoji-names/emoji-names-zh.ts +1875 -0
- package/src/data/emojis.ts +29 -198
- package/src/index.ts +2 -2
- package/src/locales/de.ts +19 -0
- package/src/locales/es.ts +19 -0
- package/src/locales/fr.ts +19 -0
- package/src/locales/ja.ts +19 -0
- package/src/locales/ko.ts +19 -0
- package/src/locales/pt.ts +19 -0
- package/src/locales/zh.ts +19 -0
- package/src/plugin.ts +12 -1
- package/dist/MMenuItem-5xojJYAL.js.map +0 -1
- package/dist/useLocale-D3ZWZ8jY.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2
|
-
import { mount } from '@vue/test-utils'
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { mount, enableAutoUnmount } from '@vue/test-utils'
|
|
3
3
|
import { nextTick } from 'vue'
|
|
4
4
|
import MLightbox from '../components/MLightbox.vue'
|
|
5
5
|
|
|
@@ -9,6 +9,8 @@ const items = [
|
|
|
9
9
|
{ src: '/c.jpg', alt: 'C' },
|
|
10
10
|
]
|
|
11
11
|
|
|
12
|
+
enableAutoUnmount(afterEach)
|
|
13
|
+
|
|
12
14
|
describe('MLightbox', () => {
|
|
13
15
|
beforeEach(() => {
|
|
14
16
|
document.body.innerHTML = ''
|
|
@@ -148,7 +150,7 @@ describe('MLightbox', () => {
|
|
|
148
150
|
props: { modelValue: true, items, index: 0 },
|
|
149
151
|
attachTo: document.body,
|
|
150
152
|
})
|
|
151
|
-
const stage = document.body.querySelector('
|
|
153
|
+
const stage = document.body.querySelector('[data-lb-stage]') as HTMLElement
|
|
152
154
|
stage.dispatchEvent(new PointerEvent('pointerdown', { clientX: 200, pointerId: 1, button: 0, bubbles: true }))
|
|
153
155
|
stage.dispatchEvent(new PointerEvent('pointermove', { clientX: 50, pointerId: 1, bubbles: true }))
|
|
154
156
|
stage.dispatchEvent(new PointerEvent('pointerup', { clientX: 50, pointerId: 1, bubbles: true }))
|
|
@@ -161,7 +163,7 @@ describe('MLightbox', () => {
|
|
|
161
163
|
props: { modelValue: true, items, index: 1 },
|
|
162
164
|
attachTo: document.body,
|
|
163
165
|
})
|
|
164
|
-
const stage = document.body.querySelector('
|
|
166
|
+
const stage = document.body.querySelector('[data-lb-stage]') as HTMLElement
|
|
165
167
|
stage.dispatchEvent(new PointerEvent('pointerdown', { clientX: 50, pointerId: 1, button: 0, bubbles: true }))
|
|
166
168
|
stage.dispatchEvent(new PointerEvent('pointermove', { clientX: 200, pointerId: 1, bubbles: true }))
|
|
167
169
|
stage.dispatchEvent(new PointerEvent('pointerup', { clientX: 200, pointerId: 1, bubbles: true }))
|
|
@@ -174,7 +176,7 @@ describe('MLightbox', () => {
|
|
|
174
176
|
props: { modelValue: true, items: [items[0]] },
|
|
175
177
|
attachTo: document.body,
|
|
176
178
|
})
|
|
177
|
-
const stage = document.body.querySelector('
|
|
179
|
+
const stage = document.body.querySelector('[data-lb-stage]') as HTMLElement
|
|
178
180
|
stage.dispatchEvent(new PointerEvent('pointerdown', { clientX: 200, pointerId: 1, button: 0, bubbles: true }))
|
|
179
181
|
stage.dispatchEvent(new PointerEvent('pointermove', { clientX: 50, pointerId: 1, bubbles: true }))
|
|
180
182
|
stage.dispatchEvent(new PointerEvent('pointerup', { clientX: 50, pointerId: 1, bubbles: true }))
|
|
@@ -192,4 +194,310 @@ describe('MLightbox', () => {
|
|
|
192
194
|
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([true])
|
|
193
195
|
expect(document.body.querySelector('img')?.getAttribute('src')).toBe('/c.jpg')
|
|
194
196
|
})
|
|
197
|
+
|
|
198
|
+
describe('gestures, zoom and accessibility', () => {
|
|
199
|
+
beforeEach(() => {
|
|
200
|
+
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'requestAnimationFrame', 'cancelAnimationFrame', 'performance'] })
|
|
201
|
+
})
|
|
202
|
+
afterEach(() => vi.useRealTimers())
|
|
203
|
+
|
|
204
|
+
const settle = () => vi.advanceTimersByTime(2000)
|
|
205
|
+
const stage = () => document.body.querySelector('[data-lb-stage]') as HTMLElement
|
|
206
|
+
const pointer = (type: string, x: number, y: number, id = 1) =>
|
|
207
|
+
(type === 'pointerdown' ? stage() : stage()).dispatchEvent(new PointerEvent(type, { clientX: x, clientY: y, pointerId: id, button: 0, bubbles: true }))
|
|
208
|
+
|
|
209
|
+
it('is a modal dialog that announces the position', async () => {
|
|
210
|
+
mount(MLightbox, { props: { modelValue: true, items, index: 1 }, attachTo: document.body })
|
|
211
|
+
await nextTick()
|
|
212
|
+
const dialog = document.body.querySelector('[role="dialog"]')!
|
|
213
|
+
expect(dialog.getAttribute('aria-modal')).toBe('true')
|
|
214
|
+
expect(document.body.querySelector('[aria-live]')?.textContent).toBe('2 of 3')
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it('moves focus to the close button and gives it back on close', async () => {
|
|
218
|
+
const opener = document.createElement('button')
|
|
219
|
+
document.body.appendChild(opener)
|
|
220
|
+
opener.focus()
|
|
221
|
+
const wrapper = mount(MLightbox, { props: { items }, attachTo: document.body })
|
|
222
|
+
;(wrapper.vm as any).open(0)
|
|
223
|
+
await nextTick()
|
|
224
|
+
await nextTick()
|
|
225
|
+
expect(document.activeElement?.hasAttribute('data-lb-close')).toBe(true)
|
|
226
|
+
;(wrapper.vm as any).close()
|
|
227
|
+
settle()
|
|
228
|
+
await nextTick()
|
|
229
|
+
expect(document.body.querySelector('[role="dialog"]')).toBeNull()
|
|
230
|
+
expect(document.activeElement).toBe(opener)
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('dragging the image down far enough closes it', async () => {
|
|
234
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
235
|
+
await nextTick()
|
|
236
|
+
pointer('pointerdown', 200, 200)
|
|
237
|
+
vi.advanceTimersByTime(16)
|
|
238
|
+
pointer('pointermove', 200, 260)
|
|
239
|
+
vi.advanceTimersByTime(16)
|
|
240
|
+
pointer('pointermove', 200, 400)
|
|
241
|
+
pointer('pointerup', 200, 400)
|
|
242
|
+
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([false])
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
it('a short drag down springs back instead of closing', async () => {
|
|
246
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
247
|
+
await nextTick()
|
|
248
|
+
pointer('pointerdown', 200, 200)
|
|
249
|
+
vi.advanceTimersByTime(200)
|
|
250
|
+
pointer('pointermove', 200, 240)
|
|
251
|
+
vi.advanceTimersByTime(200)
|
|
252
|
+
pointer('pointerup', 200, 240)
|
|
253
|
+
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
it('a double tap zooms in and another zooms back out', async () => {
|
|
257
|
+
mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
258
|
+
await nextTick()
|
|
259
|
+
settle()
|
|
260
|
+
const zoomEl = () => document.body.querySelector('[data-lb-slide][data-offset="0"] [data-lb-zoom]') as HTMLElement
|
|
261
|
+
const tap = () => {
|
|
262
|
+
pointer('pointerdown', 0, 0)
|
|
263
|
+
pointer('pointerup', 0, 0)
|
|
264
|
+
vi.advanceTimersByTime(100)
|
|
265
|
+
}
|
|
266
|
+
tap()
|
|
267
|
+
tap()
|
|
268
|
+
settle()
|
|
269
|
+
expect(zoomEl().style.transform).toContain('scale(2.5)')
|
|
270
|
+
tap()
|
|
271
|
+
tap()
|
|
272
|
+
settle()
|
|
273
|
+
expect(zoomEl().style.transform).toContain('scale(1)')
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
it('a zoomed image pans instead of swiping', async () => {
|
|
277
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
278
|
+
await nextTick()
|
|
279
|
+
settle()
|
|
280
|
+
pointer('pointerdown', 0, 0); pointer('pointerup', 0, 0); vi.advanceTimersByTime(100)
|
|
281
|
+
pointer('pointerdown', 0, 0); pointer('pointerup', 0, 0)
|
|
282
|
+
settle()
|
|
283
|
+
pointer('pointerdown', 300, 200)
|
|
284
|
+
pointer('pointermove', 50, 200)
|
|
285
|
+
pointer('pointerup', 50, 200)
|
|
286
|
+
expect(wrapper.emitted('update:index')).toBeUndefined()
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
it('a single tap on the image hides and shows the bars', async () => {
|
|
290
|
+
mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
291
|
+
await nextTick()
|
|
292
|
+
const bar = () => document.body.querySelector('[data-lb-close]')!.parentElement!
|
|
293
|
+
const img = document.body.querySelector('[data-lb-slide][data-offset="0"] img') as HTMLElement
|
|
294
|
+
img.getBoundingClientRect = () => ({ left: 0, top: 0, right: 100, bottom: 100, width: 100, height: 100, x: 0, y: 0, toJSON() {} }) as DOMRect
|
|
295
|
+
const tapImage = () => {
|
|
296
|
+
img.dispatchEvent(new PointerEvent('pointerdown', { clientX: 5, clientY: 5, pointerId: 1, button: 0, bubbles: true }))
|
|
297
|
+
img.dispatchEvent(new PointerEvent('pointerup', { clientX: 5, clientY: 5, pointerId: 1, button: 0, bubbles: true }))
|
|
298
|
+
vi.advanceTimersByTime(400)
|
|
299
|
+
}
|
|
300
|
+
tapImage()
|
|
301
|
+
await nextTick()
|
|
302
|
+
expect(bar().classList.contains('opacity-0')).toBe(true)
|
|
303
|
+
tapImage()
|
|
304
|
+
await nextTick()
|
|
305
|
+
expect(bar().classList.contains('opacity-0')).toBe(false)
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
it('arrow keys navigate and Escape closes', async () => {
|
|
309
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items, index: 0 }, attachTo: document.body })
|
|
310
|
+
await nextTick()
|
|
311
|
+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowRight' }))
|
|
312
|
+
expect(wrapper.emitted('update:index')?.[0]).toEqual([1])
|
|
313
|
+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
|
|
314
|
+
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([false])
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
it('renders the #actions slot with the current item', async () => {
|
|
318
|
+
mount(MLightbox, {
|
|
319
|
+
props: { modelValue: true, items, index: 2 },
|
|
320
|
+
slots: { actions: `<template #actions="{ item, index }"><span class="act">{{ index }}:{{ item.alt }}</span></template>` },
|
|
321
|
+
attachTo: document.body,
|
|
322
|
+
})
|
|
323
|
+
await nextTick()
|
|
324
|
+
expect(document.body.querySelector('.act')?.textContent).toBe('2:C')
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
it('with two looping images, shows the other one on both sides', async () => {
|
|
328
|
+
mount(MLightbox, { props: { modelValue: true, items: items.slice(0, 2), index: 0 }, attachTo: document.body })
|
|
329
|
+
await nextTick()
|
|
330
|
+
const offsets = [...document.body.querySelectorAll('[data-lb-slide]')].map((el) => [el.getAttribute('data-offset'), el.querySelector('img')!.getAttribute('src')])
|
|
331
|
+
expect(offsets).toEqual([['0', '/a.jpg'], ['1', '/b.jpg'], ['-1', '/b.jpg']])
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
it('a click on the image toggles the bars even though the stage captured the pointer', async () => {
|
|
335
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
336
|
+
await nextTick()
|
|
337
|
+
const img = document.body.querySelector('[data-lb-slide][data-offset="0"] img') as HTMLElement
|
|
338
|
+
img.getBoundingClientRect = () => ({ left: 100, top: 100, right: 300, bottom: 250, width: 200, height: 150, x: 100, y: 100, toJSON() {} }) as DOMRect
|
|
339
|
+
// With pointer capture the browser targets pointerup at the stage, not the image.
|
|
340
|
+
pointer('pointerdown', 150, 150)
|
|
341
|
+
pointer('pointerup', 150, 150)
|
|
342
|
+
vi.advanceTimersByTime(400)
|
|
343
|
+
await nextTick()
|
|
344
|
+
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
|
345
|
+
expect(document.body.querySelector('[data-lb-close]')!.parentElement!.classList.contains('opacity-0')).toBe(true)
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
it('hides the bars as soon as it starts closing', async () => {
|
|
349
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
350
|
+
await nextTick()
|
|
351
|
+
;(wrapper.vm as any).close()
|
|
352
|
+
await nextTick()
|
|
353
|
+
expect(document.body.querySelector('[data-lb-close]')!.parentElement!.classList.contains('opacity-0')).toBe(true)
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
it('keeps the active thumbnail in view without scrolling the viewer itself', async () => {
|
|
357
|
+
const spy = vi.spyOn(HTMLElement.prototype, 'scrollIntoView')
|
|
358
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items, showThumbnails: true }, attachTo: document.body })
|
|
359
|
+
await nextTick()
|
|
360
|
+
;(wrapper.vm as any).next()
|
|
361
|
+
await nextTick()
|
|
362
|
+
await nextTick()
|
|
363
|
+
expect(spy).not.toHaveBeenCalled()
|
|
364
|
+
expect((document.body.querySelector('[role="dialog"]') as HTMLElement).scrollLeft).toBe(0)
|
|
365
|
+
spy.mockRestore()
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
describe('pinch', () => {
|
|
369
|
+
const zoomTransform = () => (document.body.querySelector('[data-lb-slide][data-offset="0"] [data-lb-zoom]') as HTMLElement).style.transform
|
|
370
|
+
const scaleOf = () => Number(/scale\(([\d.]+)\)/.exec(zoomTransform())![1])
|
|
371
|
+
const trackOf = () => (document.body.querySelector('[data-lb-slide][data-offset="0"]') as HTMLElement).style.transform
|
|
372
|
+
|
|
373
|
+
it('spreading two fingers zooms in, pinching them back zooms out to 1', async () => {
|
|
374
|
+
mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
375
|
+
await nextTick()
|
|
376
|
+
settle()
|
|
377
|
+
pointer('pointerdown', 100, 200, 1)
|
|
378
|
+
pointer('pointerdown', 200, 200, 2)
|
|
379
|
+
pointer('pointermove', 50, 200, 1)
|
|
380
|
+
pointer('pointermove', 250, 200, 2)
|
|
381
|
+
expect(scaleOf()).toBeCloseTo(2, 5)
|
|
382
|
+
pointer('pointermove', 125, 200, 1)
|
|
383
|
+
pointer('pointermove', 175, 200, 2)
|
|
384
|
+
expect(scaleOf()).toBeLessThan(1)
|
|
385
|
+
pointer('pointerup', 125, 200, 1)
|
|
386
|
+
pointer('pointerup', 175, 200, 2)
|
|
387
|
+
settle()
|
|
388
|
+
expect(scaleOf()).toBe(1)
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
it('a swipe the first finger had started is undone when the pinch begins', async () => {
|
|
392
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
393
|
+
await nextTick()
|
|
394
|
+
settle()
|
|
395
|
+
pointer('pointerdown', 100, 200, 1)
|
|
396
|
+
pointer('pointermove', 80, 200, 1)
|
|
397
|
+
pointer('pointermove', 60, 200, 1)
|
|
398
|
+
pointer('pointerdown', 200, 200, 2)
|
|
399
|
+
pointer('pointermove', 30, 200, 1)
|
|
400
|
+
pointer('pointermove', 260, 200, 2)
|
|
401
|
+
pointer('pointerup', 30, 200, 1)
|
|
402
|
+
pointer('pointerup', 260, 200, 2)
|
|
403
|
+
settle()
|
|
404
|
+
expect(wrapper.emitted('update:index')).toBeUndefined()
|
|
405
|
+
expect(trackOf()).toContain('translate3d(0px')
|
|
406
|
+
expect(scaleOf()).toBeGreaterThan(1.5)
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
it('lifting one finger lets the other keep moving the zoomed image', async () => {
|
|
410
|
+
mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
411
|
+
await nextTick()
|
|
412
|
+
settle()
|
|
413
|
+
pointer('pointerdown', 100, 200, 1)
|
|
414
|
+
pointer('pointerdown', 200, 200, 2)
|
|
415
|
+
pointer('pointermove', 0, 200, 1)
|
|
416
|
+
pointer('pointermove', 300, 200, 2)
|
|
417
|
+
pointer('pointerup', 0, 200, 1)
|
|
418
|
+
const before = zoomTransform()
|
|
419
|
+
pointer('pointermove', 340, 240, 2)
|
|
420
|
+
expect(zoomTransform()).not.toBe(before)
|
|
421
|
+
pointer('pointerup', 340, 240, 2)
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
it('a pinch never counts as a tap', async () => {
|
|
425
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items }, attachTo: document.body })
|
|
426
|
+
await nextTick()
|
|
427
|
+
pointer('pointerdown', 100, 200, 1)
|
|
428
|
+
pointer('pointerdown', 200, 200, 2)
|
|
429
|
+
pointer('pointerup', 100, 200, 1)
|
|
430
|
+
pointer('pointerup', 200, 200, 2)
|
|
431
|
+
vi.advanceTimersByTime(500)
|
|
432
|
+
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
|
433
|
+
})
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
it('opens from a cropped thumbnail with its shape, then uncrops', async () => {
|
|
437
|
+
const thumb = document.createElement('button')
|
|
438
|
+
thumb.style.borderTopLeftRadius = '12px'
|
|
439
|
+
thumb.getBoundingClientRect = () => ({ left: 0, top: 0, right: 100, bottom: 100, width: 100, height: 100, x: 0, y: 0, toJSON() {} }) as DOMRect
|
|
440
|
+
document.body.appendChild(thumb)
|
|
441
|
+
// A 3:2 picture shown at 300×200 opening from a square: covered at scale 0.5, cropped to 200×200.
|
|
442
|
+
Object.defineProperty(HTMLImageElement.prototype, 'offsetWidth', { configurable: true, get: () => 300 })
|
|
443
|
+
Object.defineProperty(HTMLImageElement.prototype, 'offsetHeight', { configurable: true, get: () => 200 })
|
|
444
|
+
const wrapper = mount(MLightbox, { props: { items }, attachTo: document.body })
|
|
445
|
+
;(wrapper.vm as any).open(0, thumb)
|
|
446
|
+
await nextTick()
|
|
447
|
+
await nextTick()
|
|
448
|
+
await Promise.resolve()
|
|
449
|
+
vi.advanceTimersByTime(16)
|
|
450
|
+
const img = document.body.querySelector('[data-lb-slide][data-offset="0"] img') as HTMLElement
|
|
451
|
+
// @ts-expect-error restore happy-dom's own getters
|
|
452
|
+
delete HTMLImageElement.prototype.offsetWidth
|
|
453
|
+
// @ts-expect-error restore happy-dom's own getters
|
|
454
|
+
delete HTMLImageElement.prototype.offsetHeight
|
|
455
|
+
const zoomEl = img.closest('[data-lb-zoom]') as HTMLElement
|
|
456
|
+
expect(zoomEl.style.clipPath).toMatch(/^inset\(0px 4\d\.\d+px round/)
|
|
457
|
+
settle()
|
|
458
|
+
expect(zoomEl.style.clipPath).toBe('')
|
|
459
|
+
})
|
|
460
|
+
|
|
461
|
+
it('sizes an image from its ratio, so an SVG without width/height still shows', async () => {
|
|
462
|
+
Object.defineProperty(HTMLElement.prototype, 'clientWidth', { configurable: true, get() { return this.hasAttribute?.('data-lb-stage') ? 800 : 0 } })
|
|
463
|
+
Object.defineProperty(HTMLElement.prototype, 'clientHeight', { configurable: true, get() { return this.hasAttribute?.('data-lb-stage') ? 600 : 0 } })
|
|
464
|
+
const svg = `data:image/svg+xml,${encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 200'/>")}`
|
|
465
|
+
mount(MLightbox, { props: { modelValue: true, items: [{ src: svg }] }, attachTo: document.body })
|
|
466
|
+
await nextTick()
|
|
467
|
+
await nextTick()
|
|
468
|
+
const img = document.body.querySelector('[data-lb-slide] img') as HTMLImageElement
|
|
469
|
+
Object.defineProperty(img, 'naturalWidth', { value: 400 })
|
|
470
|
+
Object.defineProperty(img, 'naturalHeight', { value: 200 })
|
|
471
|
+
img.dispatchEvent(new Event('load'))
|
|
472
|
+
// happy-dom doesn't lay out the off-screen probe, so its error path falls back to the natural ratio.
|
|
473
|
+
document.body.querySelectorAll('img').forEach((p) => p !== img && p.dispatchEvent(new Event('error')))
|
|
474
|
+
await nextTick()
|
|
475
|
+
// 800×600 stage minus 48px padding on each side leaves 704×504; a 2:1 image fills the width.
|
|
476
|
+
expect(img.style.width).toBe('704px')
|
|
477
|
+
expect(img.style.height).toBe('352px')
|
|
478
|
+
// @ts-expect-error restore happy-dom's own getters
|
|
479
|
+
delete HTMLElement.prototype.clientWidth
|
|
480
|
+
// @ts-expect-error restore happy-dom's own getters
|
|
481
|
+
delete HTMLElement.prototype.clientHeight
|
|
482
|
+
})
|
|
483
|
+
|
|
484
|
+
it('opening on another image shows it directly instead of sliding to it', async () => {
|
|
485
|
+
Object.defineProperty(HTMLElement.prototype, 'clientWidth', { configurable: true, get() { return this.hasAttribute?.('data-lb-stage') ? 800 : 0 } })
|
|
486
|
+
const wrapper = mount(MLightbox, { props: { modelValue: true, items, index: 0 }, attachTo: document.body })
|
|
487
|
+
await nextTick()
|
|
488
|
+
settle()
|
|
489
|
+
await wrapper.setProps({ modelValue: false })
|
|
490
|
+
settle()
|
|
491
|
+
await nextTick()
|
|
492
|
+
// Second open, like a chat: the index and v-model change together.
|
|
493
|
+
await wrapper.setProps({ index: 2, modelValue: true })
|
|
494
|
+
await nextTick()
|
|
495
|
+
vi.advanceTimersByTime(16)
|
|
496
|
+
const current = document.body.querySelector('[data-lb-slide][data-offset="0"]') as HTMLElement
|
|
497
|
+
expect(current.querySelector('img')!.getAttribute('src')).toBe('/c.jpg')
|
|
498
|
+
expect(current.style.transform).toBe('translate3d(0px, 0, 0)')
|
|
499
|
+
// @ts-expect-error restore happy-dom's own getter
|
|
500
|
+
delete HTMLElement.prototype.clientWidth
|
|
501
|
+
})
|
|
502
|
+
})
|
|
195
503
|
})
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import MScheduler from '../components/MScheduler.vue'
|
|
4
|
+
import type { SchedulerEvent } from '../components/MScheduler.vue'
|
|
5
|
+
|
|
6
|
+
// A Wednesday; with the default Monday start its week runs Oct 12 – Oct 18, 2026.
|
|
7
|
+
const date = '2026-10-14'
|
|
8
|
+
let wrapper: VueWrapper | null = null
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
wrapper?.unmount()
|
|
11
|
+
wrapper = null
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
function mountScheduler(events: SchedulerEvent[], props: Record<string, unknown> = {}) {
|
|
15
|
+
wrapper = mount(MScheduler, { props: { events, date, startHour: 8, endHour: 20, hourHeight: 60, locale: 'en-US', ...props } })
|
|
16
|
+
return wrapper
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const block = (title: string) => wrapper!.findAll('[data-scheduler-event]').find((b) => b.text().includes(title))!
|
|
20
|
+
const px = (v: string) => Number.parseFloat(v)
|
|
21
|
+
|
|
22
|
+
describe('MScheduler', () => {
|
|
23
|
+
it('shows the week of the date prop', () => {
|
|
24
|
+
mountScheduler([])
|
|
25
|
+
expect(wrapper!.findAll('[data-scheduler-day]').map((d) => d.attributes('data-scheduler-day'))).toEqual([
|
|
26
|
+
'2026-10-12', '2026-10-13', '2026-10-14', '2026-10-15', '2026-10-16', '2026-10-17', '2026-10-18',
|
|
27
|
+
])
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('weekStartsOn 0 starts the week on Sunday', () => {
|
|
31
|
+
mountScheduler([], { weekStartsOn: 0 })
|
|
32
|
+
expect(wrapper!.find('[data-scheduler-day]').attributes('data-scheduler-day')).toBe('2026-10-11')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('places events with minute precision', () => {
|
|
36
|
+
mountScheduler([{ id: 1, title: 'Standup', start: '2026-10-14T09:30', end: '2026-10-14T10:15' }])
|
|
37
|
+
const style = block('Standup').attributes('style')!
|
|
38
|
+
// 9:30 is 1.5 hours after 8:00 at 60px an hour; 45 minutes is 45px (minus the 1px gaps).
|
|
39
|
+
expect(px(/top: ([\d.]+)px/.exec(style)![1]!)).toBe(91)
|
|
40
|
+
expect(px(/height: ([\d.]+)px/.exec(style)![1]!)).toBe(43)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('puts overlapping events side by side', () => {
|
|
44
|
+
mountScheduler([
|
|
45
|
+
{ id: 1, title: 'Alpha', start: '2026-10-14T10:00', end: '2026-10-14T12:00' },
|
|
46
|
+
{ id: 2, title: 'Beta', start: '2026-10-14T11:00', end: '2026-10-14T13:00' },
|
|
47
|
+
{ id: 3, title: 'Gamma', start: '2026-10-14T14:00', end: '2026-10-14T15:00' },
|
|
48
|
+
])
|
|
49
|
+
expect(block('Alpha').attributes('style')).toContain('width: calc(50% - 4px)')
|
|
50
|
+
expect(block('Beta').attributes('style')).toContain('left: calc(50% + 2px)')
|
|
51
|
+
expect(block('Gamma').attributes('style')).toContain('width: calc(100% - 4px)')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('clips events that start before startHour instead of dropping them', () => {
|
|
55
|
+
mountScheduler([{ id: 1, title: 'Early run', start: '2026-10-14T06:30', end: '2026-10-14T09:00' }])
|
|
56
|
+
expect(block('Early run').attributes('style')).toContain('top: 1px')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('shows multi-day and all-day events as bars across their days', () => {
|
|
60
|
+
mountScheduler([
|
|
61
|
+
{ id: 1, title: 'Conference', start: '2026-10-13T09:00', end: '2026-10-15T17:00' },
|
|
62
|
+
{ id: 2, title: 'Holiday', start: '2026-10-16', end: '2026-10-16', allDay: true },
|
|
63
|
+
{ id: 3, title: 'Trip', start: '2026-10-17', end: '2026-10-22', allDay: true },
|
|
64
|
+
])
|
|
65
|
+
expect(wrapper!.findAll('[data-scheduler-event]')).toHaveLength(0)
|
|
66
|
+
const bars = wrapper!.findAll('[data-scheduler-bar]')
|
|
67
|
+
const style = (t: string) => bars.find((b) => b.text().includes(t))!.attributes('style')
|
|
68
|
+
expect(style('Conference')).toContain('grid-column: 2 / 5')
|
|
69
|
+
expect(style('Holiday')).toContain('grid-column: 5 / 6')
|
|
70
|
+
// Runs past Sunday: clipped to the week's last column.
|
|
71
|
+
expect(style('Trip')).toContain('grid-column: 6 / 8')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('stacks overlapping bars in separate lanes', () => {
|
|
75
|
+
mountScheduler([
|
|
76
|
+
{ id: 1, title: 'A', start: '2026-10-12', end: '2026-10-14', allDay: true },
|
|
77
|
+
{ id: 2, title: 'B', start: '2026-10-13', end: '2026-10-15', allDay: true },
|
|
78
|
+
])
|
|
79
|
+
const rows = wrapper!.findAll('[data-scheduler-bar]').map((b) => /grid-row: (\d+)/.exec(b.attributes('style')!)![1])
|
|
80
|
+
expect(rows).toEqual(['1', '2'])
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('an event ending at midnight stays in the time grid', () => {
|
|
84
|
+
mountScheduler([{ id: 1, title: 'Late', start: '2026-10-14T18:00', end: '2026-10-15T00:00' }])
|
|
85
|
+
expect(wrapper!.findAll('[data-scheduler-bar]')).toHaveLength(0)
|
|
86
|
+
expect(block('Late').exists()).toBe(true)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('navigating emits update:date and follows the date prop', async () => {
|
|
90
|
+
mountScheduler([])
|
|
91
|
+
await wrapper!.findAll('button')[1]!.trigger('click')
|
|
92
|
+
expect(wrapper!.emitted('update:date')?.[0]).toEqual(['2026-10-21'])
|
|
93
|
+
await wrapper!.setProps({ date: '2026-12-02' })
|
|
94
|
+
expect(wrapper!.find('[data-scheduler-day]').attributes('data-scheduler-day')).toBe('2026-11-30')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('follows the view prop and emits update:view from the toggle', async () => {
|
|
98
|
+
mountScheduler([])
|
|
99
|
+
await wrapper!.setProps({ view: 'day' })
|
|
100
|
+
expect(wrapper!.findAll('[data-scheduler-day]')).toHaveLength(1)
|
|
101
|
+
const weekToggle = wrapper!.findAll('button').find((b) => b.text() === 'Week')!
|
|
102
|
+
await weekToggle.trigger('click')
|
|
103
|
+
expect(wrapper!.emitted('update:view')?.[0]).toEqual(['week'])
|
|
104
|
+
expect(wrapper!.findAll('[data-scheduler-day]')).toHaveLength(7)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('clicking a day header in week view opens that day', async () => {
|
|
108
|
+
mountScheduler([])
|
|
109
|
+
const headers = wrapper!.findAll('button').filter((b) => /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/.test(b.text()))
|
|
110
|
+
await headers[4]!.trigger('click')
|
|
111
|
+
expect(wrapper!.emitted('update:view')?.[0]).toEqual(['day'])
|
|
112
|
+
expect(wrapper!.emitted('update:date')?.[0]).toEqual(['2026-10-16'])
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('renders an #event slot', () => {
|
|
116
|
+
wrapper = mount(MScheduler, {
|
|
117
|
+
props: { events: [{ id: 1, title: 'Lunch', start: '2026-10-14T12:00', end: '2026-10-14T13:00' }], date, locale: 'en-US' },
|
|
118
|
+
slots: { event: `<template #event="{ event }"><b class="custom">{{ event.title }}!</b></template>` },
|
|
119
|
+
})
|
|
120
|
+
expect(wrapper.find('.custom').text()).toBe('Lunch!')
|
|
121
|
+
})
|
|
122
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest'
|
|
2
|
+
import { mount, flushPromises } from '@vue/test-utils'
|
|
3
|
+
import MTerminal from '../components/MTerminal.vue'
|
|
4
|
+
|
|
5
|
+
// xterm needs a real canvas; a stand-in records what the component hands it.
|
|
6
|
+
const instances: { options: Record<string, any> }[] = []
|
|
7
|
+
vi.mock('@xterm/xterm', () => ({
|
|
8
|
+
Terminal: class {
|
|
9
|
+
options: Record<string, any>
|
|
10
|
+
constructor(options: Record<string, any>) {
|
|
11
|
+
this.options = options
|
|
12
|
+
instances.push(this)
|
|
13
|
+
}
|
|
14
|
+
loadAddon() {}
|
|
15
|
+
open() {}
|
|
16
|
+
write() {}
|
|
17
|
+
writeln() {}
|
|
18
|
+
clear() {}
|
|
19
|
+
focus() {}
|
|
20
|
+
dispose() {}
|
|
21
|
+
onData() {}
|
|
22
|
+
},
|
|
23
|
+
}))
|
|
24
|
+
vi.mock('@xterm/addon-fit', () => ({ FitAddon: class { fit() {} } }))
|
|
25
|
+
vi.mock('@xterm/xterm/css/xterm.css', () => ({}))
|
|
26
|
+
|
|
27
|
+
const html = document.documentElement
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
instances.length = 0
|
|
30
|
+
html.classList.remove('dark')
|
|
31
|
+
html.removeAttribute('data-palette')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('MTerminal', () => {
|
|
35
|
+
it('follows theme and palette changes', async () => {
|
|
36
|
+
const wrapper = mount(MTerminal, { attachTo: document.body })
|
|
37
|
+
// happy-dom doesn't inherit custom properties into getComputedStyle, so set them where the
|
|
38
|
+
// component reads them (its container); the changes that trigger a re-read still happen on <html>.
|
|
39
|
+
const container = wrapper.find('.bg-surface-container-lowest').element as HTMLElement
|
|
40
|
+
container.style.setProperty('--color-surface-container-lowest', '#ffffff')
|
|
41
|
+
await flushPromises()
|
|
42
|
+
const term = instances[0]!
|
|
43
|
+
expect(term.options.theme.background).toBe('#ffffff')
|
|
44
|
+
|
|
45
|
+
container.style.setProperty('--color-surface-container-lowest', '#0f0d13')
|
|
46
|
+
html.classList.add('dark')
|
|
47
|
+
await flushPromises()
|
|
48
|
+
expect(term.options.theme.background).toBe('#0f0d13')
|
|
49
|
+
|
|
50
|
+
container.style.setProperty('--color-surface-container-lowest', '#101418')
|
|
51
|
+
html.setAttribute('data-palette', 'teal')
|
|
52
|
+
await flushPromises()
|
|
53
|
+
expect(term.options.theme.background).toBe('#101418')
|
|
54
|
+
wrapper.unmount()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('does not create a terminal when unmounted while xterm loads', async () => {
|
|
58
|
+
const wrapper = mount(MTerminal, { attachTo: document.body })
|
|
59
|
+
wrapper.unmount()
|
|
60
|
+
await flushPromises()
|
|
61
|
+
expect(instances).toHaveLength(0)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { nextTick, type Component } from 'vue'
|
|
4
|
+
import MMenu from '../components/MMenu.vue'
|
|
5
|
+
import MContextMenu from '../components/MContextMenu.vue'
|
|
6
|
+
import MTooltip from '../components/MTooltip.vue'
|
|
7
|
+
import MFab from '../components/MFab.vue'
|
|
8
|
+
import MSplitButton from '../components/MSplitButton.vue'
|
|
9
|
+
import MLightbox from '../components/MLightbox.vue'
|
|
10
|
+
import MBarcode from '../components/MBarcode.vue'
|
|
11
|
+
import MLoadingOverlay from '../components/MLoadingOverlay.vue'
|
|
12
|
+
import MNavigationDrawer from '../components/MNavigationDrawer.vue'
|
|
13
|
+
import MNavigationRail from '../components/MNavigationRail.vue'
|
|
14
|
+
import MSkeleton from '../components/MSkeleton.vue'
|
|
15
|
+
import MStepper from '../components/MStepper.vue'
|
|
16
|
+
import MTabs from '../components/MTabs.vue'
|
|
17
|
+
import MTransferList from '../components/MTransferList.vue'
|
|
18
|
+
|
|
19
|
+
// These components render more than one root node (an element plus a Teleport, a v-if/v-show
|
|
20
|
+
// pair, a comment before the root...), which makes Vue drop a consumer's class/attrs silently.
|
|
21
|
+
// Each case names the element that should receive them.
|
|
22
|
+
const cases: [name: string, component: Component, props: Record<string, unknown>, tag: string][] = [
|
|
23
|
+
['MMenu', MMenu, {}, 'DIV'],
|
|
24
|
+
['MContextMenu', MContextMenu, {}, 'DIV'],
|
|
25
|
+
['MTooltip', MTooltip, { text: 'Tip' }, 'SPAN'],
|
|
26
|
+
['MFab', MFab, { icon: 'add' }, 'DIV'],
|
|
27
|
+
['MSplitButton', MSplitButton, { label: 'Save' }, 'DIV'],
|
|
28
|
+
['MLightbox', MLightbox, { modelValue: false, items: [] }, 'DIV'],
|
|
29
|
+
['MBarcode', MBarcode, { value: '123456789012', displayValue: false }, 'svg'],
|
|
30
|
+
['MBarcode (error)', MBarcode, { value: 'abc', format: 'EAN13', displayValue: false }, 'DIV'],
|
|
31
|
+
['MLoadingOverlay', MLoadingOverlay, { visible: true }, 'DIV'],
|
|
32
|
+
['MLoadingOverlay (fullscreen)', MLoadingOverlay, { visible: true, fullscreen: true }, 'DIV'],
|
|
33
|
+
['MNavigationDrawer', MNavigationDrawer, { modelValue: true, sections: [] }, 'NAV'],
|
|
34
|
+
['MNavigationDrawer (modal)', MNavigationDrawer, { modelValue: true, sections: [], modal: true }, 'NAV'],
|
|
35
|
+
['MNavigationRail', MNavigationRail, { modelValue: 'a', items: [] }, 'NAV'],
|
|
36
|
+
['MNavigationRail (modal)', MNavigationRail, { modelValue: 'a', items: [], modal: true }, 'NAV'],
|
|
37
|
+
['MSkeleton', MSkeleton, {}, 'DIV'],
|
|
38
|
+
['MSkeleton (lines)', MSkeleton, { variant: 'text', lines: 3 }, 'DIV'],
|
|
39
|
+
['MStepper', MStepper, { steps: [{ label: 'One' }], modelValue: 0 }, 'DIV'],
|
|
40
|
+
['MStepper (vertical)', MStepper, { steps: [{ label: 'One' }], modelValue: 0, direction: 'vertical' }, 'DIV'],
|
|
41
|
+
['MTabs', MTabs, { modelValue: 'a', tabs: [{ value: 'a', label: 'A' }] }, 'DIV'],
|
|
42
|
+
['MTabs (secondary)', MTabs, { modelValue: 'a', tabs: [{ value: 'a', label: 'A' }], variant: 'secondary' }, 'DIV'],
|
|
43
|
+
['MTransferList', MTransferList, { modelValue: [], items: [] }, 'DIV'],
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
describe('consumer attrs reach multi-root components', () => {
|
|
47
|
+
let wrapper: VueWrapper | null = null
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
wrapper?.unmount()
|
|
50
|
+
wrapper = null
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it.each(cases)('%s', async (_name, component, props, tag) => {
|
|
54
|
+
wrapper = mount(component, {
|
|
55
|
+
props,
|
|
56
|
+
attrs: { class: 'consumer-class', 'data-consumer': 'yes' },
|
|
57
|
+
attachTo: document.body,
|
|
58
|
+
})
|
|
59
|
+
await nextTick()
|
|
60
|
+
const matches = document.body.querySelectorAll('[data-consumer="yes"]')
|
|
61
|
+
expect(matches).toHaveLength(1)
|
|
62
|
+
expect(matches[0].tagName).toBe(tag)
|
|
63
|
+
expect(matches[0].classList.contains('consumer-class')).toBe(true)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
2
2
|
import { createApp, defineComponent, h } from 'vue'
|
|
3
3
|
import { createM3UI } from '../plugin'
|
|
4
|
-
import { useColorPalette } from '../composables/useColorPalette'
|
|
4
|
+
import { useColorPalette, palettes } from '../composables/useColorPalette'
|
|
5
5
|
|
|
6
6
|
describe('createM3UI', () => {
|
|
7
7
|
beforeEach(() => {
|
|
@@ -52,4 +52,31 @@ describe('createM3UI', () => {
|
|
|
52
52
|
app.use(createM3UI({ palette: 'iron', persistPalette: false }))
|
|
53
53
|
expect(localStorage.getItem('m3-palette')).toBeNull()
|
|
54
54
|
})
|
|
55
|
+
|
|
56
|
+
describe('customPalettes', () => {
|
|
57
|
+
const builtIn = palettes.map((p) => ({ ...p }))
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
palettes.splice(0, palettes.length, ...builtIn)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('adds custom palettes to the list useColorPalette returns', () => {
|
|
63
|
+
const app = createApp(defineComponent({ render: () => h('div') }))
|
|
64
|
+
app.use(createM3UI({ customPalettes: [{ id: 'brand', label: 'Brand', seed: '#0b6e4f' }] }))
|
|
65
|
+
expect(useColorPalette().palettes).toHaveLength(builtIn.length + 1)
|
|
66
|
+
expect(useColorPalette().palettes.at(-1)).toEqual({ id: 'brand', label: 'Brand', seed: '#0b6e4f' })
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('replaces a built-in palette with the same id instead of duplicating it', () => {
|
|
70
|
+
const app = createApp(defineComponent({ render: () => h('div') }))
|
|
71
|
+
app.use(createM3UI({ customPalettes: [{ id: 'teal', label: 'Our teal', seed: '#008080' }] }))
|
|
72
|
+
expect(palettes).toHaveLength(builtIn.length)
|
|
73
|
+
expect(palettes.filter((p) => p.id === 'teal')).toEqual([{ id: 'teal', label: 'Our teal', seed: '#008080' }])
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('can be selected as the starting palette', () => {
|
|
77
|
+
const app = createApp(defineComponent({ render: () => h('div') }))
|
|
78
|
+
app.use(createM3UI({ palette: 'brand', customPalettes: [{ id: 'brand', label: 'Brand', seed: '#0b6e4f' }] }))
|
|
79
|
+
expect(document.documentElement.getAttribute('data-palette')).toBe('brand')
|
|
80
|
+
})
|
|
81
|
+
})
|
|
55
82
|
})
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { ref, watchEffect } from 'vue'
|
|
3
3
|
import JsBarcode from 'jsbarcode'
|
|
4
4
|
|
|
5
|
+
defineOptions({ inheritAttrs: false })
|
|
6
|
+
|
|
5
7
|
const props = withDefaults(
|
|
6
8
|
defineProps<{
|
|
7
9
|
value: string
|
|
@@ -54,8 +56,8 @@ watchEffect(() => {
|
|
|
54
56
|
</script>
|
|
55
57
|
|
|
56
58
|
<template>
|
|
57
|
-
<div v-if="error" class="flex items-center justify-center text-body-small text-error">
|
|
59
|
+
<div v-if="error" v-bind="$attrs" class="flex items-center justify-center text-body-small text-error">
|
|
58
60
|
<slot name="error">{{ error }}</slot>
|
|
59
61
|
</div>
|
|
60
|
-
<svg v-show="!error" ref="svgEl" role="img" :aria-label="label ?? value"></svg>
|
|
62
|
+
<svg v-show="!error" v-bind="error ? {} : $attrs" ref="svgEl" role="img" :aria-label="label ?? value"></svg>
|
|
61
63
|
</template>
|