@m3ui-vue/m3ui-vue 1.6.0 → 1.6.2
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 +940 -33
- package/dist/{MButton-CPghlKb0.js → MButton-OQ4wIERQ.js} +2 -2
- package/dist/{MButton-CPghlKb0.js.map → MButton-OQ4wIERQ.js.map} +1 -1
- package/dist/MColorPickerModal-NtkihoK6.js +577 -0
- package/dist/MColorPickerModal-NtkihoK6.js.map +1 -0
- package/dist/{MDialog-X50At1Gk.js → MDialog-DYMnaBlt.js} +3 -3
- package/dist/{MDialog-X50At1Gk.js.map → MDialog-DYMnaBlt.js.map} +1 -1
- package/dist/{MListItem-DVi1j1QI.js → MListItem-D2cNUyzP.js} +211 -168
- package/dist/MListItem-D2cNUyzP.js.map +1 -0
- package/dist/{MLoadingIndicator-vooA3110.js → MLoadingIndicator-DWUj0BAB.js} +2 -2
- package/dist/{MLoadingIndicator-vooA3110.js.map → MLoadingIndicator-DWUj0BAB.js.map} +1 -1
- package/dist/{MMenuItem-CRNZkVVr.js → MMenuItem-BuxYoASE.js} +133 -151
- package/dist/MMenuItem-BuxYoASE.js.map +1 -0
- package/dist/{MSeekBar-BL2W5_rD.js → MSeekBar-C4cn9RIF.js} +2 -2
- package/dist/{MSeekBar-BL2W5_rD.js.map → MSeekBar-C4cn9RIF.js.map} +1 -1
- package/dist/{MSlider-B9NcKTmZ.js → MSlider-BIkA6DiE.js} +2 -2
- package/dist/{MSlider-B9NcKTmZ.js.map → MSlider-BIkA6DiE.js.map} +1 -1
- package/dist/{MSpinner-_XpTRkAg.js → MSpinner-DZkXZJpc.js} +2 -2
- package/dist/{MSpinner-_XpTRkAg.js.map → MSpinner-DZkXZJpc.js.map} +1 -1
- package/dist/{MTextField-DpcPmR5B.js → MTextField-CNH-byir.js} +2 -2
- package/dist/{MTextField-DpcPmR5B.js.map → MTextField-CNH-byir.js.map} +1 -1
- package/dist/MTooltip-CK39Zon4.js +183 -0
- package/dist/MTooltip-CK39Zon4.js.map +1 -0
- package/dist/{_useEscapeStack-C5-BYr8y.js → _popupPosition-nL8SVKPK.js} +20 -2
- package/dist/_popupPosition-nL8SVKPK.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAddressField.vue.d.ts +54 -0
- package/dist/components/MAudioPlayer.vue.d.ts +1 -1
- package/dist/components/MAudioRecorder.vue.d.ts +51 -0
- package/dist/components/MAvailabilityCalendar.vue.d.ts +1 -1
- package/dist/components/MCameraCapture.vue.d.ts +51 -0
- package/dist/components/MCollapse.vue.d.ts +32 -0
- package/dist/components/MCountrySelect.vue.d.ts +41 -0
- package/dist/components/MCronField.vue.d.ts +26 -0
- package/dist/components/MDashboardGrid.vue.d.ts +65 -0
- package/dist/components/MDiffViewer.vue.d.ts +56 -0
- package/dist/components/MExpansionPanel.vue.d.ts +26 -3
- package/dist/components/MFilterBuilder.vue.d.ts +22 -0
- package/dist/components/MFlex.vue.d.ts +1 -1
- package/dist/components/MMapCluster.vue.d.ts +80 -0
- package/dist/components/MMapDraw.vue.d.ts +79 -0
- package/dist/components/MMentionField.vue.d.ts +102 -0
- package/dist/components/MNotificationCenter.vue.d.ts +57 -0
- package/dist/components/MQRScanner.vue.d.ts +52 -0
- package/dist/components/MQuiz.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MTimezoneSelect.vue.d.ts +39 -0
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MVideoPlayer.vue.d.ts +1 -1
- package/dist/components/_MFilterGroup.vue.d.ts +17 -0
- package/dist/composables/_caretPosition.d.ts +6 -0
- package/dist/composables/_useCamera.d.ts +16 -0
- package/dist/composables/_useFollowAnchor.d.ts +15 -0
- package/dist/composables/cron.d.ts +29 -0
- package/dist/composables/dashboardLayout.d.ts +28 -0
- package/dist/composables/filterBuilder.d.ts +55 -0
- package/dist/composables/mapAdapters.d.ts +6 -1
- package/dist/composables/mapSearch.d.ts +1 -0
- package/dist/composables/textDiff.d.ts +24 -0
- package/dist/composables/useLocale.d.ts +108 -0
- package/dist/draw.js +28 -27
- package/dist/draw.js.map +1 -1
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/locales/index.js +749 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +10444 -7495
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +5 -0
- package/dist/map.js +1509 -617
- package/dist/map.js.map +1 -1
- package/dist/media.js +5 -5
- package/dist/pdf.js +5 -5
- package/dist/rich-text-editor.js +5 -5
- package/dist/styles.css +1 -1
- package/dist/{useLocale-COav9m8C.js → useLocale-DaVSTdm0.js} +108 -1
- package/dist/useLocale-DaVSTdm0.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MAddressField.test.ts +149 -0
- package/src/__tests__/MAudioRecorder.test.ts +125 -0
- package/src/__tests__/MCameraCapture.test.ts +154 -0
- package/src/__tests__/MCountrySelect.test.ts +67 -0
- package/src/__tests__/MCronField.test.ts +100 -0
- package/src/__tests__/MDashboardGrid.test.ts +122 -0
- package/src/__tests__/MDiffViewer.test.ts +68 -0
- package/src/__tests__/MExpansionPanel.test.ts +107 -0
- package/src/__tests__/MFilterBuilder.test.ts +130 -0
- package/src/__tests__/MMapCluster.test.ts +127 -0
- package/src/__tests__/MMapDraw.test.ts +188 -0
- package/src/__tests__/MMapLayers.test.ts +56 -0
- package/src/__tests__/MMentionField.test.ts +163 -0
- package/src/__tests__/MNotificationCenter.test.ts +94 -0
- package/src/__tests__/_fakeMaplibre.ts +14 -3
- package/src/__tests__/attrsFallthrough.test.ts +4 -0
- package/src/__tests__/cron.test.ts +68 -0
- package/src/__tests__/dashboardLayout.test.ts +45 -0
- package/src/__tests__/filterBuilder.test.ts +91 -0
- package/src/__tests__/followAnchor.test.ts +162 -0
- package/src/__tests__/ssr.test.ts +3 -0
- package/src/__tests__/textDiff.test.ts +37 -0
- package/src/components/MAddressField.vue +301 -0
- package/src/components/MAudioRecorder.vue +334 -0
- package/src/components/MAutocomplete.vue +3 -7
- package/src/components/MCameraCapture.vue +156 -0
- package/src/components/MCollapse.vue +91 -0
- package/src/components/MColorPicker.vue +4 -8
- package/src/components/MCountrySelect.vue +89 -0
- package/src/components/MCronField.vue +251 -0
- package/src/components/MDashboardGrid.vue +382 -0
- package/src/components/MDatePicker.vue +10 -7
- package/src/components/MDateRangePicker.vue +10 -7
- package/src/components/MDiffViewer.vue +234 -0
- package/src/components/MExpansionPanel.vue +56 -48
- package/src/components/MFilterBuilder.vue +47 -0
- package/src/components/MMapBaseLayers.vue +29 -28
- package/src/components/MMapCluster.vue +295 -0
- package/src/components/MMapDraw.vue +601 -0
- package/src/components/MMapMeasure.vue +1 -1
- package/src/components/MMapSearch.vue +1 -9
- package/src/components/MMentionField.vue +373 -0
- package/src/components/MMultiAutocomplete.vue +3 -7
- package/src/components/MMultiSelect.vue +3 -7
- package/src/components/MNotificationCenter.vue +252 -0
- package/src/components/MPhoneInput.vue +3 -10
- package/src/components/MQRScanner.vue +177 -0
- package/src/components/MSelect.vue +3 -7
- package/src/components/MTimePicker.vue +10 -7
- package/src/components/MTimezoneSelect.vue +116 -0
- package/src/components/_MFilterGroup.vue +210 -0
- package/src/composables/_caretPosition.ts +44 -0
- package/src/composables/_useCamera.ts +66 -0
- package/src/composables/_useFollowAnchor.ts +109 -0
- package/src/composables/cron.ts +179 -0
- package/src/composables/dashboardLayout.ts +94 -0
- package/src/composables/filterBuilder.ts +195 -0
- package/src/composables/mapAdapters.ts +29 -15
- package/src/composables/mapSearch.ts +10 -0
- package/src/composables/textDiff.ts +106 -0
- package/src/composables/useLocale.ts +215 -0
- package/src/index.ts +25 -0
- package/src/locales/de.ts +107 -0
- package/src/locales/es.ts +107 -0
- package/src/locales/fr.ts +107 -0
- package/src/locales/ja.ts +107 -0
- package/src/locales/ko.ts +107 -0
- package/src/locales/pt.ts +107 -0
- package/src/locales/zh.ts +107 -0
- package/src/map.ts +5 -0
- package/dist/MListItem-DVi1j1QI.js.map +0 -1
- package/dist/MMenuItem-CRNZkVVr.js.map +0 -1
- package/dist/MTooltip-BL3jPYPT.js +0 -754
- package/dist/MTooltip-BL3jPYPT.js.map +0 -1
- package/dist/_useEscapeStack-C5-BYr8y.js.map +0 -1
- package/dist/useLocale-COav9m8C.js.map +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import MCronField from '../components/MCronField.vue'
|
|
5
|
+
import MChip from '../components/MChip.vue'
|
|
6
|
+
import MNumberField from '../components/MNumberField.vue'
|
|
7
|
+
import MTimePicker from '../components/MTimePicker.vue'
|
|
8
|
+
|
|
9
|
+
let wrapper: VueWrapper | undefined
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
wrapper?.unmount()
|
|
12
|
+
wrapper = undefined
|
|
13
|
+
document.body.innerHTML = ''
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
function mountCron(initial = '0 9 * * 1-5', props: Record<string, unknown> = {}) {
|
|
17
|
+
const expr = ref(initial)
|
|
18
|
+
const Host = defineComponent({
|
|
19
|
+
setup: () => () => h(MCronField, { modelValue: expr.value, 'onUpdate:modelValue': (v: string) => (expr.value = v), ...props }),
|
|
20
|
+
})
|
|
21
|
+
wrapper = mount(Host, { attachTo: document.body })
|
|
22
|
+
return expr
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const chips = () => wrapper!.findAllComponents(MChip)
|
|
26
|
+
// The text also carries the check icon's ligature
|
|
27
|
+
const chip = (label: string) => chips().find((c) => c.text().trim().endsWith(label))!
|
|
28
|
+
const input = () => wrapper!.find('input')
|
|
29
|
+
|
|
30
|
+
describe('MCronField', () => {
|
|
31
|
+
it('shows the expression, what it means, and when it runs next', () => {
|
|
32
|
+
mountCron()
|
|
33
|
+
expect((input().element as HTMLInputElement).value).toBe('0 9 * * 1-5')
|
|
34
|
+
expect(wrapper!.text()).toContain('Monday to Friday')
|
|
35
|
+
expect(wrapper!.text()).toContain('Next runs')
|
|
36
|
+
expect(wrapper!.findAll('li')).toHaveLength(3)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('recognizes the schedule it is, and shows its controls', () => {
|
|
40
|
+
mountCron()
|
|
41
|
+
expect(chip('Weekly').props('selected')).toBe(true)
|
|
42
|
+
expect(wrapper!.findComponent(MTimePicker).props('modelValue')).toBe('09:00')
|
|
43
|
+
// Weekday chips, Monday first: Mon–Fri on
|
|
44
|
+
const days = chips().slice(6)
|
|
45
|
+
expect(days.map((c) => c.props('selected'))).toEqual([true, true, true, true, true, false, false])
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('builds expressions from the controls', async () => {
|
|
49
|
+
const expr = mountCron()
|
|
50
|
+
await chip('Daily').find('button').trigger('click')
|
|
51
|
+
expect(expr.value).toBe('0 9 * * *')
|
|
52
|
+
wrapper!.findComponent(MTimePicker).vm.$emit('update:modelValue', '18:30')
|
|
53
|
+
await nextTick()
|
|
54
|
+
expect(expr.value).toBe('30 18 * * *')
|
|
55
|
+
await chip('Monthly').find('button').trigger('click')
|
|
56
|
+
expect(expr.value).toBe('30 18 1 * *')
|
|
57
|
+
wrapper!.findAllComponents(MNumberField).at(-1)!.vm.$emit('update:modelValue', 15)
|
|
58
|
+
await nextTick()
|
|
59
|
+
expect(expr.value).toBe('30 18 15 * *')
|
|
60
|
+
await chip('Every few minutes').find('button').trigger('click')
|
|
61
|
+
expect(expr.value).toBe('*/15 * * * *')
|
|
62
|
+
wrapper!.findComponent(MNumberField).vm.$emit('update:modelValue', 5)
|
|
63
|
+
await nextTick()
|
|
64
|
+
expect(expr.value).toBe('*/5 * * * *')
|
|
65
|
+
await chip('Hourly').find('button').trigger('click')
|
|
66
|
+
expect(expr.value).toBe('0 * * * *')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('toggles weekdays, keeping at least one, and writes ranges', async () => {
|
|
70
|
+
const expr = mountCron('0 9 * * 1')
|
|
71
|
+
const day = (i: number) => chips().slice(6)[i]!
|
|
72
|
+
await day(1).find('button').trigger('click')
|
|
73
|
+
await day(2).find('button').trigger('click')
|
|
74
|
+
expect(expr.value).toBe('0 9 * * 1-3')
|
|
75
|
+
await day(6).find('button').trigger('click') // Sunday
|
|
76
|
+
expect(expr.value).toBe('0 9 * * 0-3')
|
|
77
|
+
for (const i of [0, 1, 2, 6]) await day(i).find('button').trigger('click')
|
|
78
|
+
// The last one stays
|
|
79
|
+
expect(expr.value).toBe('0 9 * * 0') // Sunday, the last one left, can't go
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('takes typed expressions, emitting only valid ones', async () => {
|
|
83
|
+
const expr = mountCron()
|
|
84
|
+
await input().setValue('*/7 * * *')
|
|
85
|
+
expect(expr.value).toBe('0 9 * * 1-5')
|
|
86
|
+
expect(wrapper!.text()).toContain('Not a valid cron expression')
|
|
87
|
+
await input().setValue('15 3 1 */3 *')
|
|
88
|
+
expect(expr.value).toBe('15 3 1 */3 *')
|
|
89
|
+
// Not one of the simple schedules
|
|
90
|
+
expect(chip('Custom').props('selected')).toBe(true)
|
|
91
|
+
expect(wrapper!.text()).toContain('in January, April, July, and October')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('leaves the builder out, and the runs, when asked', () => {
|
|
95
|
+
mountCron('@hourly', { builder: false, nextRuns: 0 })
|
|
96
|
+
expect(chips()).toHaveLength(0)
|
|
97
|
+
expect(wrapper!.findAll('li')).toHaveLength(0)
|
|
98
|
+
expect(wrapper!.text()).toContain('At minute 0 of every hour')
|
|
99
|
+
})
|
|
100
|
+
})
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import MDashboardGrid from '../components/MDashboardGrid.vue'
|
|
5
|
+
import type { DashboardItem } from '../composables/dashboardLayout'
|
|
6
|
+
|
|
7
|
+
let width = 1200
|
|
8
|
+
let wrapper: VueWrapper | undefined
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
width = 1200
|
|
11
|
+
Object.defineProperty(HTMLElement.prototype, 'clientWidth', { configurable: true, get() { return (this as HTMLElement).classList.contains('m3-dashboard-grid') ? width : 0 } })
|
|
12
|
+
})
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
wrapper?.unmount()
|
|
15
|
+
wrapper = undefined
|
|
16
|
+
document.body.innerHTML = ''
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
// 12 columns over 1200px with 16px gaps: a column is 85.33px, a step 101.33px; rows are 96px, a step 112px
|
|
20
|
+
const base = (): (DashboardItem & { label: string })[] => [
|
|
21
|
+
{ id: 'a', x: 0, y: 0, w: 6, h: 2, label: 'Sales' },
|
|
22
|
+
{ id: 'b', x: 6, y: 0, w: 6, h: 2, label: 'Visitors' },
|
|
23
|
+
{ id: 'c', x: 0, y: 2, w: 12, h: 1, label: 'Orders', static: false },
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
async function mountGrid(props: Record<string, unknown> = {}) {
|
|
27
|
+
const layout = ref(base())
|
|
28
|
+
const Host = defineComponent({
|
|
29
|
+
setup: () => () => h(MDashboardGrid, { modelValue: layout.value, 'onUpdate:modelValue': (v: typeof layout.value) => (layout.value = v), ...props }, {
|
|
30
|
+
item: ({ item }: { item: DashboardItem & { label: string } }) => h('div', { class: 'card' }, item.label),
|
|
31
|
+
}),
|
|
32
|
+
})
|
|
33
|
+
wrapper = mount(Host, { attachTo: document.body })
|
|
34
|
+
await nextTick()
|
|
35
|
+
await nextTick()
|
|
36
|
+
return layout
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const items = () => wrapper!.findAll('.m3-dashboard-grid__item')
|
|
40
|
+
const item = (label: string) => items().find((i) => i.text().includes(label))!
|
|
41
|
+
|
|
42
|
+
describe('MDashboardGrid', () => {
|
|
43
|
+
it('places widgets on the grid by their cells', async () => {
|
|
44
|
+
await mountGrid()
|
|
45
|
+
const b = item('Visitors').element as HTMLElement
|
|
46
|
+
expect(b.style.transform).toBe('translate(608px, 0px)')
|
|
47
|
+
expect(parseFloat(b.style.width)).toBeCloseTo(592, 0)
|
|
48
|
+
expect(b.style.height).toBe('208px')
|
|
49
|
+
expect((wrapper!.find('.m3-dashboard-grid').element as HTMLElement).style.height).toBe('320px')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('moves a widget with the mouse, pushing the one it lands on below', async () => {
|
|
53
|
+
const layout = await mountGrid()
|
|
54
|
+
const a = item('Sales').element
|
|
55
|
+
a.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 50, button: 0, pointerType: 'mouse', bubbles: true }))
|
|
56
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 110, clientY: 50, pointerType: 'mouse' }))
|
|
57
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 708, clientY: 50, pointerType: 'mouse' }))
|
|
58
|
+
await nextTick()
|
|
59
|
+
// The landing spot shows
|
|
60
|
+
expect(wrapper!.find('.border-dashed').exists()).toBe(true)
|
|
61
|
+
window.dispatchEvent(new PointerEvent('pointerup', { pointerType: 'mouse' }))
|
|
62
|
+
await nextTick()
|
|
63
|
+
const pos = Object.fromEntries(layout.value.map((i) => [i.id, [i.x, i.y, i.w, i.h]]))
|
|
64
|
+
expect(pos).toEqual({ a: [6, 0, 6, 2], b: [6, 2, 6, 2], c: [0, 4, 12, 1] })
|
|
65
|
+
// Labels and other fields kept
|
|
66
|
+
expect(layout.value[0]!.label).toBe('Sales')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('resizes from the corner', async () => {
|
|
70
|
+
const layout = await mountGrid()
|
|
71
|
+
const corner = item('Sales').find('[data-dashboard-resize]').element
|
|
72
|
+
corner.dispatchEvent(new PointerEvent('pointerdown', { clientX: 590, clientY: 200, button: 0, pointerType: 'mouse', bubbles: true }))
|
|
73
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 590, clientY: 312, pointerType: 'mouse' }))
|
|
74
|
+
window.dispatchEvent(new PointerEvent('pointerup', { pointerType: 'mouse' }))
|
|
75
|
+
await nextTick()
|
|
76
|
+
expect(layout.value.find((i) => i.id === 'a')).toMatchObject({ w: 6, h: 3 })
|
|
77
|
+
expect(layout.value.find((i) => i.id === 'c')).toMatchObject({ y: 3 })
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('needs a long press with a finger, and a moving finger is a scroll', async () => {
|
|
81
|
+
const layout = await mountGrid()
|
|
82
|
+
const a = item('Sales').element
|
|
83
|
+
a.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 50, button: 0, pointerType: 'touch', bubbles: true }))
|
|
84
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100, clientY: 90, pointerType: 'touch' }))
|
|
85
|
+
window.dispatchEvent(new PointerEvent('pointerup', { pointerType: 'touch' }))
|
|
86
|
+
await nextTick()
|
|
87
|
+
expect(layout.value).toEqual(base())
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('moves and resizes with the keyboard, and Escape puts it back', async () => {
|
|
91
|
+
const layout = await mountGrid()
|
|
92
|
+
const a = item('Sales')
|
|
93
|
+
await a.trigger('keydown', { key: ' ' })
|
|
94
|
+
expect(wrapper!.find('[aria-live]').text()).toContain('Picked up Sales')
|
|
95
|
+
await a.trigger('keydown', { key: 'ArrowRight' })
|
|
96
|
+
// b is pushed below; compaction floats nothing into an empty spot, so down alone wouldn't stick
|
|
97
|
+
expect(layout.value.find((i) => i.id === 'a')).toMatchObject({ x: 1, y: 0 })
|
|
98
|
+
await a.trigger('keydown', { key: 'ArrowDown', shiftKey: true })
|
|
99
|
+
expect(layout.value.find((i) => i.id === 'a')!.h).toBe(3)
|
|
100
|
+
await nextTick()
|
|
101
|
+
expect(wrapper!.find('[aria-live]').text()).toContain('Sales: column 2, row 1, 6 by 3')
|
|
102
|
+
await a.trigger('keydown', { key: 'Escape' })
|
|
103
|
+
expect(layout.value.find((i) => i.id === 'a')).toMatchObject({ x: 0, y: 0, w: 6 })
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('leaves static widgets and read-only grids alone', async () => {
|
|
107
|
+
const layout = await mountGrid({ editable: false })
|
|
108
|
+
expect(item('Sales').attributes('tabindex')).toBeUndefined()
|
|
109
|
+
expect(wrapper!.find('[data-dashboard-resize]').exists()).toBe(false)
|
|
110
|
+
item('Sales').element.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 50, button: 0, pointerType: 'mouse', bubbles: true }))
|
|
111
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 700, clientY: 50, pointerType: 'mouse' }))
|
|
112
|
+
window.dispatchEvent(new PointerEvent('pointerup', { pointerType: 'mouse' }))
|
|
113
|
+
expect(layout.value).toEqual(base())
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('stacks in one column below the breakpoint, in reading order', async () => {
|
|
117
|
+
width = 400
|
|
118
|
+
await mountGrid()
|
|
119
|
+
expect(items().map((i) => i.text())).toEqual(['Sales', 'Visitors', 'Orders'])
|
|
120
|
+
expect(wrapper!.find('[data-dashboard-resize]').exists()).toBe(false)
|
|
121
|
+
})
|
|
122
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import MDiffViewer from '../components/MDiffViewer.vue'
|
|
4
|
+
import MSegmentedButton from '../components/MSegmentedButton.vue'
|
|
5
|
+
|
|
6
|
+
let width = 1000
|
|
7
|
+
let wrapper: VueWrapper | undefined
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
width = 1000
|
|
10
|
+
Object.defineProperty(HTMLElement.prototype, 'clientWidth', { configurable: true, get() { return (this as HTMLElement).classList.contains('m3-diff') ? width : 0 } })
|
|
11
|
+
})
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
wrapper?.unmount()
|
|
14
|
+
wrapper = undefined
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const before = Array.from({ length: 20 }, (_, i) => `line ${i + 1}`).join('\n')
|
|
18
|
+
const after = before.replace('line 10', 'line ten').replace('line 20', 'line 20\nline 21')
|
|
19
|
+
|
|
20
|
+
describe('MDiffViewer', () => {
|
|
21
|
+
it('counts changes and folds long unchanged stretches around them', async () => {
|
|
22
|
+
wrapper = mount(MDiffViewer, { props: { original: before, modified: after, mode: 'unified', originalLabel: 'a.txt', modifiedLabel: 'b.txt' } })
|
|
23
|
+
expect(wrapper.text()).toContain('a.txt')
|
|
24
|
+
expect(wrapper.text()).toContain('+2')
|
|
25
|
+
expect(wrapper.text()).toContain('−1')
|
|
26
|
+
// Lines 1–6 fold (3 kept before line 10), 14–16 fold too (3 after, 3 before line 21's add)
|
|
27
|
+
const folds = wrapper.findAll('button').filter((b) => b.text().includes('unchanged'))
|
|
28
|
+
expect(folds.map((b) => b.text())).toEqual(['⋯ Show 6 unchanged lines', '⋯ Show 4 unchanged lines'])
|
|
29
|
+
await folds[0]!.trigger('click')
|
|
30
|
+
expect(wrapper.findAll('button').filter((b) => b.text().includes('unchanged'))).toHaveLength(1)
|
|
31
|
+
expect(wrapper.text()).toContain('line 1')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('highlights the changed words inside a changed line', () => {
|
|
35
|
+
wrapper = mount(MDiffViewer, { props: { original: 'const total = price * qty', modified: 'const total = price * quantity', mode: 'unified' } })
|
|
36
|
+
const marks = wrapper.findAll('span.rounded-xs')
|
|
37
|
+
expect(marks.map((m) => m.text())).toEqual(['qty', 'quantity'])
|
|
38
|
+
expect(marks[0]!.classes()).toContain('bg-error-container')
|
|
39
|
+
expect(marks[1]!.classes()).toContain('bg-success-container')
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('shows removed and added lines facing each other side by side', () => {
|
|
43
|
+
wrapper = mount(MDiffViewer, { props: { original: 'a\nb\nc', modified: 'a\nB\nc\nd', context: -1 } })
|
|
44
|
+
const rows = wrapper.findAll('tbody tr')
|
|
45
|
+
expect(rows).toHaveLength(4)
|
|
46
|
+
const cells = (i: number) => rows[i]!.findAll('td').map((c) => c.text())
|
|
47
|
+
expect(cells(1)).toEqual(['2', 'b', '2', 'B'])
|
|
48
|
+
expect(cells(3)).toEqual(['', '', '4', 'd'])
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('switches view from its toggle, and goes unified when narrow', async () => {
|
|
52
|
+
wrapper = mount(MDiffViewer, { props: { original: 'a', modified: 'b' } })
|
|
53
|
+
await new Promise((r) => setTimeout(r))
|
|
54
|
+
wrapper.findComponent(MSegmentedButton).vm.$emit('update:modelValue', 'unified')
|
|
55
|
+
expect(wrapper.emitted('update:mode')![0]).toEqual(['unified'])
|
|
56
|
+
wrapper.unmount()
|
|
57
|
+
width = 400
|
|
58
|
+
wrapper = mount(MDiffViewer, { props: { original: 'a', modified: 'b' } })
|
|
59
|
+
await new Promise((r) => setTimeout(r))
|
|
60
|
+
expect(wrapper.findComponent(MSegmentedButton).exists()).toBe(false)
|
|
61
|
+
expect(wrapper.findAll('tbody tr')).toHaveLength(2)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('says when nothing changed', () => {
|
|
65
|
+
wrapper = mount(MDiffViewer, { props: { original: 'same', modified: 'same' } })
|
|
66
|
+
expect(wrapper.text()).toContain('No changes')
|
|
67
|
+
})
|
|
68
|
+
})
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { h, nextTick } from 'vue'
|
|
4
|
+
import MCollapse from '../components/MCollapse.vue'
|
|
5
|
+
import MExpansionPanel from '../components/MExpansionPanel.vue'
|
|
6
|
+
|
|
7
|
+
let wrapper: VueWrapper | undefined
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
wrapper?.unmount()
|
|
10
|
+
wrapper = undefined
|
|
11
|
+
vi.useRealTimers()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const end = (el: Element) => {
|
|
15
|
+
const e = new Event('transitionend') as TransitionEvent
|
|
16
|
+
Object.defineProperty(e, 'propertyName', { value: 'grid-template-rows' })
|
|
17
|
+
el.dispatchEvent(e)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('MCollapse', () => {
|
|
21
|
+
it('opens and closes, inert while closed, with after-open / after-close', async () => {
|
|
22
|
+
wrapper = mount(MCollapse, { props: { open: false }, slots: { default: () => h('button', 'Inside') } })
|
|
23
|
+
const body = wrapper.find('.m3-collapse__body')
|
|
24
|
+
expect(body.attributes('inert')).toBeDefined()
|
|
25
|
+
expect(wrapper.find('button').exists()).toBe(true) // kept mounted by default
|
|
26
|
+
await wrapper.setProps({ open: true })
|
|
27
|
+
expect(wrapper.classes()).toContain('m3-collapse--open')
|
|
28
|
+
expect(body.attributes('inert')).toBeUndefined()
|
|
29
|
+
end(wrapper.element)
|
|
30
|
+
expect(wrapper.emitted('after-open')).toHaveLength(1)
|
|
31
|
+
await wrapper.setProps({ open: false })
|
|
32
|
+
end(wrapper.element)
|
|
33
|
+
expect(wrapper.emitted('after-close')).toHaveLength(1)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('unmounts the content once closed with unmountOnClose, and mounts it on open', async () => {
|
|
37
|
+
wrapper = mount(MCollapse, { props: { open: false, unmountOnClose: true }, slots: { default: () => h('p', 'Inside') } })
|
|
38
|
+
expect(wrapper.find('p').exists()).toBe(false)
|
|
39
|
+
await wrapper.setProps({ open: true })
|
|
40
|
+
expect(wrapper.find('p').exists()).toBe(true)
|
|
41
|
+
await wrapper.setProps({ open: false })
|
|
42
|
+
// Still there while closing
|
|
43
|
+
expect(wrapper.find('p').exists()).toBe(true)
|
|
44
|
+
end(wrapper.element)
|
|
45
|
+
await nextTick()
|
|
46
|
+
expect(wrapper.find('p').exists()).toBe(false)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('settles by itself when no transition runs', async () => {
|
|
50
|
+
vi.useFakeTimers()
|
|
51
|
+
wrapper = mount(MCollapse, { props: { open: false, duration: 200 } })
|
|
52
|
+
await wrapper.setProps({ open: true })
|
|
53
|
+
vi.advanceTimersByTime(260)
|
|
54
|
+
expect(wrapper.emitted('after-open')).toHaveLength(1)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('MExpansionPanel', () => {
|
|
59
|
+
it('toggles uncontrolled, linking its header to the body', async () => {
|
|
60
|
+
wrapper = mount(MExpansionPanel, { props: { title: 'Details' }, slots: { default: () => 'Body' } })
|
|
61
|
+
const header = wrapper.find('button')
|
|
62
|
+
expect(header.attributes('aria-expanded')).toBe('false')
|
|
63
|
+
expect(wrapper.find(`#${header.attributes('aria-controls')}`).exists()).toBe(true)
|
|
64
|
+
await header.trigger('click')
|
|
65
|
+
expect(header.attributes('aria-expanded')).toBe('true')
|
|
66
|
+
expect(wrapper.findComponent(MCollapse).props('open')).toBe(true)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('emits v-model when controlled', async () => {
|
|
70
|
+
wrapper = mount(MExpansionPanel, { props: { title: 'Details', modelValue: false } })
|
|
71
|
+
await wrapper.find('button').trigger('click')
|
|
72
|
+
expect(wrapper.emitted('update:modelValue')![0]).toEqual([true])
|
|
73
|
+
expect(wrapper.findComponent(MCollapse).props('open')).toBe(false)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('takes header slots instead of the text props', () => {
|
|
77
|
+
wrapper = mount(MExpansionPanel, {
|
|
78
|
+
slots: {
|
|
79
|
+
leading: () => h('i', { class: 'lead' }, 'L'),
|
|
80
|
+
title: () => [h('span', 'Obra '), h('mark', 'Norte')],
|
|
81
|
+
subtitle: () => 'Started today',
|
|
82
|
+
trailing: () => h('b', { class: 'count' }, '3'),
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
expect(wrapper.find('.lead').exists()).toBe(true)
|
|
86
|
+
expect(wrapper.find('mark').text()).toBe('Norte')
|
|
87
|
+
expect(wrapper.text()).toContain('Started today')
|
|
88
|
+
// The trailing slot sits before the chevron
|
|
89
|
+
const header = wrapper.find('button').element
|
|
90
|
+
expect(header.lastElementChild!.textContent).toBe('expand_more')
|
|
91
|
+
expect(header.lastElementChild!.previousElementSibling!.className).toBe('count')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('is a plain row with expandable false: no button, chevron or body', async () => {
|
|
95
|
+
wrapper = mount(MExpansionPanel, { props: { title: 'Nothing inside', expandable: false } })
|
|
96
|
+
expect(wrapper.find('button').exists()).toBe(false)
|
|
97
|
+
expect(wrapper.find('[aria-expanded]').exists()).toBe(false)
|
|
98
|
+
expect(wrapper.text()).not.toContain('expand_more')
|
|
99
|
+
expect(wrapper.findComponent(MCollapse).exists()).toBe(false)
|
|
100
|
+
expect(wrapper.find('.opacity-\\[0\\.38\\]').exists()).toBe(false)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('drops the body padding with flush', () => {
|
|
104
|
+
wrapper = mount(MExpansionPanel, { props: { title: 'List', flush: true }, slots: { default: () => h('ul', { class: 'list' }) } })
|
|
105
|
+
expect(wrapper.find('.list').element.parentElement!.className).not.toContain('px-5')
|
|
106
|
+
})
|
|
107
|
+
})
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import MFilterBuilder from '../components/MFilterBuilder.vue'
|
|
5
|
+
import MSelect from '../components/MSelect.vue'
|
|
6
|
+
import MNumberField from '../components/MNumberField.vue'
|
|
7
|
+
import MMultiSelect from '../components/MMultiSelect.vue'
|
|
8
|
+
import MDatePicker from '../components/MDatePicker.vue'
|
|
9
|
+
import MTextField from '../components/MTextField.vue'
|
|
10
|
+
import MSegmentedButton from '../components/MSegmentedButton.vue'
|
|
11
|
+
import type { FilterField, FilterGroup, FilterRule } from '../composables/filterBuilder'
|
|
12
|
+
|
|
13
|
+
const fields: FilterField[] = [
|
|
14
|
+
{ key: 'name', label: 'Name' },
|
|
15
|
+
{ key: 'price', label: 'Price', type: 'number' },
|
|
16
|
+
{ key: 'due', label: 'Due', type: 'date' },
|
|
17
|
+
{ key: 'status', label: 'Status', type: 'select', options: [{ label: 'Open', value: 'open' }, { label: 'Done', value: 'done' }] },
|
|
18
|
+
{ key: 'urgent', label: 'Urgent', type: 'boolean' },
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
let wrapper: VueWrapper | undefined
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
wrapper?.unmount()
|
|
24
|
+
wrapper = undefined
|
|
25
|
+
document.body.innerHTML = ''
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
function mountBuilder(props: Record<string, unknown> = {}, initial: FilterGroup | null = null) {
|
|
29
|
+
const filter = ref<FilterGroup | null>(initial)
|
|
30
|
+
const Host = defineComponent({
|
|
31
|
+
setup: () => () => h(MFilterBuilder, { modelValue: filter.value, 'onUpdate:modelValue': (v: FilterGroup) => (filter.value = v), fields, ...props }),
|
|
32
|
+
})
|
|
33
|
+
wrapper = mount(Host, { attachTo: document.body })
|
|
34
|
+
return filter
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const button = (text: string) => wrapper!.findAll('button').find((b) => b.text().includes(text))!
|
|
38
|
+
const rules = () => wrapper!.findAll('[data-filter-rule]')
|
|
39
|
+
/** The n-th rule's field and operator selects */
|
|
40
|
+
const selects = (n: number) => rules()[n]!.findAllComponents(MSelect)
|
|
41
|
+
const rule = (filter: { value: FilterGroup | null }, n: number) => filter.value!.rules[n] as FilterRule
|
|
42
|
+
|
|
43
|
+
describe('MFilterBuilder', () => {
|
|
44
|
+
it('starts empty and adds a condition on the first field', async () => {
|
|
45
|
+
const filter = mountBuilder()
|
|
46
|
+
expect(wrapper!.text()).toContain('No conditions: every row matches')
|
|
47
|
+
await button('Add condition').trigger('click')
|
|
48
|
+
expect(filter.value!.rules).toHaveLength(1)
|
|
49
|
+
expect(rule(filter, 0)).toMatchObject({ field: 'name', operator: 'contains' })
|
|
50
|
+
expect(rules()[0]!.findComponent(MTextField).exists()).toBe(true)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('switches the value input and operators with the field\'s type', async () => {
|
|
54
|
+
const filter = mountBuilder()
|
|
55
|
+
await button('Add condition').trigger('click')
|
|
56
|
+
selects(0)[0]!.vm.$emit('update:modelValue', 'price')
|
|
57
|
+
await nextTick()
|
|
58
|
+
expect(rule(filter, 0)).toMatchObject({ field: 'price', operator: 'equals' })
|
|
59
|
+
expect(rules()[0]!.findComponent(MNumberField).exists()).toBe(true)
|
|
60
|
+
expect((selects(0)[1]!.props('options') as { value: string }[]).map((o) => o.value)).toContain('between')
|
|
61
|
+
|
|
62
|
+
selects(0)[1]!.vm.$emit('update:modelValue', 'between')
|
|
63
|
+
await nextTick()
|
|
64
|
+
expect(rules()[0]!.findAllComponents(MNumberField)).toHaveLength(2)
|
|
65
|
+
rules()[0]!.findAllComponents(MNumberField)[1]!.vm.$emit('update:modelValue', 99)
|
|
66
|
+
await nextTick()
|
|
67
|
+
expect(rule(filter, 0).value).toEqual([null, 99])
|
|
68
|
+
|
|
69
|
+
selects(0)[0]!.vm.$emit('update:modelValue', 'status')
|
|
70
|
+
await nextTick()
|
|
71
|
+
expect(rule(filter, 0)).toMatchObject({ field: 'status', operator: 'in' })
|
|
72
|
+
expect(rule(filter, 0).value).toBeUndefined()
|
|
73
|
+
expect(rules()[0]!.findComponent(MMultiSelect).props('options')).toEqual(fields[3]!.options)
|
|
74
|
+
|
|
75
|
+
selects(0)[0]!.vm.$emit('update:modelValue', 'due')
|
|
76
|
+
await nextTick()
|
|
77
|
+
expect(rules()[0]!.findComponent(MDatePicker).exists()).toBe(true)
|
|
78
|
+
// Dates read greater / less as after / before
|
|
79
|
+
expect((selects(0)[1]!.props('options') as { label: string }[]).map((o) => o.label)).toContain('is after')
|
|
80
|
+
|
|
81
|
+
selects(0)[0]!.vm.$emit('update:modelValue', 'urgent')
|
|
82
|
+
await nextTick()
|
|
83
|
+
expect(rule(filter, 0).operator).toBe('isTrue')
|
|
84
|
+
expect(rules()[0]!.findComponent(MTextField).exists()).toBe(false)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('keeps a value that still fits a new operator, and drops one that doesn\'t', async () => {
|
|
88
|
+
const filter = mountBuilder({}, { id: 'g', combinator: 'and', rules: [{ id: 'r', field: 'name', operator: 'contains', value: 'ab' }] })
|
|
89
|
+
selects(0)[1]!.vm.$emit('update:modelValue', 'startsWith')
|
|
90
|
+
await nextTick()
|
|
91
|
+
expect(rule(filter, 0).value).toBe('ab')
|
|
92
|
+
selects(0)[1]!.vm.$emit('update:modelValue', 'isEmpty')
|
|
93
|
+
await nextTick()
|
|
94
|
+
expect(rule(filter, 0).value).toBeUndefined()
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('shows all / any once there are two conditions, and removes them', async () => {
|
|
98
|
+
const filter = mountBuilder()
|
|
99
|
+
await button('Add condition').trigger('click')
|
|
100
|
+
expect(wrapper!.findComponent(MSegmentedButton).exists()).toBe(false)
|
|
101
|
+
await button('Add condition').trigger('click')
|
|
102
|
+
const seg = wrapper!.findComponent(MSegmentedButton)
|
|
103
|
+
seg.vm.$emit('update:modelValue', 'or')
|
|
104
|
+
await nextTick()
|
|
105
|
+
expect(filter.value!.combinator).toBe('or')
|
|
106
|
+
await rules()[0]!.find('button[aria-label="Remove condition"]').trigger('click')
|
|
107
|
+
expect(filter.value!.rules).toHaveLength(1)
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('nests a group up to maxDepth, with the other combinator, and removes it', async () => {
|
|
111
|
+
const filter = mountBuilder()
|
|
112
|
+
await button('Add group').trigger('click')
|
|
113
|
+
const group = filter.value!.rules[0] as FilterGroup
|
|
114
|
+
expect(group).toMatchObject({ combinator: 'or', rules: [{ field: 'name' }] })
|
|
115
|
+
expect(wrapper!.findAll('[data-filter-group]')).toHaveLength(1)
|
|
116
|
+
// maxDepth 1: no deeper groups
|
|
117
|
+
expect(wrapper!.find('[data-filter-group]').findAll('button').some((b) => b.text().includes('Add group'))).toBe(false)
|
|
118
|
+
await wrapper!.find('[data-filter-group] button[aria-label="Remove group"]').trigger('click')
|
|
119
|
+
expect(filter.value!.rules).toEqual([])
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('offers no groups with maxDepth 0, and nothing to change when disabled', async () => {
|
|
123
|
+
mountBuilder({ maxDepth: 0 })
|
|
124
|
+
expect(button('Add group')).toBeUndefined()
|
|
125
|
+
wrapper!.unmount()
|
|
126
|
+
mountBuilder({ disabled: true }, { id: 'g', combinator: 'and', rules: [{ id: 'r', field: 'name', operator: 'contains', value: 'x' }] })
|
|
127
|
+
expect(button('Add condition').attributes('disabled')).toBeDefined()
|
|
128
|
+
expect(selects(0)[0]!.props('disabled')).toBe(true)
|
|
129
|
+
})
|
|
130
|
+
})
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { flushPromises, mount } from '@vue/test-utils'
|
|
3
|
+
import { h, nextTick } from 'vue'
|
|
4
|
+
import { created, type FakeMap } from './_fakeMaplibre'
|
|
5
|
+
|
|
6
|
+
vi.mock('maplibre-gl', async () => (await import('./_fakeMaplibre')).fakeModule)
|
|
7
|
+
|
|
8
|
+
const { MMap, MMapCluster } = await import('../map')
|
|
9
|
+
|
|
10
|
+
const points = {
|
|
11
|
+
type: 'FeatureCollection',
|
|
12
|
+
features: [[-64.18, -31.42], [-64.19, -31.41], [-64.2, -31.43]].map((c) => ({ type: 'Feature', properties: {}, geometry: { type: 'Point', coordinates: c } })),
|
|
13
|
+
}
|
|
14
|
+
const cluster = (id: number, count: number, at: [number, number]) => ({
|
|
15
|
+
properties: { cluster: true, cluster_id: id, point_count: count },
|
|
16
|
+
geometry: { type: 'Point', coordinates: at },
|
|
17
|
+
})
|
|
18
|
+
// The fake map doesn't put marker elements in the page: look inside the live markers
|
|
19
|
+
const live = () => created.markers.filter((m) => m.map).map((m) => m.element)
|
|
20
|
+
const inBubbles = <T extends Element = HTMLElement>(sel: string) => live().flatMap((el) => [...el.querySelectorAll<T>(sel)])
|
|
21
|
+
const frame = () => new Promise((r) => requestAnimationFrame(() => r(null)))
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
created.maps = []
|
|
25
|
+
created.markers = []
|
|
26
|
+
created.popups = []
|
|
27
|
+
document.documentElement.lang = 'en'
|
|
28
|
+
})
|
|
29
|
+
afterEach(() => { document.body.innerHTML = '' })
|
|
30
|
+
|
|
31
|
+
async function mountCluster(props: Record<string, unknown> = {}, slots: Record<string, unknown> = {}) {
|
|
32
|
+
const events: { cluster: unknown[]; click: unknown[] } = { cluster: [], click: [] }
|
|
33
|
+
const wrapper = mount(MMap, {
|
|
34
|
+
props: { mapStyle: 'https://x.test/style.json' },
|
|
35
|
+
slots: {
|
|
36
|
+
default: () => h(MMapCluster, {
|
|
37
|
+
data: points, id: 'spots', ...props,
|
|
38
|
+
onClusterClick: (c: unknown) => events.cluster.push(c),
|
|
39
|
+
onClick: (e: unknown) => events.click.push(e),
|
|
40
|
+
}, slots),
|
|
41
|
+
},
|
|
42
|
+
attachTo: document.body,
|
|
43
|
+
})
|
|
44
|
+
await flushPromises()
|
|
45
|
+
const map = created.maps.at(-1)! as FakeMap
|
|
46
|
+
map.load()
|
|
47
|
+
await nextTick()
|
|
48
|
+
await nextTick()
|
|
49
|
+
return { wrapper, map, events }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function showClusters(map: FakeMap, features: ReturnType<typeof cluster>[]) {
|
|
53
|
+
map.sourceFeatures = features
|
|
54
|
+
map.fire('moveend')
|
|
55
|
+
await frame()
|
|
56
|
+
await nextTick()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe('MMapCluster', () => {
|
|
60
|
+
it('adds a clustered source and a circle layer for the single points', async () => {
|
|
61
|
+
const { map } = await mountCluster({ radius: 60, maxZoom: 12 })
|
|
62
|
+
expect(map.sources.get('spots')!.spec).toMatchObject({ type: 'geojson', data: points, cluster: true, clusterRadius: 60, clusterMaxZoom: 12 })
|
|
63
|
+
const layer = map.layers.find((l) => l.id === 'spots-point-0')!
|
|
64
|
+
expect(layer).toMatchObject({ type: 'circle', source: 'spots', filter: ['!', ['has', 'point_count']] })
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('shows one bubble per cluster, sized by count, deduplicated across tiles', async () => {
|
|
68
|
+
const { map } = await mountCluster()
|
|
69
|
+
await showClusters(map, [cluster(1, 3, [-64.19, -31.42]), cluster(1, 3, [-64.19, -31.42]), cluster(2, 1500, [-64.3, -31.5])])
|
|
70
|
+
const buttons = inBubbles<HTMLButtonElement>('button')
|
|
71
|
+
expect(buttons.map((b) => b.textContent!.trim())).toEqual(['3', '1.5K'])
|
|
72
|
+
expect(buttons[0]!.getAttribute('aria-label')).toBe('3 places, zoom in')
|
|
73
|
+
expect(buttons[0]!.style.width).toBe('32px')
|
|
74
|
+
expect(buttons[1]!.style.width).toBe('56px')
|
|
75
|
+
expect(buttons[0]!.className).toContain('bg-primary')
|
|
76
|
+
expect(live()).toHaveLength(2)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('removes bubbles for clusters that are gone', async () => {
|
|
80
|
+
const { map } = await mountCluster()
|
|
81
|
+
await showClusters(map, [cluster(1, 3, [-64.19, -31.42]), cluster(2, 4, [-64.3, -31.5])])
|
|
82
|
+
await showClusters(map, [cluster(2, 4, [-64.3, -31.5])])
|
|
83
|
+
expect(inBubbles('button')).toHaveLength(1)
|
|
84
|
+
expect(live()).toHaveLength(1)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('zooms in on click, emitting cluster-click', async () => {
|
|
88
|
+
const { map, events } = await mountCluster()
|
|
89
|
+
await showClusters(map, [cluster(7, 5, [-64.19, -31.42])])
|
|
90
|
+
inBubbles<HTMLButtonElement>('button')[0]!.click()
|
|
91
|
+
await flushPromises()
|
|
92
|
+
expect(events.cluster).toHaveLength(1)
|
|
93
|
+
expect(events.cluster[0]).toMatchObject({ id: 7, count: 5, lngLat: [-64.19, -31.42] })
|
|
94
|
+
expect(map.flights).toContainEqual(['easeTo', { center: [-64.19, -31.42], zoom: 9 }])
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('leaves zooming to the consumer with zoomOnClick false, and gives the points', async () => {
|
|
98
|
+
const { map, events } = await mountCluster({ zoomOnClick: false })
|
|
99
|
+
map.sources.get('spots')!.leaves = points.features
|
|
100
|
+
await showClusters(map, [cluster(7, 3, [-64.19, -31.42])])
|
|
101
|
+
inBubbles<HTMLButtonElement>('button')[0]!.click()
|
|
102
|
+
await flushPromises()
|
|
103
|
+
expect(map.flights).toEqual([])
|
|
104
|
+
const leaves = await (events.cluster[0] as { leaves: (n?: number) => Promise<unknown[]> }).leaves(2)
|
|
105
|
+
expect(leaves).toHaveLength(2)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('takes a #cluster slot and a color', async () => {
|
|
109
|
+
const { map } = await mountCluster({ color: 'tertiary' }, {
|
|
110
|
+
cluster: ({ count, label }: { count: number; label: string }) => h('span', { class: 'mine' }, `${label}/${count}`),
|
|
111
|
+
})
|
|
112
|
+
await showClusters(map, [cluster(1, 2500, [-64.19, -31.42])])
|
|
113
|
+
expect(inBubbles('.mine')[0]!.textContent).toBe('2.5K/2500')
|
|
114
|
+
expect(inBubbles('button')).toEqual([])
|
|
115
|
+
expect(live()[0]!.className).toBe('m3-map-cluster')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('cleans up its source, layers and bubbles on unmount', async () => {
|
|
119
|
+
const { wrapper, map } = await mountCluster()
|
|
120
|
+
await showClusters(map, [cluster(1, 3, [-64.19, -31.42])])
|
|
121
|
+
expect(live()).toHaveLength(1)
|
|
122
|
+
wrapper.unmount()
|
|
123
|
+
expect(map.sources.has('spots')).toBe(false)
|
|
124
|
+
expect(map.layers.find((l) => l.id === 'spots-point-0')).toBeUndefined()
|
|
125
|
+
expect(live()).toHaveLength(0)
|
|
126
|
+
})
|
|
127
|
+
})
|