@m3ui-vue/m3ui-vue 1.1.4 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/API.md +511 -34
- package/dist/MMenuItem-DI351kIf.js +929 -0
- package/dist/MMenuItem-DI351kIf.js.map +1 -0
- package/dist/{MSlider-JflHJ70q.js → MSlider-BnEy5ieZ.js} +295 -320
- package/dist/MSlider-BnEy5ieZ.js.map +1 -0
- package/dist/MTextField-BBmkaIbO.js +633 -0
- package/dist/MTextField-BBmkaIbO.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +83 -49
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MButton.vue.d.ts +7 -1
- package/dist/components/MButtonGroup.vue.d.ts +40 -31
- package/dist/components/MCarousel.vue.d.ts +2 -0
- package/dist/components/MChart.vue.d.ts +6 -0
- package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
- package/dist/components/MContextMenu.vue.d.ts +2 -2
- package/dist/components/MCopyButton.vue.d.ts +1 -1
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +13 -1
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MMap.vue.d.ts +20 -2
- package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
- package/dist/components/MMapFilter.vue.d.ts +3 -0
- package/dist/components/MMapLayers.vue.d.ts +3 -0
- package/dist/components/MMenu.vue.d.ts +2 -2
- package/dist/components/MMenuItem.vue.d.ts +7 -3
- package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
- package/dist/components/MOverlay.vue.d.ts +12 -1
- package/dist/components/MProgressBar.vue.d.ts +5 -3
- package/dist/components/MPullToRefresh.vue.d.ts +7 -2
- package/dist/components/MRichTextEditor.vue.d.ts +7 -1
- package/dist/components/MSearchField.vue.d.ts +58 -0
- package/dist/components/MSegmentedButton.vue.d.ts +31 -23
- package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
- package/dist/components/MSkeleton.vue.d.ts +6 -3
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTextField.vue.d.ts +5 -1
- package/dist/components/MTimeline.vue.d.ts +85 -22
- package/dist/components/MTooltip.vue.d.ts +1 -1
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/composables/_mapStyle.d.ts +13 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_tooltipTrigger.d.ts +22 -0
- package/dist/composables/_useMenuNav.d.ts +28 -0
- package/dist/composables/useAutoGrow.d.ts +21 -0
- package/dist/composables/useColorPalette.d.ts +1 -1
- package/dist/composables/useLocale.d.ts +3 -0
- package/dist/composables/useMap.d.ts +19 -3
- package/dist/composables/useMapFilter.d.ts +4 -1
- package/dist/composables/useMapLayers.d.ts +5 -2
- package/dist/composables/useScrollReveal.d.ts +44 -0
- package/dist/composables/useThemeTokens.d.ts +21 -0
- package/dist/composables/viewportHints.d.ts +27 -0
- package/dist/directives/vClickOutside.d.ts +25 -0
- package/dist/directives/vFocusRing.d.ts +22 -0
- package/dist/directives/vLongPress.d.ts +27 -0
- package/dist/directives/vReveal.d.ts +10 -0
- package/dist/directives/vScrollElevation.d.ts +31 -0
- package/dist/directives/vSkeleton.d.ts +19 -0
- package/dist/directives/vStateLayer.d.ts +20 -0
- package/dist/directives/vSwipe.d.ts +45 -0
- package/dist/directives/vTooltip.d.ts +23 -0
- package/dist/index.d.ts +28 -1
- package/dist/locales/index.js +21 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7132 -6217
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +1 -1
- package/dist/map.js +821 -791
- package/dist/map.js.map +1 -1
- package/dist/motion-DZiXG09o.js +150 -0
- package/dist/motion-DZiXG09o.js.map +1 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/rich-text-editor.js +13 -9
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles/theme.css +63 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-CXibICQA.js → useLocale-JYxDDeXC.js} +4 -2
- package/dist/useLocale-JYxDDeXC.js.map +1 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MButton.test.ts +22 -0
- package/src/__tests__/MCarousel.test.ts +9 -0
- package/src/__tests__/MChart.test.ts +77 -5
- package/src/__tests__/MIconButton.test.ts +33 -0
- package/src/__tests__/MMap.test.ts +53 -1
- package/src/__tests__/MMapLayers.test.ts +46 -2
- package/src/__tests__/MMenu.test.ts +104 -1
- package/src/__tests__/MMenuItem.test.ts +18 -0
- package/src/__tests__/MNavigationDrawer.test.ts +80 -0
- package/src/__tests__/MOverlay.test.ts +49 -0
- package/src/__tests__/MProgressBar.test.ts +41 -0
- package/src/__tests__/MPullToRefresh.test.ts +33 -0
- package/src/__tests__/MRichTextEditor.test.ts +22 -0
- package/src/__tests__/MSearchField.test.ts +71 -0
- package/src/__tests__/MSegmentedButton.test.ts +10 -0
- package/src/__tests__/MSkeleton.test.ts +38 -0
- package/src/__tests__/MTimeline.test.ts +238 -0
- package/src/__tests__/_fakeMaplibre.ts +3 -1
- package/src/__tests__/attrsFallthrough.test.ts +3 -0
- package/src/__tests__/escapeStack.test.ts +93 -0
- package/src/__tests__/ssr.test.ts +21 -2
- package/src/__tests__/useAutoGrow.test.ts +103 -0
- package/src/__tests__/useScrollReveal.test.ts +102 -0
- package/src/__tests__/useThemeTokens.test.ts +114 -0
- package/src/__tests__/vClickOutside.test.ts +82 -0
- package/src/__tests__/vFocusRing.test.ts +36 -0
- package/src/__tests__/vLongPress.test.ts +81 -0
- package/src/__tests__/vScrollElevation.test.ts +89 -0
- package/src/__tests__/vSkeleton.test.ts +48 -0
- package/src/__tests__/vStateLayer.test.ts +53 -0
- package/src/__tests__/vSwipe.test.ts +93 -0
- package/src/__tests__/vTooltip.test.ts +95 -0
- package/src/__tests__/viewportHints.test.ts +41 -0
- package/src/components/MAutocomplete.vue +5 -0
- package/src/components/MBottomSheet.vue +4 -1
- package/src/components/MButton.vue +15 -1
- package/src/components/MButtonGroup.vue +22 -17
- package/src/components/MCarousel.vue +7 -1
- package/src/components/MChart.vue +74 -34
- package/src/components/MCircleProgressBar.vue +14 -9
- package/src/components/MCommandPalette.vue +3 -2
- package/src/components/MContextMenu.vue +19 -60
- package/src/components/MDragDropList.vue +2 -0
- package/src/components/MIconButton.vue +40 -1
- package/src/components/MKanban.vue +2 -0
- package/src/components/MLightbox.vue +7 -2
- package/src/components/MMap.vue +38 -5
- package/src/components/MMapBaseLayers.vue +7 -3
- package/src/components/MMapFilter.vue +7 -4
- package/src/components/MMapGeoJson.vue +1 -1
- package/src/components/MMapLayers.vue +6 -2
- package/src/components/MMapMeasure.vue +5 -2
- package/src/components/MMenu.vue +18 -59
- package/src/components/MMenuItem.vue +11 -2
- package/src/components/MMultiAutocomplete.vue +5 -0
- package/src/components/MNavigationDrawer.vue +96 -11
- package/src/components/MNavigationRail.vue +4 -15
- package/src/components/MOverlay.vue +32 -13
- package/src/components/MProgressBar.vue +25 -27
- package/src/components/MPullToRefresh.vue +20 -1
- package/src/components/MRichTextEditor.vue +19 -5
- package/src/components/MSearchBar.vue +5 -0
- package/src/components/MSearchField.vue +142 -0
- package/src/components/MSegmentedButton.vue +20 -18
- package/src/components/MSelect.vue +10 -1
- package/src/components/MSideSheet.vue +5 -2
- package/src/components/MSimpleCarousel.vue +10 -1
- package/src/components/MSkeleton.vue +30 -8
- package/src/components/MSpotlightSearch.vue +3 -2
- package/src/components/MTextField.vue +15 -2
- package/src/components/MTimeline.vue +370 -81
- package/src/components/MTooltip.vue +20 -152
- package/src/components/_MDrawerItemList.vue +25 -6
- package/src/composables/_mapStyle.ts +45 -0
- package/src/composables/_themeTransition.ts +2 -0
- package/src/composables/_tooltipTrigger.ts +184 -0
- package/src/composables/_useMenuNav.ts +209 -0
- package/src/composables/useAutoGrow.ts +78 -0
- package/src/composables/useLocale.ts +5 -0
- package/src/composables/useMap.ts +43 -5
- package/src/composables/useMapFilter.ts +6 -5
- package/src/composables/useMapLayers.ts +7 -6
- package/src/composables/useScrollReveal.ts +151 -0
- package/src/composables/useThemeTokens.ts +116 -0
- package/src/composables/viewportHints.ts +80 -0
- package/src/directives/vClickOutside.ts +90 -0
- package/src/directives/vFocusRing.ts +60 -0
- package/src/directives/vLongPress.ts +134 -0
- package/src/directives/vReveal.ts +57 -0
- package/src/directives/vScrollElevation.ts +116 -0
- package/src/directives/vSkeleton.ts +87 -0
- package/src/directives/vStateLayer.ts +83 -0
- package/src/directives/vSwipe.ts +197 -0
- package/src/directives/vTooltip.ts +128 -0
- package/src/index.ts +28 -1
- package/src/locales/de.ts +2 -0
- package/src/locales/es.ts +2 -0
- package/src/locales/fr.ts +2 -0
- package/src/locales/ja.ts +2 -0
- package/src/locales/ko.ts +2 -0
- package/src/locales/pt.ts +2 -0
- package/src/locales/zh.ts +2 -0
- package/src/map.ts +1 -1
- package/src/plugin.ts +34 -0
- package/src/styles/theme.css +63 -0
- package/dist/MMenuItem-BfjqwcYP.js +0 -830
- package/dist/MMenuItem-BfjqwcYP.js.map +0 -1
- package/dist/MSlider-JflHJ70q.js.map +0 -1
- package/dist/MTextField-NaIB6RbM.js +0 -673
- package/dist/MTextField-NaIB6RbM.js.map +0 -1
- package/dist/composables/_useThemeTokens.d.ts +0 -7
- package/dist/useLocale-CXibICQA.js.map +0 -1
- package/src/composables/_useThemeTokens.ts +0 -42
|
@@ -19,10 +19,12 @@ beforeEach(() => {
|
|
|
19
19
|
afterEach(() => { document.body.innerHTML = '' })
|
|
20
20
|
|
|
21
21
|
/** Mounts an MMap, waits for MapLibre to "load" and the slot to render. */
|
|
22
|
-
async function mountMap(props: Record<string, unknown> = {}, slot?: () => unknown) {
|
|
22
|
+
async function mountMap(props: Record<string, unknown> = {}, slot?: () => unknown, style?: FakeMap['style']) {
|
|
23
23
|
const wrapper = mount(MMap, { props: { mapStyle: 'https://tiles.test/style.json', ...props }, slots: slot ? { default: slot } : {}, attachTo: document.body })
|
|
24
24
|
await flushPromises()
|
|
25
25
|
const map = created.maps.at(-1)!
|
|
26
|
+
// What getStyle() returns once the first style loads
|
|
27
|
+
if (style) map.style = style
|
|
26
28
|
map.load()
|
|
27
29
|
await nextTick()
|
|
28
30
|
await nextTick()
|
|
@@ -420,3 +422,53 @@ describe('useMap', () => {
|
|
|
420
422
|
expect(() => mount(defineComponent({ setup() { useMap(); return () => null } }))).toThrow(/inside <MMap>/)
|
|
421
423
|
})
|
|
422
424
|
})
|
|
425
|
+
|
|
426
|
+
describe('keepLayers', () => {
|
|
427
|
+
type Style = import('maplibre-gl').StyleSpecification
|
|
428
|
+
const base = (name: string): Style => ({
|
|
429
|
+
version: 8,
|
|
430
|
+
sources: { [`${name}-tiles`]: { type: 'vector', url: `https://tiles.test/${name}` } },
|
|
431
|
+
layers: [{ id: `${name}-bg`, type: 'background' }],
|
|
432
|
+
})
|
|
433
|
+
// The light style as it is after runtime additions: its own plus a zones source/layer and a measure layer
|
|
434
|
+
const runtime = (): Style => {
|
|
435
|
+
const s = base('light')
|
|
436
|
+
return {
|
|
437
|
+
...s,
|
|
438
|
+
sources: { ...s.sources, zones: { type: 'geojson', data: { type: 'FeatureCollection', features: [] } } },
|
|
439
|
+
layers: [...s.layers, { id: 'zones-fill', type: 'fill', source: 'zones' }, { id: 'measure-line', type: 'line', source: 'zones' }],
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async function switchStyle(props: Record<string, unknown> = {}) {
|
|
444
|
+
const { wrapper, map } = await mountMap({ mapStyle: 'light', ...props }, undefined, base('light') as never)
|
|
445
|
+
await wrapper.setProps({ mapStyle: 'dark' })
|
|
446
|
+
const transform = map.styleOptions.at(-1)!.transformStyle!
|
|
447
|
+
return { wrapper, map, result: transform(runtime(), base('dark')) as Style, transform }
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
it('carries runtime sources and layers into the new style, on top', async () => {
|
|
451
|
+
const { result } = await switchStyle()
|
|
452
|
+
expect(result.layers.map((l) => l.id)).toEqual(['dark-bg', 'zones-fill', 'measure-line'])
|
|
453
|
+
expect(Object.keys(result.sources)).toEqual(['dark-tiles', 'zones'])
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
it('picks layers with a function, drops them with false, and runs transformStyle after', async () => {
|
|
457
|
+
const picked = await switchStyle({ keepLayers: (l: { id: string }) => l.id.startsWith('zones') })
|
|
458
|
+
expect(picked.result.layers.map((l) => l.id)).toEqual(['dark-bg', 'zones-fill'])
|
|
459
|
+
|
|
460
|
+
const dropped = await switchStyle({ keepLayers: false })
|
|
461
|
+
expect(dropped.result.layers.map((l) => l.id)).toEqual(['dark-bg'])
|
|
462
|
+
|
|
463
|
+
const custom = await switchStyle({ transformStyle: (_p: unknown, next: Style) => ({ ...next, name: 'tweaked' }) })
|
|
464
|
+
expect(custom.result.name).toBe('tweaked')
|
|
465
|
+
expect(custom.result.layers.map((l) => l.id)).toContain('zones-fill')
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
it('counts a carried layer as runtime again on the next switch', async () => {
|
|
469
|
+
const { wrapper, map, result } = await switchStyle()
|
|
470
|
+
await wrapper.setProps({ mapStyle: 'light' })
|
|
471
|
+
const back = map.styleOptions.at(-1)!.transformStyle!(result, base('light')) as Style
|
|
472
|
+
expect(back.layers.map((l) => l.id)).toEqual(['light-bg', 'zones-fill', 'measure-line'])
|
|
473
|
+
})
|
|
474
|
+
})
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
2
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
3
|
-
import { defineComponent, h, nextTick } from 'vue'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
4
|
import type { StyleSpecification } from 'maplibre-gl'
|
|
5
5
|
import { created, type FakeMap } from './_fakeMaplibre'
|
|
6
6
|
|
|
7
7
|
vi.mock('maplibre-gl', async () => (await import('./_fakeMaplibre')).fakeModule)
|
|
8
8
|
|
|
9
|
-
const { MMap, MMapLayers, MMapBaseLayers, MMapIdentify, MMapHover, useMapLayers, orvianAdapter, genericAdapter, formatFieldValue, identifyFeatures } = await import('../map')
|
|
9
|
+
const { MMap, MMapLayers, MMapBaseLayers, MMapIdentify, MMapHover, MMapFilter, useMap, useMapLayers, orvianAdapter, genericAdapter, formatFieldValue, identifyFeatures } = await import('../map')
|
|
10
10
|
|
|
11
11
|
// A style the way the Orvian viewers write it (served by mvt-rs)
|
|
12
12
|
const STYLE_URL = 'https://tiles.test/services/styles/public:city'
|
|
@@ -189,6 +189,50 @@ describe('MMapBaseLayers', () => {
|
|
|
189
189
|
})
|
|
190
190
|
})
|
|
191
191
|
|
|
192
|
+
describe('outside the map', () => {
|
|
193
|
+
// A side panel next to the map: the MMap's template ref reaches the panels through their `map` prop
|
|
194
|
+
async function mountBeside() {
|
|
195
|
+
const mapRef = ref()
|
|
196
|
+
let api!: ReturnType<typeof useMap>
|
|
197
|
+
const Own = defineComponent({ props: { map: Object }, setup(props) { api = useMap(() => props.map as never); return () => null } })
|
|
198
|
+
const wrapper = mount(defineComponent({
|
|
199
|
+
setup: () => () => h('div', [
|
|
200
|
+
h('aside', [
|
|
201
|
+
h(MMapLayers, { map: mapRef.value, search: false }),
|
|
202
|
+
h(MMapBaseLayers, { map: mapRef.value }),
|
|
203
|
+
h(MMapFilter, { map: mapRef.value, layer: 'poi', property: 'kind', values: ['cafe', 'park'] }),
|
|
204
|
+
h(Own, { map: mapRef.value }),
|
|
205
|
+
]),
|
|
206
|
+
h(MMap, { ref: mapRef, mapStyle: STYLE_URL, adapter: orvianAdapter() }),
|
|
207
|
+
]),
|
|
208
|
+
}), { attachTo: document.body })
|
|
209
|
+
await flushPromises()
|
|
210
|
+
const map = created.maps.at(-1)! as FakeMap
|
|
211
|
+
map.style = orvianStyle() as never
|
|
212
|
+
map.load()
|
|
213
|
+
await nextTick()
|
|
214
|
+
await nextTick()
|
|
215
|
+
return { wrapper, map, api: () => api }
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
it('MMapLayers, MMapBaseLayers and MMapFilter work from a panel beside the map', async () => {
|
|
219
|
+
const { wrapper, map } = await mountBeside()
|
|
220
|
+
const panel = wrapper.find('aside')
|
|
221
|
+
expect(panel.text()).toContain('Parcels')
|
|
222
|
+
await panel.find('button[aria-label="Hide layer"]').trigger('click')
|
|
223
|
+
expect(map.getLayoutProperty('parcels', 'visibility')).toBe('none')
|
|
224
|
+
await panel.find('button[aria-label="Satellite"]').trigger('click')
|
|
225
|
+
expect(map.getLayoutProperty('sat', 'visibility')).toBe('visible')
|
|
226
|
+
await panel.findAll('button').find((b) => b.text().includes('cafe'))!.trigger('click')
|
|
227
|
+
expect(map.getFilter('poi')).toEqual(['in', ['get', 'kind'], ['literal', ['cafe']]])
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('useMap() takes the map too, empty until it mounts', async () => {
|
|
231
|
+
const { map, api } = await mountBeside()
|
|
232
|
+
expect(api().map.value).toBe(map)
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
|
|
192
236
|
describe('identify', () => {
|
|
193
237
|
it('lists the identify layers\' features under a point, formatted, minus hidden and excluded properties', async () => {
|
|
194
238
|
const { map } = await mountWithLayers()
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest'
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
2
2
|
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
3
3
|
import { mount } from '@vue/test-utils'
|
|
4
4
|
import MMenu from '../components/MMenu.vue'
|
|
5
5
|
import MContextMenu from '../components/MContextMenu.vue'
|
|
6
|
+
import MMenuItem from '../components/MMenuItem.vue'
|
|
6
7
|
|
|
7
8
|
const frame = () => new Promise<void>((r) => requestAnimationFrame(() => r()))
|
|
8
9
|
// Long enough for the open spring to finish, so the close has real distance to cover
|
|
@@ -44,6 +45,75 @@ describe('MMenu', () => {
|
|
|
44
45
|
|
|
45
46
|
expect(document.querySelector('.item')).toBeNull()
|
|
46
47
|
})
|
|
48
|
+
|
|
49
|
+
describe('push submenus: swipe back', () => {
|
|
50
|
+
let wrapper: ReturnType<typeof mount> | null = null
|
|
51
|
+
afterEach(() => { wrapper?.unmount(); wrapper = null })
|
|
52
|
+
const finishAnimations = () => document.querySelectorAll('*').forEach((el) => el.getAnimations().forEach((a) => a.finish()))
|
|
53
|
+
|
|
54
|
+
async function openSubmenu() {
|
|
55
|
+
wrapper = mount(
|
|
56
|
+
defineComponent({
|
|
57
|
+
setup: () => () =>
|
|
58
|
+
h(MMenu, { submenuMode: 'push' }, {
|
|
59
|
+
trigger: () => h('button', { class: 'trigger' }, 'open'),
|
|
60
|
+
default: () => h(MMenuItem, null, {
|
|
61
|
+
default: () => 'Share',
|
|
62
|
+
children: () => h('span', { class: 'leaf' }, 'Email'),
|
|
63
|
+
}),
|
|
64
|
+
}),
|
|
65
|
+
}),
|
|
66
|
+
{ attachTo: document.body, global: { stubs: { transition: false } } },
|
|
67
|
+
)
|
|
68
|
+
document.querySelector<HTMLElement>('.trigger')!.click()
|
|
69
|
+
await nextTick()
|
|
70
|
+
await settle()
|
|
71
|
+
document.querySelector<HTMLElement>('[aria-haspopup="menu"]')!.click()
|
|
72
|
+
await nextTick()
|
|
73
|
+
const level = document.querySelector<HTMLElement>('[data-menu-level="1"]')!
|
|
74
|
+
const box = level.parentElement!
|
|
75
|
+
Object.defineProperty(box, 'clientWidth', { value: 300, configurable: true })
|
|
76
|
+
return { box }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function swipe(box: HTMLElement, to: number, steps = 6) {
|
|
80
|
+
const at = (type: string, x: number, target: EventTarget) =>
|
|
81
|
+
target.dispatchEvent(new PointerEvent(type, { pointerId: 1, pointerType: 'touch', clientX: x, clientY: 100, bubbles: true }))
|
|
82
|
+
at('pointerdown', 20, box)
|
|
83
|
+
for (let i = 1; i <= steps; i++) at('pointermove', 20 + (to - 20) * i / steps, window)
|
|
84
|
+
at('pointerup', to, window)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
it('goes back to the parent level when swiped past a third of the panel', async () => {
|
|
88
|
+
const { box } = await openSubmenu()
|
|
89
|
+
expect(document.querySelector('.leaf')).not.toBeNull()
|
|
90
|
+
expect(box.style.touchAction).toBe('pan-y')
|
|
91
|
+
swipe(box, 160)
|
|
92
|
+
await nextTick()
|
|
93
|
+
finishAnimations()
|
|
94
|
+
await nextTick()
|
|
95
|
+
expect(document.querySelector('[data-menu-level]')).toBeNull()
|
|
96
|
+
expect(document.querySelector('[aria-haspopup="menu"]')).not.toBeNull()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('stays on the submenu after a short, slow swipe, and ignores a mouse drag', async () => {
|
|
100
|
+
const { box } = await openSubmenu()
|
|
101
|
+
const at = (type: string, x: number, target: EventTarget, t: number) =>
|
|
102
|
+
target.dispatchEvent(new PointerEvent(type, { pointerId: 1, pointerType: 'touch', clientX: x, clientY: 100, bubbles: true, timeStamp: t } as PointerEventInit))
|
|
103
|
+
at('pointerdown', 20, box, 0)
|
|
104
|
+
at('pointermove', 40, window, 500)
|
|
105
|
+
at('pointermove', 50, window, 1000)
|
|
106
|
+
at('pointerup', 50, window, 1500)
|
|
107
|
+
await nextTick()
|
|
108
|
+
expect(document.querySelector('[data-menu-level="1"]')).not.toBeNull()
|
|
109
|
+
|
|
110
|
+
box.dispatchEvent(new PointerEvent('pointerdown', { pointerId: 2, pointerType: 'mouse', clientX: 20, clientY: 100, bubbles: true }))
|
|
111
|
+
window.dispatchEvent(new PointerEvent('pointermove', { pointerId: 2, pointerType: 'mouse', clientX: 250, clientY: 100 }))
|
|
112
|
+
window.dispatchEvent(new PointerEvent('pointerup', { pointerId: 2, pointerType: 'mouse', clientX: 250, clientY: 100 }))
|
|
113
|
+
await nextTick()
|
|
114
|
+
expect(document.querySelector('[data-menu-level="1"]')).not.toBeNull()
|
|
115
|
+
})
|
|
116
|
+
})
|
|
47
117
|
})
|
|
48
118
|
|
|
49
119
|
describe('MContextMenu', () => {
|
|
@@ -82,3 +152,36 @@ describe('MContextMenu', () => {
|
|
|
82
152
|
expect(document.querySelector('.item')).toBeNull()
|
|
83
153
|
})
|
|
84
154
|
})
|
|
155
|
+
|
|
156
|
+
describe('menus on the Escape stack', () => {
|
|
157
|
+
beforeEach(() => {
|
|
158
|
+
document.body.innerHTML = ''
|
|
159
|
+
})
|
|
160
|
+
const escape = () => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', cancelable: true }))
|
|
161
|
+
|
|
162
|
+
it('a menu open in a dialog takes Escape alone; the next one closes the dialog', async () => {
|
|
163
|
+
const { default: MDialog } = await import('../components/MDialog.vue')
|
|
164
|
+
const dialog = mount(MDialog, {
|
|
165
|
+
props: { modelValue: true, title: 'T' },
|
|
166
|
+
slots: {
|
|
167
|
+
default: () =>
|
|
168
|
+
h(MMenu, null, {
|
|
169
|
+
trigger: () => h('button', { class: 'trigger' }, 'open'),
|
|
170
|
+
default: () => h('span', { class: 'item' }, 'Copy'),
|
|
171
|
+
}),
|
|
172
|
+
},
|
|
173
|
+
attachTo: document.body,
|
|
174
|
+
})
|
|
175
|
+
await nextTick()
|
|
176
|
+
document.querySelector<HTMLElement>('.trigger')!.click()
|
|
177
|
+
await nextTick()
|
|
178
|
+
|
|
179
|
+
escape()
|
|
180
|
+
await nextTick()
|
|
181
|
+
expect(dialog.emitted('update:modelValue')).toBeUndefined()
|
|
182
|
+
|
|
183
|
+
escape()
|
|
184
|
+
expect(dialog.emitted('update:modelValue')).toEqual([[false]])
|
|
185
|
+
dialog.unmount()
|
|
186
|
+
})
|
|
187
|
+
})
|
|
@@ -81,4 +81,22 @@ describe('MMenuItem', () => {
|
|
|
81
81
|
const filled = inMenu({ selected: true, icon: 'star' }).button.find('.material-symbols-outlined')
|
|
82
82
|
expect(filled.attributes('style')).toContain('FILL')
|
|
83
83
|
})
|
|
84
|
+
|
|
85
|
+
it('renders the #icon slot in the icon box, with its color and the on state', () => {
|
|
86
|
+
const w = mount(MMenuItem, {
|
|
87
|
+
props: { icon: 'flip', selected: true },
|
|
88
|
+
slots: { default: 'Flip vertical', icon: (p: { on: boolean }) => h('i', { class: 'custom', 'data-on': String(p.on) }) },
|
|
89
|
+
})
|
|
90
|
+
const box = w.find('.custom').element.parentElement!
|
|
91
|
+
expect(box.className).toContain('size-5')
|
|
92
|
+
expect(w.find('.custom').attributes('data-on')).toBe('true')
|
|
93
|
+
// the slot replaces the icon prop's MIcon
|
|
94
|
+
expect(w.find('button').text()).not.toContain('flip')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('keeps the #icon slot instead of the sliding check on a selectable item', () => {
|
|
98
|
+
const w = mount(MMenuItem, { props: { selected: false }, slots: { default: 'A', icon: '<i class="custom" />' } })
|
|
99
|
+
expect(w.find('.custom').exists()).toBe(true)
|
|
100
|
+
expect(w.text()).not.toContain('check')
|
|
101
|
+
})
|
|
84
102
|
})
|
|
@@ -183,3 +183,83 @@ describe('MNavigationDrawer swipe to close', () => {
|
|
|
183
183
|
vi.unstubAllGlobals()
|
|
184
184
|
})
|
|
185
185
|
})
|
|
186
|
+
|
|
187
|
+
describe('MNavigationDrawer open groups', () => {
|
|
188
|
+
const groups = [{
|
|
189
|
+
items: [
|
|
190
|
+
{ value: 'mail', label: 'Mail', children: [{ value: 'inbox', label: 'Inbox' }, { value: 'sent', label: 'Sent' }] },
|
|
191
|
+
{ value: 'files', label: 'Files', children: [
|
|
192
|
+
{ value: 'docs', label: 'Docs', children: [{ value: 'report', label: 'Report' }] },
|
|
193
|
+
] },
|
|
194
|
+
],
|
|
195
|
+
}]
|
|
196
|
+
const openItems = () => (wrapper!.vm as unknown as { openItems: Record<string, boolean> }).openItems
|
|
197
|
+
|
|
198
|
+
function inline(props: Record<string, unknown> = {}) {
|
|
199
|
+
wrapper = mount(MNavigationDrawer, { props: { modelValue: true, modal: false, sections: groups, ...props } })
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
it('opens every group that holds the selected item', () => {
|
|
203
|
+
inline({ selected: 'report' })
|
|
204
|
+
expect(openItems()).toMatchObject({ files: true, docs: true })
|
|
205
|
+
expect(openItems().mail).toBeFalsy()
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it('follows selected, leaving other groups open unless accordion', async () => {
|
|
209
|
+
inline({ selected: 'inbox' })
|
|
210
|
+
await wrapper!.setProps({ selected: 'report' })
|
|
211
|
+
expect(openItems()).toMatchObject({ mail: true, files: true, docs: true })
|
|
212
|
+
|
|
213
|
+
wrapper!.unmount()
|
|
214
|
+
inline({ selected: 'inbox', accordion: true })
|
|
215
|
+
await wrapper!.setProps({ selected: 'report' })
|
|
216
|
+
expect(openItems()).toMatchObject({ mail: false, files: true, docs: true })
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('accordion closes the siblings of a group opened by hand', async () => {
|
|
220
|
+
inline({ accordion: true, selected: 'inbox' })
|
|
221
|
+
const files = wrapper!.findAll('button').find((b) => b.text().includes('Files'))!
|
|
222
|
+
await files.trigger('click')
|
|
223
|
+
expect(openItems()).toMatchObject({ mail: false, files: true })
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
it('leaves groups alone with expandSelected false', () => {
|
|
227
|
+
inline({ selected: 'report', expandSelected: false })
|
|
228
|
+
expect(openItems().files).toBeFalsy()
|
|
229
|
+
})
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
describe('MNavigationDrawer collapsedLabels', () => {
|
|
233
|
+
const tree = [{
|
|
234
|
+
items: [
|
|
235
|
+
{ value: 'inbox', label: 'Inbox', icon: 'inbox', badge: 4 },
|
|
236
|
+
{ value: 'labels', label: 'Labels', icon: 'label', badge: 'New', children: [{ value: 'work', label: 'Work', icon: 'work' }] },
|
|
237
|
+
],
|
|
238
|
+
}]
|
|
239
|
+
const mountInline = (props: Record<string, unknown> = {}) =>
|
|
240
|
+
(wrapper = mount(MNavigationDrawer, { props: { modelValue: true, modal: false, sections: tree, selected: 'work', ...props } }))
|
|
241
|
+
|
|
242
|
+
it('shows each label under its icon, nested items included, with the selection on the pill', () => {
|
|
243
|
+
const w = mountInline({ collapsed: true, collapsedLabels: true })
|
|
244
|
+
expect(w.find('nav').classes()).toContain('nd-rail')
|
|
245
|
+
expect(w.findAll('.nd-rail-label').map((l) => l.text())).toEqual(['Inbox', 'Labels', 'Work'])
|
|
246
|
+
const work = w.findAll('button').find((b) => b.text().includes('Work'))!
|
|
247
|
+
expect(work.classes()).not.toContain('bg-secondary-container')
|
|
248
|
+
expect(work.find('span[aria-hidden="true"]').classes()).toContain('bg-secondary-container')
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
it('puts badges on the icon when collapsed: a number as a count, text as a dot', () => {
|
|
252
|
+
const w = mountInline({ collapsed: true })
|
|
253
|
+
const badges = w.findAll('.bg-error')
|
|
254
|
+
expect(badges.map((b) => b.text())).toEqual(['4', ''])
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('keeps the row look when expanded or without the prop', () => {
|
|
258
|
+
const expanded = mountInline({ collapsed: false, collapsedLabels: true })
|
|
259
|
+
expect(expanded.find('nav').classes()).not.toContain('nd-rail')
|
|
260
|
+
expect(expanded.findAll('button').find((b) => b.text().includes('Work'))!.classes()).toContain('bg-secondary-container')
|
|
261
|
+
expanded.unmount()
|
|
262
|
+
const plain = mountInline({ collapsed: true })
|
|
263
|
+
expect(plain.findAll('.nd-rail-label')).toHaveLength(0)
|
|
264
|
+
})
|
|
265
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import MOverlay from '../components/MOverlay.vue'
|
|
4
|
+
import MDialog from '../components/MDialog.vue'
|
|
5
|
+
|
|
6
|
+
let wrappers: VueWrapper[] = []
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrappers.forEach((w) => w.unmount())
|
|
9
|
+
wrappers = []
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
document.body.style.overflow = ''
|
|
12
|
+
})
|
|
13
|
+
const open = (props: Record<string, unknown> = {}) => {
|
|
14
|
+
const w = mount(MOverlay, { props: { modelValue: true, ...props }, attachTo: document.body })
|
|
15
|
+
wrappers.push(w)
|
|
16
|
+
return w
|
|
17
|
+
}
|
|
18
|
+
const escape = () => document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', cancelable: true }))
|
|
19
|
+
|
|
20
|
+
describe('MOverlay', () => {
|
|
21
|
+
it('ignores Escape and leaves the scroll alone by default', () => {
|
|
22
|
+
const w = open()
|
|
23
|
+
escape()
|
|
24
|
+
expect(w.emitted('update:modelValue')).toBeUndefined()
|
|
25
|
+
expect(document.body.style.overflow).toBe('')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('closes on Escape with closeOnEscape', () => {
|
|
29
|
+
const w = open({ closeOnEscape: true })
|
|
30
|
+
escape()
|
|
31
|
+
expect(w.emitted('update:modelValue')).toEqual([[false]])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('leaves Escape to a dialog opened over it', () => {
|
|
35
|
+
const w = open({ closeOnEscape: true })
|
|
36
|
+
const d = mount(MDialog, { props: { modelValue: true, title: 'T' }, attachTo: document.body })
|
|
37
|
+
wrappers.push(d)
|
|
38
|
+
escape()
|
|
39
|
+
expect(d.emitted('update:modelValue')).toEqual([[false]])
|
|
40
|
+
expect(w.emitted('update:modelValue')).toBeUndefined()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('locks the page scroll while open with lockScroll', async () => {
|
|
44
|
+
const w = open({ lockScroll: true })
|
|
45
|
+
expect(document.body.style.overflow).toBe('hidden')
|
|
46
|
+
await w.setProps({ modelValue: false })
|
|
47
|
+
expect(document.body.style.overflow).toBe('')
|
|
48
|
+
})
|
|
49
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MProgressBar from '../components/MProgressBar.vue'
|
|
4
|
+
import MCircleProgressBar from '../components/MCircleProgressBar.vue'
|
|
5
|
+
|
|
6
|
+
const vars = (el: Element) => {
|
|
7
|
+
const s = (el as HTMLElement).style
|
|
8
|
+
return { bar: s.getPropertyValue('--m3-progress-bar'), track: s.getPropertyValue('--m3-progress-track') }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('MProgressBar colors', () => {
|
|
12
|
+
it('uses the role and its container by default', () => {
|
|
13
|
+
const w = mount(MProgressBar, { props: { value: 40, color: 'tertiary' } })
|
|
14
|
+
expect(vars(w.element)).toEqual({ bar: 'var(--color-tertiary)', track: 'var(--color-tertiary-container)' })
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('takes any CSS color, with a translucent track of it', () => {
|
|
18
|
+
const w = mount(MProgressBar, { props: { value: 40, color: '#fff' } })
|
|
19
|
+
expect(vars(w.element)).toEqual({ bar: '#fff', track: 'color-mix(in srgb, #fff 24%, transparent)' })
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('takes a track color as a role or a CSS color', () => {
|
|
23
|
+
expect(vars(mount(MProgressBar, { props: { value: 40, trackColor: 'rgb(255 255 255 / 0.35)' } }).element).track).toBe('rgb(255 255 255 / 0.35)')
|
|
24
|
+
expect(vars(mount(MProgressBar, { props: { value: 40, trackColor: 'secondary-container' } }).element).track).toBe('var(--color-secondary-container)')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('paints the bar and track from those variables', () => {
|
|
28
|
+
const w = mount(MProgressBar, { props: { value: 40 } })
|
|
29
|
+
expect(w.find('.bg-\\(--m3-progress-bar\\)').exists()).toBe(true)
|
|
30
|
+
expect(w.find('.bg-\\(--m3-progress-track\\)').exists()).toBe(true)
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('MCircleProgressBar colors', () => {
|
|
35
|
+
it('takes any CSS color for the ring and track', () => {
|
|
36
|
+
const w = mount(MCircleProgressBar, { props: { value: 40, color: '#fff', trackColor: 'transparent' } })
|
|
37
|
+
const strokes = w.findAll('circle, path').map((c) => (c.element as SVGElement).style.stroke).filter(Boolean)
|
|
38
|
+
expect(strokes).toContain('#fff')
|
|
39
|
+
expect(strokes).toContain('transparent')
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -121,3 +121,36 @@ describe('MPullToRefresh (mouse)', () => {
|
|
|
121
121
|
vi.unstubAllGlobals()
|
|
122
122
|
})
|
|
123
123
|
})
|
|
124
|
+
|
|
125
|
+
describe('MPullToRefresh (scroll)', () => {
|
|
126
|
+
it('exposes its scrolling element and scrollTo', () => {
|
|
127
|
+
const { wrapper, scrollEl } = mountPtr()
|
|
128
|
+
const vm = wrapper.vm as unknown as { scrollEl: HTMLElement; scrollTo: (o: ScrollToOptions) => void }
|
|
129
|
+
expect(vm.scrollEl).toBe(scrollEl)
|
|
130
|
+
const spy = vi.fn()
|
|
131
|
+
;(scrollEl as HTMLElement).scrollTo = spy
|
|
132
|
+
vm.scrollTo({ top: 0, behavior: 'smooth' })
|
|
133
|
+
expect(spy).toHaveBeenCalledWith({ top: 0, behavior: 'smooth' })
|
|
134
|
+
wrapper.unmount()
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('restores its scroll position when a <KeepAlive> brings it back', async () => {
|
|
138
|
+
const { defineComponent, h, KeepAlive, ref, nextTick } = await import('vue')
|
|
139
|
+
const show = ref(true)
|
|
140
|
+
const Other = defineComponent({ render: () => h('p', 'other') })
|
|
141
|
+
const Host = defineComponent({
|
|
142
|
+
setup: () => () => h(KeepAlive, null, [show.value ? h(MPullToRefresh, null, () => h('div', 'list')) : h(Other)]),
|
|
143
|
+
})
|
|
144
|
+
const wrapper = mount(Host, { attachTo: document.body })
|
|
145
|
+
const el = wrapper.find('.overflow-y-auto').element as HTMLElement
|
|
146
|
+
el.scrollTop = 300
|
|
147
|
+
el.dispatchEvent(new Event('scroll'))
|
|
148
|
+
show.value = false
|
|
149
|
+
await nextTick()
|
|
150
|
+
el.scrollTop = 0 // what a detached element reports
|
|
151
|
+
show.value = true
|
|
152
|
+
await nextTick()
|
|
153
|
+
expect(el.scrollTop).toBe(300)
|
|
154
|
+
wrapper.unmount()
|
|
155
|
+
})
|
|
156
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MRichTextEditor from '../components/MRichTextEditor.vue'
|
|
4
|
+
|
|
5
|
+
describe('MRichTextEditor fill', () => {
|
|
6
|
+
it('grows with its content by default, from minHeight', () => {
|
|
7
|
+
const w = mount(MRichTextEditor, { props: { modelValue: '', minHeight: '120px' } })
|
|
8
|
+
const content = w.find('.rte-content')
|
|
9
|
+
expect((content.element as HTMLElement).style.minHeight).toBe('120px')
|
|
10
|
+
expect(content.classes()).not.toContain('overflow-y-auto')
|
|
11
|
+
w.unmount()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('fills its height and scrolls the text inside with fill', () => {
|
|
15
|
+
const w = mount(MRichTextEditor, { props: { modelValue: '', fill: true } })
|
|
16
|
+
expect(w.classes()).toContain('flex-col')
|
|
17
|
+
const content = w.find('.rte-content')
|
|
18
|
+
expect(content.classes()).toEqual(expect.arrayContaining(['flex-1', 'min-h-0', 'overflow-y-auto']))
|
|
19
|
+
expect((content.element as HTMLElement).style.minHeight).toBe('')
|
|
20
|
+
w.unmount()
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MSearchField from '../components/MSearchField.vue'
|
|
4
|
+
|
|
5
|
+
describe('MSearchField', () => {
|
|
6
|
+
it('works with v-model and emits search on Enter', async () => {
|
|
7
|
+
const w = mount(MSearchField, { props: { modelValue: '' } })
|
|
8
|
+
const input = w.find('input')
|
|
9
|
+
await input.setValue('lamp')
|
|
10
|
+
expect(w.emitted('update:modelValue')).toEqual([['lamp']])
|
|
11
|
+
await w.setProps({ modelValue: 'lamp' })
|
|
12
|
+
await input.trigger('keydown', { key: 'Enter' })
|
|
13
|
+
expect(w.emitted('search')).toEqual([['lamp']])
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('clears with the button, which shows only while there is text', async () => {
|
|
17
|
+
const w = mount(MSearchField, { props: { modelValue: '' } })
|
|
18
|
+
expect(w.find('button').exists()).toBe(false)
|
|
19
|
+
await w.setProps({ modelValue: 'x' })
|
|
20
|
+
await w.find('button').trigger('click')
|
|
21
|
+
expect(w.emitted('update:modelValue')).toEqual([['']])
|
|
22
|
+
expect(w.emitted('clear')).toHaveLength(1)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('Escape empties it first and keeps the event from reaching the document', async () => {
|
|
26
|
+
const w = mount(MSearchField, { props: { modelValue: 'x' }, attachTo: document.body })
|
|
27
|
+
let reached = false
|
|
28
|
+
const spy = () => (reached = true)
|
|
29
|
+
document.addEventListener('keydown', spy)
|
|
30
|
+
w.find('input').element.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }))
|
|
31
|
+
document.removeEventListener('keydown', spy)
|
|
32
|
+
expect(w.emitted('update:modelValue')).toEqual([['']])
|
|
33
|
+
expect(reached).toBe(false)
|
|
34
|
+
w.unmount()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('lets Escape through once the field is empty', () => {
|
|
38
|
+
const w = mount(MSearchField, { props: { modelValue: '' }, attachTo: document.body })
|
|
39
|
+
let reached = false
|
|
40
|
+
const spy = () => (reached = true)
|
|
41
|
+
document.addEventListener('keydown', spy)
|
|
42
|
+
w.find('input').element.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }))
|
|
43
|
+
document.removeEventListener('keydown', spy)
|
|
44
|
+
expect(reached).toBe(true)
|
|
45
|
+
expect(w.emitted('clear')).toBeUndefined()
|
|
46
|
+
w.unmount()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('puts class and style on the pill, other attributes on the input', () => {
|
|
50
|
+
const w = mount(MSearchField, { attrs: { class: 'bg-surface-container-highest', name: 'q', 'aria-describedby': 'hint' } })
|
|
51
|
+
expect(w.classes()).toContain('bg-surface-container-highest')
|
|
52
|
+
expect(w.classes()).toContain('m3-search-field-lg')
|
|
53
|
+
const input = w.find('input')
|
|
54
|
+
expect(input.attributes('name')).toBe('q')
|
|
55
|
+
expect(input.attributes('aria-describedby')).toBe('hint')
|
|
56
|
+
expect(w.attributes('name')).toBeUndefined()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('defaults the placeholder and accessible name to the locale', () => {
|
|
60
|
+
const input = mount(MSearchField).find('input')
|
|
61
|
+
expect(input.attributes('placeholder')).toBe('Search...')
|
|
62
|
+
expect(input.attributes('aria-label')).toBe('Search...')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('spaces a slotted leading button like M3 (8px in), and keeps 16px with the default icon', () => {
|
|
66
|
+
expect(mount(MSearchField).classes()).not.toContain('m3-search-field-slotted')
|
|
67
|
+
const w = mount(MSearchField, { slots: { leading: '<button class="menu">m</button>' } })
|
|
68
|
+
expect(w.classes()).toContain('m3-search-field-slotted')
|
|
69
|
+
expect(w.find('.menu').element.parentElement!.className).toContain('-me-2')
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MSegmentedButton from '../components/MSegmentedButton.vue'
|
|
4
|
+
|
|
5
|
+
describe('MSegmentedButton', () => {
|
|
6
|
+
it('lets the segments share the width when the group is stretched (a flex column, w-full)', () => {
|
|
7
|
+
const w = mount(MSegmentedButton, { props: { modelValue: 'a', options: [{ value: 'a', label: 'A' }, { value: 'b', label: 'B' }] } })
|
|
8
|
+
for (const b of w.findAll('button')) expect(b.classes()).toContain('grow')
|
|
9
|
+
})
|
|
10
|
+
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MSkeleton from '../components/MSkeleton.vue'
|
|
4
|
+
|
|
5
|
+
// (the template starts with a comment, so the root is found by class, not wrapper.element)
|
|
6
|
+
const style = (props: Record<string, unknown>) => (mount(MSkeleton, { props }).find('.m3-skeleton').element as HTMLElement).style
|
|
7
|
+
|
|
8
|
+
describe('MSkeleton', () => {
|
|
9
|
+
it('leaves its default size and corners to a base-layer class, so consumer classes win', () => {
|
|
10
|
+
const w = mount(MSkeleton, { props: { variant: 'rounded' }, attrs: { class: 'w-40 rounded-xl' } })
|
|
11
|
+
const root = w.find('.m3-skeleton')
|
|
12
|
+
expect(root.classes()).toEqual(expect.arrayContaining(['m3-skeleton-rounded', 'w-40', 'rounded-xl']))
|
|
13
|
+
const s = (root.element as HTMLElement).style
|
|
14
|
+
expect(s.width).toBe('')
|
|
15
|
+
expect(s.height).toBe('')
|
|
16
|
+
expect(s.borderRadius).toBe('')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('takes width and height props inline', () => {
|
|
20
|
+
const s = style({ width: '120px', height: 'auto' })
|
|
21
|
+
expect(s.width).toBe('120px')
|
|
22
|
+
expect(s.height).toBe('auto')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('takes a radius as a shape step or any CSS length', () => {
|
|
26
|
+
expect(style({ radius: 'xl' }).borderRadius).toBe('var(--radius-xl)')
|
|
27
|
+
expect(style({ radius: 'full' }).borderRadius).toBe('9999px')
|
|
28
|
+
expect(style({ radius: 'none' }).borderRadius).toBe('0px')
|
|
29
|
+
expect(style({ radius: '6px' }).borderRadius).toBe('6px')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('rounds every line of a multi-line text skeleton with radius', () => {
|
|
33
|
+
const w = mount(MSkeleton, { props: { lines: 3, radius: 'xs' } })
|
|
34
|
+
const lines = w.findAll('.h-3\\.5')
|
|
35
|
+
expect(lines).toHaveLength(3)
|
|
36
|
+
lines.forEach((l) => expect((l.element as HTMLElement).style.borderRadius).toBe('var(--radius-xs)'))
|
|
37
|
+
})
|
|
38
|
+
})
|