@m3ui-vue/m3ui-vue 0.8.5 → 0.8.7
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 +5 -1
- package/dist/{MMenuItem-BXIxwIdM.js → MMenuItem-DmrsQrK7.js} +2 -2
- package/dist/{MMenuItem-BXIxwIdM.js.map → MMenuItem-DmrsQrK7.js.map} +1 -1
- package/dist/chart.js +5 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBottomSheet.vue.d.ts +3 -3
- package/dist/components/MChatBubble.vue.d.ts +4 -2
- package/dist/components/MCheckbox.vue.d.ts +2 -0
- package/dist/components/MDragDropList.vue.d.ts +19 -6
- package/dist/components/MFileUpload.vue.d.ts +16 -4
- package/dist/components/MKanban.vue.d.ts +15 -6
- package/dist/components/MListDetail.vue.d.ts +31 -0
- package/dist/components/MNavigationRail.vue.d.ts +6 -3
- package/dist/components/MNavigationSuite.vue.d.ts +46 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +6 -1
- package/dist/components/MSideSheet.vue.d.ts +4 -4
- package/dist/components/MSupportingPane.vue.d.ts +34 -0
- package/dist/components/MTransferList.vue.d.ts +57 -30
- package/dist/components/MWindow.vue.d.ts +39 -1
- package/dist/components/_MTransferPane.vue.d.ts +46 -0
- package/dist/composables/_useItemLink.d.ts +30 -0
- package/dist/composables/_useSheetMotion.d.ts +7 -0
- package/dist/composables/useLocale.d.ts +27 -0
- package/dist/composables/useWindowSizeClass.d.ts +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/locales/index.js +196 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4331 -2945
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DbREg9Zn.js → useLocale-Bircp823.js} +29 -2
- package/dist/useLocale-Bircp823.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MChart.test.ts +28 -0
- package/src/__tests__/MChatBubble.test.ts +33 -0
- package/src/__tests__/MDragDropList.test.ts +194 -0
- package/src/__tests__/MFileUpload.test.ts +78 -0
- package/src/__tests__/MKanban.test.ts +150 -0
- package/src/__tests__/MPullToRefresh.test.ts +67 -0
- package/src/__tests__/MRating.test.ts +72 -0
- package/src/__tests__/MShortNavigationBar.test.ts +25 -0
- package/src/__tests__/MTransferList.test.ts +149 -0
- package/src/__tests__/MWindow.test.ts +258 -0
- package/src/__tests__/adaptiveLayouts.test.ts +191 -0
- package/src/__tests__/sheets.test.ts +76 -0
- package/src/components/MBottomSheet.vue +11 -57
- package/src/components/MChart.vue +2 -1
- package/src/components/MChatBubble.vue +107 -20
- package/src/components/MCheckbox.vue +3 -0
- package/src/components/MDragDropList.vue +485 -56
- package/src/components/MFileUpload.vue +56 -20
- package/src/components/MKanban.vue +720 -78
- package/src/components/MListDetail.vue +103 -0
- package/src/components/MNavigationRail.vue +48 -31
- package/src/components/MNavigationSuite.vue +89 -0
- package/src/components/MPullToRefresh.vue +101 -35
- package/src/components/MRating.vue +163 -67
- package/src/components/MResult.vue +19 -9
- package/src/components/MShortNavigationBar.vue +37 -17
- package/src/components/MSideSheet.vue +11 -56
- package/src/components/MSupportingPane.vue +70 -0
- package/src/components/MTransferList.vue +174 -137
- package/src/components/MWindow.vue +507 -108
- package/src/components/_MTransferPane.vue +260 -0
- package/src/composables/_useItemLink.ts +19 -0
- package/src/composables/_useSheetMotion.ts +181 -0
- package/src/composables/useLocale.ts +75 -0
- package/src/composables/useWindowSizeClass.ts +93 -0
- package/src/index.ts +6 -0
- package/src/locales/de.ts +37 -0
- package/src/locales/es.ts +37 -0
- package/src/locales/fr.ts +37 -0
- package/src/locales/ja.ts +37 -0
- package/src/locales/ko.ts +37 -0
- package/src/locales/pt.ts +37 -0
- package/src/locales/zh.ts +37 -0
- package/dist/useLocale-DbREg9Zn.js.map +0 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MKanban from '../components/MKanban.vue'
|
|
5
|
+
import type { KanbanColumn } from '../components/MKanban.vue'
|
|
6
|
+
|
|
7
|
+
const board = (): KanbanColumn[] => [
|
|
8
|
+
{ id: 'todo', title: 'To do', cards: [{ id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' }] },
|
|
9
|
+
{ id: 'doing', title: 'Doing', cards: [{ id: 'e' }], limit: 1 },
|
|
10
|
+
{ id: 'done', title: 'Done', cards: [] },
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
function rect(left: number, top: number, width: number, height: number) {
|
|
14
|
+
return { left, top, width, height, right: left + width, bottom: top + height, x: left, y: top, toJSON() {} } as DOMRect
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// happy-dom has no layout: columns 300px apart, card areas start at y=50, cards 56px + 8px gap.
|
|
18
|
+
function layout(w: ReturnType<typeof mount>) {
|
|
19
|
+
w.findAll('section').forEach((col, ci) => {
|
|
20
|
+
const left = ci * 300
|
|
21
|
+
col.element.getBoundingClientRect = () => rect(left, 0, 288, 600)
|
|
22
|
+
const area = col.find('[role="list"]').element as HTMLElement
|
|
23
|
+
area.getBoundingClientRect = () => rect(left, 50, 288, 500)
|
|
24
|
+
col.findAll('[role="listitem"]').forEach((card, i) => {
|
|
25
|
+
Object.defineProperty(card.element, 'offsetTop', { value: i * 64, configurable: true })
|
|
26
|
+
Object.defineProperty(card.element, 'offsetHeight', { value: 56, configurable: true })
|
|
27
|
+
card.element.getBoundingClientRect = () => rect(left + 12, 50 + i * 64, 264, 56)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function pointer(target: Element | Window, type: string, x: number, y: number) {
|
|
33
|
+
target.dispatchEvent(new PointerEvent(type, { bubbles: true, cancelable: true, button: 0, pointerId: 1, pointerType: 'mouse', clientX: x, clientY: y }))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function mountBoard() {
|
|
37
|
+
const w = mount(MKanban, {
|
|
38
|
+
props: { modelValue: board(), 'onUpdate:modelValue': (v: KanbanColumn[]) => w.setProps({ modelValue: v }) },
|
|
39
|
+
attachTo: document.body,
|
|
40
|
+
})
|
|
41
|
+
return w
|
|
42
|
+
}
|
|
43
|
+
const ids = (w: ReturnType<typeof mount>) =>
|
|
44
|
+
(w.props('modelValue') as KanbanColumn[]).map((c) => c.cards.map((x) => x.id).join(''))
|
|
45
|
+
const card = (w: ReturnType<typeof mount>, id: string) =>
|
|
46
|
+
w.findAll('[role="listitem"]').find((c) => c.text() === id)!
|
|
47
|
+
|
|
48
|
+
describe('MKanban', () => {
|
|
49
|
+
it('drags a card to another column', async () => {
|
|
50
|
+
const w = mountBoard()
|
|
51
|
+
layout(w)
|
|
52
|
+
pointer(card(w, 'a').element, 'pointerdown', 100, 70)
|
|
53
|
+
pointer(window, 'pointermove', 110, 70)
|
|
54
|
+
pointer(window, 'pointermove', 400, 70)
|
|
55
|
+
pointer(window, 'pointerup', 400, 70)
|
|
56
|
+
await nextTick()
|
|
57
|
+
expect(ids(w)).toEqual(['bcd', 'ae', ''])
|
|
58
|
+
expect(w.emitted('cardMove')![0]![0]).toEqual({ cardId: 'a', fromColumn: 'todo', toColumn: 'doing', toIndex: 0 })
|
|
59
|
+
w.unmount()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('reorders within a column without the old off-by-one', async () => {
|
|
63
|
+
const w = mountBoard()
|
|
64
|
+
layout(w)
|
|
65
|
+
// Drag "a" down so its center sits just above "c"'s middle: it should land between b and c.
|
|
66
|
+
pointer(card(w, 'a').element, 'pointerdown', 100, 70)
|
|
67
|
+
pointer(window, 'pointermove', 100, 80)
|
|
68
|
+
// The mock keeps b/c/d at their mount-time offsets (64/128/192, midpoints 92/156/220).
|
|
69
|
+
// A drag of +100px puts a's center at 128: past b's middle, before c's -> between b and c.
|
|
70
|
+
pointer(window, 'pointermove', 100, 170)
|
|
71
|
+
pointer(window, 'pointerup', 100, 170)
|
|
72
|
+
await nextTick()
|
|
73
|
+
expect(ids(w)[0]).toBe('bacd')
|
|
74
|
+
w.unmount()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('does not emit when a card is dropped where it was', async () => {
|
|
78
|
+
const w = mountBoard()
|
|
79
|
+
layout(w)
|
|
80
|
+
pointer(card(w, 'b').element, 'pointerdown', 100, 134)
|
|
81
|
+
pointer(window, 'pointermove', 100, 140)
|
|
82
|
+
pointer(window, 'pointerup', 100, 140)
|
|
83
|
+
await nextTick()
|
|
84
|
+
expect(w.emitted('cardMove')).toBeUndefined()
|
|
85
|
+
w.unmount()
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('moves cards with the keyboard and announces the column', async () => {
|
|
89
|
+
const w = mountBoard()
|
|
90
|
+
await card(w, 'a').trigger('keydown', { key: ' ' })
|
|
91
|
+
await card(w, 'a').trigger('keydown', { key: 'ArrowDown' })
|
|
92
|
+
expect(ids(w)[0]).toBe('bacd')
|
|
93
|
+
await card(w, 'a').trigger('keydown', { key: 'ArrowRight' })
|
|
94
|
+
expect(ids(w)).toEqual(['bcd', 'ea', ''])
|
|
95
|
+
expect(w.find('[aria-live]').text()).toBe('Moved to Doing, position 2 of 2.')
|
|
96
|
+
await card(w, 'a').trigger('keydown', { key: 'Escape' })
|
|
97
|
+
expect(ids(w)).toEqual(['abcd', 'e', ''])
|
|
98
|
+
w.unmount()
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('emits cardClick on click and Enter, but not after a drag', async () => {
|
|
102
|
+
const w = mountBoard()
|
|
103
|
+
layout(w)
|
|
104
|
+
await card(w, 'b').trigger('click')
|
|
105
|
+
await card(w, 'c').trigger('keydown', { key: 'Enter' })
|
|
106
|
+
expect(w.emitted('cardClick')!.map((e) => (e[0] as { card: { id: string } }).card.id)).toEqual(['b', 'c'])
|
|
107
|
+
const d = card(w, 'd').element
|
|
108
|
+
pointer(d, 'pointerdown', 100, 250)
|
|
109
|
+
pointer(window, 'pointermove', 100, 270)
|
|
110
|
+
pointer(window, 'pointerup', 100, 270)
|
|
111
|
+
d.dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
112
|
+
expect(w.emitted('cardClick')).toHaveLength(2)
|
|
113
|
+
w.unmount()
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('shows the WIP limit and flags it when exceeded', async () => {
|
|
117
|
+
const w = mountBoard()
|
|
118
|
+
const doingHeader = () => w.findAll('section')[1]!.find('header')
|
|
119
|
+
expect(doingHeader().text()).toContain('1/1')
|
|
120
|
+
await card(w, 'a').trigger('keydown', { key: ' ' })
|
|
121
|
+
await card(w, 'a').trigger('keydown', { key: 'ArrowRight' })
|
|
122
|
+
expect(doingHeader().text()).toContain('2/1')
|
|
123
|
+
expect(doingHeader().find('.bg-error-container').exists()).toBe(true)
|
|
124
|
+
w.unmount()
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
describe('MKanban card actions', () => {
|
|
129
|
+
it('does not fire cardClick or start a drag from buttons or data-kanban-action areas', async () => {
|
|
130
|
+
const w = mount(MKanban, {
|
|
131
|
+
props: { modelValue: board() },
|
|
132
|
+
slots: {
|
|
133
|
+
card: `<template #card="{ card }"><span class="title">{{ card.id }}</span><button class="btn">menu</button><span class="act" data-kanban-action>copy</span></template>`,
|
|
134
|
+
},
|
|
135
|
+
attachTo: document.body,
|
|
136
|
+
})
|
|
137
|
+
layout(w)
|
|
138
|
+
const first = w.findAll('[role="listitem"]')[0]!
|
|
139
|
+
await first.find('.btn').trigger('click')
|
|
140
|
+
await first.find('.act').trigger('click')
|
|
141
|
+
expect(w.emitted('cardClick')).toBeUndefined()
|
|
142
|
+
await first.find('.title').trigger('click')
|
|
143
|
+
expect(w.emitted('cardClick')).toHaveLength(1)
|
|
144
|
+
pointer(first.find('.act').element, 'pointerdown', 100, 70)
|
|
145
|
+
pointer(window, 'pointermove', 400, 70)
|
|
146
|
+
pointer(window, 'pointerup', 400, 70)
|
|
147
|
+
expect(w.emitted('cardMove')).toBeUndefined()
|
|
148
|
+
w.unmount()
|
|
149
|
+
})
|
|
150
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MPullToRefresh from '../components/MPullToRefresh.vue'
|
|
4
|
+
|
|
5
|
+
function touch(el: Element, type: string, y: number) {
|
|
6
|
+
const t = { identifier: 1, clientY: y, clientX: 0, target: el }
|
|
7
|
+
const ev = new Event(type, { bubbles: true, cancelable: true }) as Event & Record<string, unknown>
|
|
8
|
+
Object.assign(ev, {
|
|
9
|
+
touches: type === 'touchend' ? [] : [t],
|
|
10
|
+
changedTouches: [t],
|
|
11
|
+
})
|
|
12
|
+
el.dispatchEvent(ev)
|
|
13
|
+
return ev
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function mountPtr() {
|
|
17
|
+
const wrapper = mount(MPullToRefresh, { slots: { default: '<div>list</div>' }, attachTo: document.body })
|
|
18
|
+
const scrollEl = wrapper.find('.overflow-y-auto').element
|
|
19
|
+
return { wrapper, scrollEl }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('MPullToRefresh (touch)', () => {
|
|
23
|
+
it('blocks native scroll and emits refresh on a downward pull past threshold', () => {
|
|
24
|
+
const { wrapper, scrollEl } = mountPtr()
|
|
25
|
+
touch(scrollEl, 'touchstart', 100)
|
|
26
|
+
const move1 = touch(scrollEl, 'touchmove', 120)
|
|
27
|
+
const move2 = touch(scrollEl, 'touchmove', 200)
|
|
28
|
+
touch(scrollEl, 'touchend', 200)
|
|
29
|
+
expect(move1.defaultPrevented).toBe(true)
|
|
30
|
+
expect(move2.defaultPrevented).toBe(true)
|
|
31
|
+
expect(wrapper.emitted('refresh')).toHaveLength(1)
|
|
32
|
+
wrapper.unmount()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('does not refresh on a short pull', () => {
|
|
36
|
+
const { wrapper, scrollEl } = mountPtr()
|
|
37
|
+
touch(scrollEl, 'touchstart', 100)
|
|
38
|
+
touch(scrollEl, 'touchmove', 130)
|
|
39
|
+
touch(scrollEl, 'touchend', 130)
|
|
40
|
+
expect(wrapper.emitted('refresh')).toBeUndefined()
|
|
41
|
+
wrapper.unmount()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('leaves an upward swipe to native scrolling', () => {
|
|
45
|
+
const { wrapper, scrollEl } = mountPtr()
|
|
46
|
+
touch(scrollEl, 'touchstart', 200)
|
|
47
|
+
const up = touch(scrollEl, 'touchmove', 150)
|
|
48
|
+
const down = touch(scrollEl, 'touchmove', 300)
|
|
49
|
+
touch(scrollEl, 'touchend', 300)
|
|
50
|
+
expect(up.defaultPrevented).toBe(false)
|
|
51
|
+
expect(down.defaultPrevented).toBe(false)
|
|
52
|
+
expect(wrapper.emitted('refresh')).toBeUndefined()
|
|
53
|
+
wrapper.unmount()
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('ignores touches when the list is scrolled down', () => {
|
|
57
|
+
const { wrapper, scrollEl } = mountPtr()
|
|
58
|
+
;(scrollEl as HTMLElement).scrollTop = 50
|
|
59
|
+
Object.defineProperty(scrollEl, 'scrollTop', { value: 50, configurable: true })
|
|
60
|
+
touch(scrollEl, 'touchstart', 100)
|
|
61
|
+
const move = touch(scrollEl, 'touchmove', 250)
|
|
62
|
+
touch(scrollEl, 'touchend', 250)
|
|
63
|
+
expect(move.defaultPrevented).toBe(false)
|
|
64
|
+
expect(wrapper.emitted('refresh')).toBeUndefined()
|
|
65
|
+
wrapper.unmount()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MRating from '../components/MRating.vue'
|
|
4
|
+
|
|
5
|
+
// Items are laid out as 32px-wide boxes (size 28 + 4) starting at x=0.
|
|
6
|
+
function mockLayout(wrapper: ReturnType<typeof mount>) {
|
|
7
|
+
const items = wrapper.findAll('[role="slider"] > span')
|
|
8
|
+
items.forEach((item, i) => {
|
|
9
|
+
const left = i * 32
|
|
10
|
+
item.element.getBoundingClientRect = () =>
|
|
11
|
+
({ left, right: left + 32, width: 32, top: 0, bottom: 32, height: 32, x: left, y: 0 }) as DOMRect
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function filledWidths(wrapper: ReturnType<typeof mount>) {
|
|
16
|
+
return wrapper.findAll('.start-0.overflow-hidden').map((el) => el.attributes('style'))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('MRating', () => {
|
|
20
|
+
it('renders the filled part of a half value', () => {
|
|
21
|
+
const wrapper = mount(MRating, { props: { modelValue: 2.5 } })
|
|
22
|
+
const widths = filledWidths(wrapper)
|
|
23
|
+
expect(widths[1]).toContain('width: 100%')
|
|
24
|
+
expect(widths[2]).toContain('width: 50%')
|
|
25
|
+
expect(widths[3]).toContain('width: 0%')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('renders arbitrary fractions exactly', () => {
|
|
29
|
+
const wrapper = mount(MRating, { props: { modelValue: 4.25, readonly: true } })
|
|
30
|
+
expect(filledWidths(wrapper)[4]).toContain('width: 25%')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('does not reset to 0 when clicking the current value again', async () => {
|
|
34
|
+
const wrapper = mount(MRating, { props: { modelValue: 3 } })
|
|
35
|
+
mockLayout(wrapper)
|
|
36
|
+
const root = wrapper.find('[role="slider"]')
|
|
37
|
+
root.element.setPointerCapture = () => {}
|
|
38
|
+
root.element.releasePointerCapture = () => {}
|
|
39
|
+
await root.trigger('pointerdown', { button: 0, clientX: 80, pointerId: 1 })
|
|
40
|
+
await root.trigger('pointerup', { pointerId: 1 })
|
|
41
|
+
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('picks a half value from the left half of an item', async () => {
|
|
45
|
+
const wrapper = mount(MRating, { props: { modelValue: 0, halfIncrements: true } })
|
|
46
|
+
mockLayout(wrapper)
|
|
47
|
+
const root = wrapper.find('[role="slider"]')
|
|
48
|
+
root.element.setPointerCapture = () => {}
|
|
49
|
+
await root.trigger('pointerdown', { button: 0, clientX: 70, pointerId: 1 })
|
|
50
|
+
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([2.5])
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('steps with the keyboard and clamps to range', async () => {
|
|
54
|
+
const wrapper = mount(MRating, { props: { modelValue: 1, halfIncrements: true } })
|
|
55
|
+
const root = wrapper.find('[role="slider"]')
|
|
56
|
+
await root.trigger('keydown', { key: 'ArrowRight' })
|
|
57
|
+
await root.trigger('keydown', { key: 'Home' })
|
|
58
|
+
await root.trigger('keydown', { key: 'End' })
|
|
59
|
+
expect(wrapper.emitted('update:modelValue')).toEqual([[1.5], [0], [5]])
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('ignores input when readonly or disabled', async () => {
|
|
63
|
+
const ro = mount(MRating, { props: { modelValue: 2, readonly: true } })
|
|
64
|
+
await ro.find('[role="img"]').trigger('keydown', { key: 'ArrowRight' })
|
|
65
|
+
expect(ro.emitted('update:modelValue')).toBeUndefined()
|
|
66
|
+
|
|
67
|
+
const dis = mount(MRating, { props: { modelValue: 2, disabled: true } })
|
|
68
|
+
expect(dis.find('[role="slider"]').attributes('tabindex')).toBeUndefined()
|
|
69
|
+
await dis.find('[role="slider"]').trigger('keydown', { key: 'ArrowRight' })
|
|
70
|
+
expect(dis.emitted('update:modelValue')).toBeUndefined()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MShortNavigationBar from '../components/MShortNavigationBar.vue'
|
|
4
|
+
|
|
5
|
+
const items = [
|
|
6
|
+
{ value: 'home', label: 'Home', icon: 'home' },
|
|
7
|
+
{ value: 'off', label: 'Off', icon: 'block', disabled: true },
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
describe('MShortNavigationBar', () => {
|
|
11
|
+
it.each(['top', 'start'] as const)('disabled items look disabled and never select (iconPosition %s)', async (iconPosition) => {
|
|
12
|
+
const w = mount(MShortNavigationBar, { props: { modelValue: 'home', items, iconPosition } })
|
|
13
|
+
const [home, off] = w.findAll('button')
|
|
14
|
+
expect(off!.attributes('disabled')).toBeDefined()
|
|
15
|
+
expect(off!.classes()).toContain('cursor-not-allowed')
|
|
16
|
+
expect(off!.html()).toContain('text-on-surface-variant/38')
|
|
17
|
+
expect(off!.html()).not.toContain('group-hover:')
|
|
18
|
+
expect(home!.html()).not.toContain('/38')
|
|
19
|
+
|
|
20
|
+
// Even if the click reaches it (e.g. the disabled attribute is stripped), nothing is emitted.
|
|
21
|
+
off!.element.removeAttribute('disabled')
|
|
22
|
+
await off!.trigger('click')
|
|
23
|
+
expect(w.emitted('update:modelValue')).toBeUndefined()
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MTransferList from '../components/MTransferList.vue'
|
|
4
|
+
import type { TransferItem } from '../components/MTransferList.vue'
|
|
5
|
+
|
|
6
|
+
const items: TransferItem[] = [
|
|
7
|
+
{ value: 1, label: 'Ana', description: 'ana@acme.dev' },
|
|
8
|
+
{ value: 2, label: 'Luis', description: 'luis@acme.dev' },
|
|
9
|
+
{ value: 3, label: 'Marta', description: 'marta@acme.dev' },
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
function setup(modelValue: (string | number)[] = [], extra: Record<string, unknown> = {}) {
|
|
13
|
+
const w = mount(MTransferList, {
|
|
14
|
+
props: { modelValue, items, filterable: true, ...extra, 'onUpdate:modelValue': (v: (string | number)[]) => w.setProps({ modelValue: v }) },
|
|
15
|
+
attachTo: document.body,
|
|
16
|
+
})
|
|
17
|
+
return w
|
|
18
|
+
}
|
|
19
|
+
const panes = (w: ReturnType<typeof setup>) => w.findAll('section')
|
|
20
|
+
const rows = (w: ReturnType<typeof setup>, pane: number) => panes(w)[pane]!.findAll('li')
|
|
21
|
+
const btn = (w: ReturnType<typeof setup>, label: string) => w.findAll('button').find((b) => b.attributes('aria-label') === label)!
|
|
22
|
+
const lastValue = (w: ReturnType<typeof setup>) => w.emitted('update:modelValue')!.at(-1)![0]
|
|
23
|
+
|
|
24
|
+
describe('MTransferList', () => {
|
|
25
|
+
it('clicking a row checkbox checks it once (no double toggle)', async () => {
|
|
26
|
+
const w = setup()
|
|
27
|
+
await rows(w, 0)[0]!.find('input[type="checkbox"]').trigger('click')
|
|
28
|
+
expect(btn(w, 'Move selected right').attributes('disabled')).toBeUndefined()
|
|
29
|
+
await btn(w, 'Move selected right').trigger('click')
|
|
30
|
+
expect(lastValue(w)).toEqual([1])
|
|
31
|
+
w.unmount()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('clicking anywhere else on the row toggles it', async () => {
|
|
35
|
+
const w = setup()
|
|
36
|
+
await rows(w, 0)[1]!.trigger('click')
|
|
37
|
+
expect(rows(w, 0)[1]!.classes()).toContain('bg-secondary-container')
|
|
38
|
+
await rows(w, 0)[1]!.trigger('click')
|
|
39
|
+
expect(rows(w, 0)[1]!.classes()).not.toContain('bg-secondary-container')
|
|
40
|
+
w.unmount()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('select all checks every visible item and shows a count', async () => {
|
|
44
|
+
const w = setup()
|
|
45
|
+
await panes(w)[0]!.find('header input[type="checkbox"]').trigger('click')
|
|
46
|
+
expect(panes(w)[0]!.find('header').text()).toContain('3/3')
|
|
47
|
+
await btn(w, 'Move selected right').trigger('click')
|
|
48
|
+
expect(lastValue(w)).toEqual([1, 2, 3])
|
|
49
|
+
w.unmount()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('search matches the description too', async () => {
|
|
53
|
+
const w = setup()
|
|
54
|
+
await panes(w)[0]!.find('input[type="text"]').setValue('marta@')
|
|
55
|
+
expect(rows(w, 0)).toHaveLength(1)
|
|
56
|
+
expect(rows(w, 0)[0]!.text()).toContain('Marta')
|
|
57
|
+
w.unmount()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('double-click and Enter move a single item across', async () => {
|
|
61
|
+
const w = setup()
|
|
62
|
+
await rows(w, 0)[0]!.trigger('dblclick')
|
|
63
|
+
expect(lastValue(w)).toEqual([1])
|
|
64
|
+
await rows(w, 1)[0]!.trigger('keydown', { key: 'Enter' })
|
|
65
|
+
expect(lastValue(w)).toEqual([])
|
|
66
|
+
w.unmount()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('keeps the custom empty slots', () => {
|
|
70
|
+
const w = mount(MTransferList, {
|
|
71
|
+
props: { modelValue: [], items },
|
|
72
|
+
slots: { 'target-empty': '<p class="custom-empty">Nobody yet</p>' },
|
|
73
|
+
})
|
|
74
|
+
expect(w.find('.custom-empty').text()).toBe('Nobody yet')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('pins leaving rows at their own offset on "move all" instead of stacking them', async () => {
|
|
78
|
+
const w = mount(MTransferList, {
|
|
79
|
+
props: { modelValue: [], items, 'onUpdate:modelValue': (v: (string | number)[]) => w.setProps({ modelValue: v }) },
|
|
80
|
+
attachTo: document.body,
|
|
81
|
+
global: { stubs: { 'transition-group': false } },
|
|
82
|
+
})
|
|
83
|
+
// happy-dom has no layout: model the flow, where a row without a pinned `top` sits after
|
|
84
|
+
// its in-flow (non-leaving) siblings, like the browser's static position does.
|
|
85
|
+
for (const li of rows(w, 0).map((r) => r.element as HTMLElement)) {
|
|
86
|
+
Object.defineProperty(li, 'offsetTop', {
|
|
87
|
+
configurable: true,
|
|
88
|
+
get() {
|
|
89
|
+
if (this.style.top) return parseFloat(this.style.top)
|
|
90
|
+
let n = 0
|
|
91
|
+
for (let p = this.previousElementSibling; p; p = p.previousElementSibling) {
|
|
92
|
+
if (![...p.classList].some((c: string) => c.endsWith('-leave-active'))) n++
|
|
93
|
+
}
|
|
94
|
+
return 4 + n * 56
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
const leaving = rows(w, 0).map((r) => r.element as HTMLElement)
|
|
99
|
+
await btn(w, 'Move all right').trigger('click')
|
|
100
|
+
expect(leaving.map((li) => li.style.top)).toEqual(['4px', '60px', '116px'])
|
|
101
|
+
w.unmount()
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('#item replaces the row content, keeps the checkbox and tells each pane apart', () => {
|
|
105
|
+
const w = mount(MTransferList, {
|
|
106
|
+
props: { modelValue: [2], items },
|
|
107
|
+
slots: { item: `<template #item="{ item, side, checked }"><b class="custom">{{ side }}:{{ item.label }}:{{ checked }}</b></template>` },
|
|
108
|
+
})
|
|
109
|
+
expect(rows(w, 0).map((r) => r.find('.custom').text())).toEqual(['source:Ana:false', 'source:Marta:false'])
|
|
110
|
+
expect(rows(w, 1)[0]!.find('.custom').text()).toBe('target:Luis:false')
|
|
111
|
+
expect(rows(w, 0)[0]!.find('input[type="checkbox"]').exists()).toBe(true)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('controls inside #item keep their clicks instead of checking or moving the row', async () => {
|
|
115
|
+
let hits = 0
|
|
116
|
+
const w = mount(MTransferList, {
|
|
117
|
+
props: { modelValue: [], items, 'onUpdate:modelValue': (v: (string | number)[]) => w.setProps({ modelValue: v }) },
|
|
118
|
+
slots: { item: `<template #item="{ item }"><span>{{ item.label }}</span><button class="act">x</button><span data-transfer-action class="mark">m</span></template>` },
|
|
119
|
+
})
|
|
120
|
+
rows(w, 0)[0]!.find('.act').element.addEventListener('click', () => hits++)
|
|
121
|
+
await rows(w, 0)[0]!.find('.act').trigger('click')
|
|
122
|
+
await rows(w, 0)[0]!.find('.act').trigger('dblclick')
|
|
123
|
+
await rows(w, 0)[0]!.find('.mark').trigger('click')
|
|
124
|
+
await rows(w, 0)[0]!.find('.act').trigger('keydown', { key: 'Enter' })
|
|
125
|
+
expect(hits).toBe(1)
|
|
126
|
+
expect(rows(w, 0)[0]!.classes()).not.toContain('bg-secondary-container')
|
|
127
|
+
expect(w.emitted('update:modelValue')).toBeUndefined()
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('bare rows are drawn by the slot and work as checkboxes', async () => {
|
|
131
|
+
const w = mount(MTransferList, {
|
|
132
|
+
props: { modelValue: [], items, bare: true, 'onUpdate:modelValue': (v: (string | number)[]) => w.setProps({ modelValue: v }) },
|
|
133
|
+
slots: { item: `<template #item="{ item, checked, move }"><div class="card" :data-checked="checked">{{ item.label }}<button class="go" @click="move">go</button></div></template>` },
|
|
134
|
+
})
|
|
135
|
+
const row = rows(w, 0)[0]!
|
|
136
|
+
expect(row.find('input[type="checkbox"]').exists()).toBe(false)
|
|
137
|
+
expect(row.attributes('role')).toBe('checkbox')
|
|
138
|
+
expect(row.attributes('tabindex')).toBe('0')
|
|
139
|
+
await row.find('.card').trigger('click')
|
|
140
|
+
expect(row.attributes('aria-checked')).toBe('true')
|
|
141
|
+
expect(row.find('.card').attributes('data-checked')).toBe('true')
|
|
142
|
+
await row.trigger('keydown', { key: ' ' })
|
|
143
|
+
expect(row.attributes('aria-checked')).toBe('false')
|
|
144
|
+
await row.trigger('keydown', { key: 'Enter' })
|
|
145
|
+
expect(lastValue(w)).toEqual([1])
|
|
146
|
+
await rows(w, 0)[0]!.find('.go').trigger('click')
|
|
147
|
+
expect(lastValue(w)).toEqual([1, 2])
|
|
148
|
+
})
|
|
149
|
+
})
|