@veltra/desktop 1.14.0 → 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/auto-complete/style.d.ts +0 -1
- package/dist/components/cascade/cascade.js +13 -19
- package/dist/components/cascade/cascade.js.map +1 -1
- package/dist/components/cascade/style.d.ts +1 -3
- package/dist/components/checkbox/checkbox.js +5 -11
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/checkbox/style.d.ts +1 -1
- package/dist/components/checkbox/style.js +0 -1
- package/dist/components/checkbox-group/style.d.ts +1 -1
- package/dist/components/chip/chip.js +63 -0
- package/dist/components/chip/chip.js.map +1 -0
- package/dist/components/chip/style.d.ts +1 -0
- package/dist/components/chip/style.js +1 -0
- package/dist/components/chip/style2.css +90 -0
- package/dist/components/chip-group/chip-group.js +279 -0
- package/dist/components/chip-group/chip-group.js.map +1 -0
- package/dist/components/chip-group/reveal.js +80 -0
- package/dist/components/chip-group/reveal.js.map +1 -0
- package/dist/components/chip-group/style.d.ts +1 -0
- package/dist/components/chip-group/style.js +2 -0
- package/dist/components/chip-group/style2.css +68 -0
- package/dist/components/condition-editor/style.d.ts +0 -1
- package/dist/components/date-picker/style.d.ts +1 -2
- package/dist/components/date-range-picker/date-range-picker.js +14 -20
- package/dist/components/date-range-picker/date-range-picker.js.map +1 -1
- package/dist/components/dialog/dialog.js +5 -2
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/dialog/style2.css +0 -10
- package/dist/components/dialog/use-maximum.js +77 -20
- package/dist/components/dialog/use-maximum.js.map +1 -1
- package/dist/components/drawer/drawer.js +57 -54
- package/dist/components/drawer/drawer.js.map +1 -1
- package/dist/components/drawer/style.d.ts +1 -1
- package/dist/components/drawer/style.js +0 -1
- package/dist/components/drawer/style2.css +139 -15
- package/dist/components/form-item/style2.css +1 -1
- package/dist/components/index.d.ts +32 -30
- package/dist/components/index.js +63 -59
- package/dist/components/index.js.map +1 -1
- package/dist/components/input/input.js.map +1 -1
- package/dist/components/input/input.vue_vue_type_script_setup_true_lang.js +13 -19
- package/dist/components/input/input.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/input/style.d.ts +1 -1
- package/dist/components/input/style.js +0 -1
- package/dist/components/message/style2.css +13 -0
- package/dist/components/message-confirm/style2.css +10 -0
- package/dist/components/multi-select/multi-select.js +19 -21
- package/dist/components/multi-select/multi-select.js.map +1 -1
- package/dist/components/multi-select/style.d.ts +1 -4
- package/dist/components/multi-select/style.js +0 -1
- package/dist/components/multi-tree-select/multi-tree-select.js +20 -22
- package/dist/components/multi-tree-select/multi-tree-select.js.map +1 -1
- package/dist/components/multi-tree-select/style.d.ts +1 -5
- package/dist/components/multi-tree-select/style.js +0 -1
- package/dist/components/nav/nav-sub.js +56 -51
- package/dist/components/nav/nav-sub.js.map +1 -1
- package/dist/components/notification/notification-box.js +4 -2
- package/dist/components/notification/notification-box.js.map +1 -1
- package/dist/components/notification/style2.css +16 -0
- package/dist/components/number-input/style.d.ts +0 -1
- package/dist/components/palette/style.d.ts +1 -2
- package/dist/components/password-input/style.d.ts +1 -1
- package/dist/components/radio/radio.js +5 -8
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/radio/style.d.ts +1 -1
- package/dist/components/radio/style.js +0 -1
- package/dist/components/radio-group/style.d.ts +1 -1
- package/dist/components/rich-text-editor/style2.css +2 -2
- package/dist/components/scroll/style2.css +27 -13
- package/dist/components/segment/segment.js +50 -3
- package/dist/components/segment/segment.js.map +1 -1
- package/dist/components/segment/style2.css +20 -2
- package/dist/components/select/select.js +24 -25
- package/dist/components/select/select.js.map +1 -1
- package/dist/components/select/style.d.ts +0 -1
- package/dist/components/switch/style2.css +1 -1
- package/dist/components/table/style.d.ts +1 -3
- package/dist/components/tabs/style.d.ts +1 -2
- package/dist/components/tabs/style.js +0 -1
- package/dist/components/tabs/style2.css +29 -0
- package/dist/components/tabs/tabs-horizontal.js +7 -3
- package/dist/components/tabs/tabs-horizontal.js.map +1 -1
- package/dist/components/tabs/tabs.js +2 -8
- package/dist/components/tabs/tabs.js.map +1 -1
- package/dist/components/tabs/use-tabs-bar.js +41 -9
- package/dist/components/tabs/use-tabs-bar.js.map +1 -1
- package/dist/components/tag/style2.css +3 -3
- package/dist/components/textarea/style.d.ts +1 -1
- package/dist/components/textarea/style.js +0 -1
- package/dist/components/textarea/textarea.js +7 -13
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/theme/style.d.ts +0 -1
- package/dist/components/theme/style2.css +9 -5
- package/dist/components/time-picker/style.d.ts +1 -2
- package/dist/components/tip/style2.css +5 -5
- package/dist/components/tip/tip.js +22 -1
- package/dist/components/tip/tip.js.map +1 -1
- package/dist/components/transfer/style.d.ts +1 -2
- package/dist/components/tree/style.d.ts +1 -1
- package/dist/components/tree-select/style.d.ts +1 -3
- package/dist/components/tree-select/tree-select.js +24 -25
- package/dist/components/tree-select/tree-select.js.map +1 -1
- package/dist/index.d.ts +86 -82
- package/dist/index.js +84 -82
- package/dist/style.d.ts +0 -9
- package/dist/style.js +2 -0
- package/dist/types/chip-group.d.ts +35 -0
- package/dist/types/chip.d.ts +28 -0
- package/dist/types/index.d.ts +3 -1
- package/package.json +1 -1
- package/src/components/cascade/cascade.vue +9 -11
- package/src/components/checkbox/checkbox.vue +6 -8
- package/src/components/checkbox/style.ts +0 -1
- package/src/components/chip/__test__/chip.test.ts +69 -0
- package/src/components/chip/chip.vue +54 -0
- package/src/components/chip/index.ts +1 -0
- package/src/components/chip/style.scss +91 -0
- package/src/components/chip/style.ts +1 -0
- package/src/components/chip-group/__test__/chip-group.test.ts +411 -0
- package/src/components/chip-group/__test__/reveal.test.ts +74 -0
- package/src/components/chip-group/chip-group.vue +326 -0
- package/src/components/chip-group/index.ts +1 -0
- package/src/components/chip-group/reveal.ts +106 -0
- package/src/components/chip-group/style.scss +72 -0
- package/src/components/chip-group/style.ts +2 -0
- package/src/components/date-range-picker/date-range-picker.vue +10 -12
- package/src/components/dialog/dialog.vue +2 -1
- package/src/components/dialog/style.scss +0 -12
- package/src/components/dialog/use-maximum.ts +88 -28
- package/src/components/drawer/__test__/drawer.test.ts +23 -2
- package/src/components/drawer/drawer.vue +49 -40
- package/src/components/drawer/style.scss +63 -53
- package/src/components/drawer/style.ts +0 -1
- package/src/components/form-item/style.scss +2 -2
- package/src/components/index.ts +4 -0
- package/src/components/input/input.vue +14 -16
- package/src/components/input/style.ts +0 -1
- package/src/components/message/style.scss +15 -0
- package/src/components/message-confirm/style.scss +14 -0
- package/src/components/multi-select/__test__/multi-select.test.ts +47 -0
- package/src/components/multi-select/multi-select.vue +14 -12
- package/src/components/multi-select/style.ts +0 -1
- package/src/components/multi-tree-select/__test__/multi-tree-select.test.ts +41 -0
- package/src/components/multi-tree-select/multi-tree-select.vue +20 -13
- package/src/components/multi-tree-select/style.ts +0 -1
- package/src/components/nav/nav-sub.vue +22 -11
- package/src/components/notification/notification-box.vue +5 -2
- package/src/components/notification/style.scss +18 -0
- package/src/components/radio/radio.vue +1 -3
- package/src/components/radio/style.ts +0 -1
- package/src/components/rich-text-editor/style.scss +7 -2
- package/src/components/scroll/style.scss +39 -20
- package/src/components/segment/segment.vue +44 -2
- package/src/components/segment/style.scss +22 -2
- package/src/components/select/select.vue +24 -19
- package/src/components/switch/style.scss +4 -1
- package/src/components/tabs/style.scss +35 -0
- package/src/components/tabs/style.ts +0 -1
- package/src/components/tabs/tabs-horizontal.vue +2 -1
- package/src/components/tabs/tabs.vue +4 -6
- package/src/components/tabs/use-tabs-bar.ts +55 -8
- package/src/components/tag/style.scss +4 -4
- package/src/components/textarea/style.ts +0 -1
- package/src/components/textarea/textarea.vue +7 -9
- package/src/components/theme/style.scss +25 -5
- package/src/components/tip/style.scss +5 -5
- package/src/components/tip/tip.vue +33 -1
- package/src/components/tree-select/tree-select.vue +21 -17
- package/src/style.ts +2 -0
- package/src/types/chip-group.ts +36 -0
- package/src/types/chip.ts +29 -0
- package/src/types/index.ts +2 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it, vi } from 'vite-plus/test'
|
|
4
|
+
import { createApp, h, nextTick, ref } from 'vue'
|
|
5
|
+
|
|
6
|
+
import UChipGroup from '../chip-group.vue'
|
|
7
|
+
|
|
8
|
+
const items = [
|
|
9
|
+
{ label: 'A', value: 'a' },
|
|
10
|
+
{ label: 'B', value: 'b' },
|
|
11
|
+
{ label: 'C', value: 'c' }
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
function mountChipGroup(props: Record<string, unknown> = {}, groupItems = items) {
|
|
15
|
+
const host = document.createElement('div')
|
|
16
|
+
document.body.appendChild(host)
|
|
17
|
+
|
|
18
|
+
const model = ref(props.modelValue)
|
|
19
|
+
const changes: unknown[] = []
|
|
20
|
+
|
|
21
|
+
const app = createApp({
|
|
22
|
+
render() {
|
|
23
|
+
return h(UChipGroup, {
|
|
24
|
+
...props,
|
|
25
|
+
items: groupItems as any,
|
|
26
|
+
modelValue: model.value,
|
|
27
|
+
'onUpdate:modelValue': (value: any) => {
|
|
28
|
+
model.value = value
|
|
29
|
+
},
|
|
30
|
+
onChange: (item: any) => {
|
|
31
|
+
changes.push(item)
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
app.mount(host)
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
host,
|
|
41
|
+
model,
|
|
42
|
+
changes,
|
|
43
|
+
unmount() {
|
|
44
|
+
app.unmount()
|
|
45
|
+
host.remove()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function queryRoot(host: HTMLElement) {
|
|
51
|
+
return host.querySelector<HTMLElement>('.u-chip-group')!
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function queryViewport(host: HTMLElement) {
|
|
55
|
+
return host.querySelector<HTMLElement>('.u-chip-group__viewport')!
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function queryChips(host: HTMLElement) {
|
|
59
|
+
return [...host.querySelectorAll<HTMLElement>('.u-chip')]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function queryInputs(host: HTMLElement) {
|
|
63
|
+
return queryChips(host).map((chip) => chip.querySelector<HTMLInputElement>('input')!)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function rect(left: number, width: number): DOMRect {
|
|
67
|
+
return {
|
|
68
|
+
x: left,
|
|
69
|
+
y: 0,
|
|
70
|
+
left,
|
|
71
|
+
top: 0,
|
|
72
|
+
width,
|
|
73
|
+
height: 32,
|
|
74
|
+
right: left + width,
|
|
75
|
+
bottom: 32,
|
|
76
|
+
toJSON() {
|
|
77
|
+
return {}
|
|
78
|
+
}
|
|
79
|
+
} as DOMRect
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function mockOverflow(
|
|
83
|
+
viewport: HTMLElement,
|
|
84
|
+
chip: HTMLElement,
|
|
85
|
+
chipLeft: number,
|
|
86
|
+
chipWidth: number
|
|
87
|
+
) {
|
|
88
|
+
let scrollLeft = 0
|
|
89
|
+
vi.spyOn(viewport, 'getBoundingClientRect').mockReturnValue(rect(0, 200))
|
|
90
|
+
vi.spyOn(chip, 'getBoundingClientRect').mockImplementation(() =>
|
|
91
|
+
rect(chipLeft - scrollLeft, chipWidth)
|
|
92
|
+
)
|
|
93
|
+
Object.defineProperty(viewport, 'clientWidth', { configurable: true, value: 200 })
|
|
94
|
+
Object.defineProperty(viewport, 'scrollWidth', { configurable: true, value: 800 })
|
|
95
|
+
Object.defineProperty(viewport, 'scrollLeft', {
|
|
96
|
+
configurable: true,
|
|
97
|
+
get: () => scrollLeft,
|
|
98
|
+
set: (value: number) => {
|
|
99
|
+
scrollLeft = value
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function pick(host: HTMLElement, index: number) {
|
|
105
|
+
const input = queryInputs(host)[index]!
|
|
106
|
+
input.checked = true
|
|
107
|
+
input.dispatchEvent(new Event('change', { bubbles: true }))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
describe('ChipGroup', () => {
|
|
111
|
+
it('基础渲染:胶囊选项与选中态', async () => {
|
|
112
|
+
const { host, unmount } = mountChipGroup({ modelValue: 'a' })
|
|
113
|
+
await nextTick()
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const root = queryRoot(host)
|
|
117
|
+
expect(root).toBeTruthy()
|
|
118
|
+
expect(host.querySelector('[role="radiogroup"]')?.getAttribute('aria-orientation')).toBe(
|
|
119
|
+
'horizontal'
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const chips = queryChips(host)
|
|
123
|
+
expect(chips.length).toBe(3)
|
|
124
|
+
expect(chips[0]!.textContent).toContain('A')
|
|
125
|
+
expect(chips[0]!.classList.contains('is-checked')).toBe(true)
|
|
126
|
+
expect(chips[1]!.classList.contains('is-checked')).toBe(false)
|
|
127
|
+
expect(chips.every((chip) => chip.querySelector('.u-chip__face'))).toBe(true)
|
|
128
|
+
} finally {
|
|
129
|
+
unmount()
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('同一组 radio 共享 name', async () => {
|
|
134
|
+
const { host, unmount } = mountChipGroup({ modelValue: 'a' })
|
|
135
|
+
await nextTick()
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const names = queryInputs(host).map((input) => input.name)
|
|
139
|
+
expect(names[0]).toBeTruthy()
|
|
140
|
+
expect(new Set(names).size).toBe(1)
|
|
141
|
+
} finally {
|
|
142
|
+
unmount()
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('禁用项呈禁用态且原生不可选中', async () => {
|
|
147
|
+
const { host, unmount } = mountChipGroup({
|
|
148
|
+
modelValue: 'a',
|
|
149
|
+
disabledItem: (item: any) => item.value === 'b'
|
|
150
|
+
})
|
|
151
|
+
await nextTick()
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
const chips = queryChips(host)
|
|
155
|
+
expect(chips[1]!.classList.contains('is-disabled')).toBe(true)
|
|
156
|
+
|
|
157
|
+
const inputs = queryInputs(host)
|
|
158
|
+
expect(inputs[0]!.disabled).toBe(false)
|
|
159
|
+
expect(inputs[1]!.disabled).toBe(true)
|
|
160
|
+
} finally {
|
|
161
|
+
unmount()
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('点击选项更新 modelValue 并 emit change(参数为 item)', async () => {
|
|
166
|
+
const { host, model, changes, unmount } = mountChipGroup({ modelValue: 'a' })
|
|
167
|
+
await nextTick()
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
pick(host, 1)
|
|
171
|
+
await nextTick()
|
|
172
|
+
|
|
173
|
+
expect(model.value).toBe('b')
|
|
174
|
+
expect(changes).toEqual([items[1]])
|
|
175
|
+
expect(queryChips(host)[1]!.classList.contains('is-checked')).toBe(true)
|
|
176
|
+
} finally {
|
|
177
|
+
unmount()
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
it('完全可见时点击直接选中', async () => {
|
|
182
|
+
const { host, model, unmount } = mountChipGroup({ modelValue: 'a' })
|
|
183
|
+
await nextTick()
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
const viewport = queryViewport(host)
|
|
187
|
+
const scrollTo = vi.spyOn(viewport, 'scrollTo')
|
|
188
|
+
queryChips(host)[2]!.click()
|
|
189
|
+
await nextTick()
|
|
190
|
+
|
|
191
|
+
expect(scrollTo).not.toHaveBeenCalled()
|
|
192
|
+
expect(model.value).toBe('c')
|
|
193
|
+
} finally {
|
|
194
|
+
unmount()
|
|
195
|
+
}
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('贴边或被截断时先滚入可视区再选中', async () => {
|
|
199
|
+
const { host, model, changes, unmount } = mountChipGroup({ modelValue: 'a' })
|
|
200
|
+
await nextTick()
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
const viewport = queryViewport(host)
|
|
204
|
+
const chip = queryChips(host)[2]!
|
|
205
|
+
mockOverflow(viewport, chip, 180, 80)
|
|
206
|
+
|
|
207
|
+
const scrollTo = vi.spyOn(viewport, 'scrollTo').mockImplementation(function (
|
|
208
|
+
this: HTMLElement,
|
|
209
|
+
options
|
|
210
|
+
) {
|
|
211
|
+
const left = typeof options === 'number' ? options : (options?.left ?? 0)
|
|
212
|
+
this.scrollLeft = left
|
|
213
|
+
this.dispatchEvent(new Event('scrollend'))
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
chip.click()
|
|
217
|
+
await nextTick()
|
|
218
|
+
await Promise.resolve()
|
|
219
|
+
|
|
220
|
+
expect(scrollTo).toHaveBeenCalled()
|
|
221
|
+
expect(viewport.scrollLeft).toBe(90)
|
|
222
|
+
expect(model.value).toBe('c')
|
|
223
|
+
expect(changes).toEqual([items[2]])
|
|
224
|
+
} finally {
|
|
225
|
+
unmount()
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it('焦点落到未完全露出的纸片时把它滚入可视区', async () => {
|
|
230
|
+
const { host, unmount } = mountChipGroup({ modelValue: 'a' })
|
|
231
|
+
await nextTick()
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
const viewport = queryViewport(host)
|
|
235
|
+
const chip = queryChips(host)[2]!
|
|
236
|
+
mockOverflow(viewport, chip, 180, 80)
|
|
237
|
+
|
|
238
|
+
const scrollTo = vi.spyOn(viewport, 'scrollTo').mockImplementation(function (
|
|
239
|
+
this: HTMLElement,
|
|
240
|
+
options
|
|
241
|
+
) {
|
|
242
|
+
const left = typeof options === 'number' ? options : (options?.left ?? 0)
|
|
243
|
+
this.scrollLeft = left
|
|
244
|
+
this.dispatchEvent(new Event('scrollend'))
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
queryInputs(host)[2]!.dispatchEvent(new FocusEvent('focusin', { bubbles: true }))
|
|
248
|
+
await nextTick()
|
|
249
|
+
|
|
250
|
+
expect(scrollTo).toHaveBeenCalled()
|
|
251
|
+
expect(viewport.scrollLeft).toBe(90)
|
|
252
|
+
} finally {
|
|
253
|
+
unmount()
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
it('滚动位置决定左右遮罩', async () => {
|
|
258
|
+
const { host, unmount } = mountChipGroup({ modelValue: 'a' })
|
|
259
|
+
await nextTick()
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
const viewport = queryViewport(host)
|
|
263
|
+
Object.defineProperty(viewport, 'clientWidth', { configurable: true, value: 100 })
|
|
264
|
+
Object.defineProperty(viewport, 'scrollWidth', { configurable: true, value: 500 })
|
|
265
|
+
Object.defineProperty(viewport, 'scrollLeft', {
|
|
266
|
+
configurable: true,
|
|
267
|
+
writable: true,
|
|
268
|
+
value: 40
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
viewport.dispatchEvent(new Event('scroll'))
|
|
272
|
+
await nextTick()
|
|
273
|
+
|
|
274
|
+
expect(viewport.classList.contains('is-mask-start')).toBe(true)
|
|
275
|
+
expect(viewport.classList.contains('is-mask-end')).toBe(true)
|
|
276
|
+
} finally {
|
|
277
|
+
unmount()
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
it('方向键在未禁用项之间移动并绕回', async () => {
|
|
282
|
+
const { host, model, changes, unmount } = mountChipGroup({
|
|
283
|
+
modelValue: 'a',
|
|
284
|
+
disabledItem: (item: any) => item.value === 'b'
|
|
285
|
+
})
|
|
286
|
+
await nextTick()
|
|
287
|
+
|
|
288
|
+
try {
|
|
289
|
+
const input = queryInputs(host)[0]!
|
|
290
|
+
input.focus()
|
|
291
|
+
input.dispatchEvent(
|
|
292
|
+
new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true, cancelable: true })
|
|
293
|
+
)
|
|
294
|
+
await nextTick()
|
|
295
|
+
|
|
296
|
+
expect(model.value).toBe('c')
|
|
297
|
+
expect(changes).toEqual([items[2]])
|
|
298
|
+
|
|
299
|
+
const last = queryInputs(host)[2]!
|
|
300
|
+
last.dispatchEvent(
|
|
301
|
+
new KeyboardEvent('keydown', { key: 'ArrowRight', bubbles: true, cancelable: true })
|
|
302
|
+
)
|
|
303
|
+
await nextTick()
|
|
304
|
+
expect(model.value).toBe('a')
|
|
305
|
+
} finally {
|
|
306
|
+
unmount()
|
|
307
|
+
}
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
it('纵向滚轮转为横向滚动,到头后不再拦截', async () => {
|
|
311
|
+
const { host, unmount } = mountChipGroup({ modelValue: 'a' })
|
|
312
|
+
await nextTick()
|
|
313
|
+
|
|
314
|
+
try {
|
|
315
|
+
const viewport = queryViewport(host)
|
|
316
|
+
mockOverflow(viewport, queryChips(host)[0]!, 0, 80)
|
|
317
|
+
|
|
318
|
+
const wheel = (deltaY: number, deltaX = 0) => {
|
|
319
|
+
const event = new WheelEvent('wheel', { bubbles: true, cancelable: true })
|
|
320
|
+
Object.defineProperty(event, 'deltaY', { value: deltaY })
|
|
321
|
+
Object.defineProperty(event, 'deltaX', { value: deltaX })
|
|
322
|
+
viewport.dispatchEvent(event)
|
|
323
|
+
return event
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const forward = wheel(40)
|
|
327
|
+
expect(forward.defaultPrevented).toBe(true)
|
|
328
|
+
expect(viewport.scrollLeft).toBe(40)
|
|
329
|
+
|
|
330
|
+
const horizontal = wheel(10, 30)
|
|
331
|
+
expect(horizontal.defaultPrevented).toBe(false)
|
|
332
|
+
expect(viewport.scrollLeft).toBe(40)
|
|
333
|
+
|
|
334
|
+
viewport.scrollLeft = 600
|
|
335
|
+
host.style.overflowY = 'auto'
|
|
336
|
+
let pageTop = 0
|
|
337
|
+
Object.defineProperty(host, 'clientHeight', { configurable: true, value: 80 })
|
|
338
|
+
Object.defineProperty(host, 'scrollHeight', { configurable: true, value: 400 })
|
|
339
|
+
Object.defineProperty(host, 'scrollTop', {
|
|
340
|
+
configurable: true,
|
|
341
|
+
get: () => pageTop,
|
|
342
|
+
set: (value: number) => {
|
|
343
|
+
pageTop = value
|
|
344
|
+
}
|
|
345
|
+
})
|
|
346
|
+
const atEnd = wheel(40)
|
|
347
|
+
expect(atEnd.defaultPrevented).toBe(true)
|
|
348
|
+
expect(viewport.scrollLeft).toBe(600)
|
|
349
|
+
expect(host.scrollTop).toBe(40)
|
|
350
|
+
} finally {
|
|
351
|
+
unmount()
|
|
352
|
+
}
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
it('拖过阈值才滚动,并且松手不选中', async () => {
|
|
356
|
+
const { host, model, unmount } = mountChipGroup({ modelValue: 'a' })
|
|
357
|
+
await nextTick()
|
|
358
|
+
|
|
359
|
+
try {
|
|
360
|
+
const viewport = queryViewport(host)
|
|
361
|
+
const chip = queryChips(host)[1]!
|
|
362
|
+
mockOverflow(viewport, chip, 0, 80)
|
|
363
|
+
viewport.dispatchEvent(new Event('scroll'))
|
|
364
|
+
await nextTick()
|
|
365
|
+
|
|
366
|
+
const pointer = (type: string, clientX: number) => {
|
|
367
|
+
chip.dispatchEvent(
|
|
368
|
+
new PointerEvent(type, {
|
|
369
|
+
button: 0,
|
|
370
|
+
pointerId: 1,
|
|
371
|
+
pointerType: 'mouse',
|
|
372
|
+
clientX,
|
|
373
|
+
bubbles: true,
|
|
374
|
+
cancelable: true
|
|
375
|
+
})
|
|
376
|
+
)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
pointer('pointerdown', 20)
|
|
380
|
+
pointer('pointermove', 22)
|
|
381
|
+
pointer('pointerup', 22)
|
|
382
|
+
chip.click()
|
|
383
|
+
await nextTick()
|
|
384
|
+
expect(model.value).toBe('b')
|
|
385
|
+
expect(viewport.scrollLeft).toBe(0)
|
|
386
|
+
|
|
387
|
+
pointer('pointerdown', 20)
|
|
388
|
+
pointer('pointermove', 40)
|
|
389
|
+
pointer('pointerup', 40)
|
|
390
|
+
chip.click()
|
|
391
|
+
await nextTick()
|
|
392
|
+
expect(viewport.scrollLeft).toBe(-20)
|
|
393
|
+
expect(model.value).toBe('b')
|
|
394
|
+
expect(viewport.classList.contains('is-dragging')).toBe(false)
|
|
395
|
+
} finally {
|
|
396
|
+
unmount()
|
|
397
|
+
}
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
it('只读时展示选中项文本', async () => {
|
|
401
|
+
const { host, unmount } = mountChipGroup({ modelValue: 'b', readonly: true })
|
|
402
|
+
await nextTick()
|
|
403
|
+
|
|
404
|
+
try {
|
|
405
|
+
expect(host.querySelector('.u-chip')).toBeNull()
|
|
406
|
+
expect(host.textContent).toContain('B')
|
|
407
|
+
} finally {
|
|
408
|
+
unmount()
|
|
409
|
+
}
|
|
410
|
+
})
|
|
411
|
+
})
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vite-plus/test'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CHIP_EDGE_FADE,
|
|
5
|
+
chipRevealScroll,
|
|
6
|
+
chipWheelScroll,
|
|
7
|
+
isChipClear,
|
|
8
|
+
type ChipRevealMetrics
|
|
9
|
+
} from '../reveal'
|
|
10
|
+
|
|
11
|
+
function metrics(
|
|
12
|
+
partial: Partial<ChipRevealMetrics> & Pick<ChipRevealMetrics, 'chipLeft' | 'chipRight'>
|
|
13
|
+
): ChipRevealMetrics {
|
|
14
|
+
return { scrollLeft: 0, clientWidth: 200, scrollWidth: 800, fade: CHIP_EDGE_FADE, ...partial }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('chipWheelScroll', () => {
|
|
18
|
+
it('纵向滚轮转成横向位移', () => {
|
|
19
|
+
expect(chipWheelScroll(10, 200, 800, 0, 40)).toEqual({ left: 50, leftover: 0 })
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('横轴位移更大时不拦截', () => {
|
|
23
|
+
expect(chipWheelScroll(10, 200, 800, 30, 10)).toBeNull()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('未溢出时不拦截,到头后把剩余滚轮交出去', () => {
|
|
27
|
+
expect(chipWheelScroll(0, 200, 200, 0, 40)).toBeNull()
|
|
28
|
+
expect(chipWheelScroll(0, 200, 800, 0, -40)).toEqual({ left: 0, leftover: -40 })
|
|
29
|
+
expect(chipWheelScroll(590, 200, 800, 0, 40)).toEqual({ left: 600, leftover: 30 })
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('chipRevealScroll', () => {
|
|
34
|
+
it('没有溢出时,完整落在视口内的纸片不滚动', () => {
|
|
35
|
+
const input = metrics({ chipLeft: 10, chipRight: 70, scrollWidth: 200 })
|
|
36
|
+
expect(isChipClear(input)).toBe(true)
|
|
37
|
+
expect(chipRevealScroll(input)).toBe(0)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('右侧被截断时滚到纸片右缘离开遮罩', () => {
|
|
41
|
+
const input = metrics({ chipLeft: 180, chipRight: 260 })
|
|
42
|
+
expect(isChipClear(input)).toBe(false)
|
|
43
|
+
expect(chipRevealScroll(input)).toBe(90)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('完整可见但压在右侧渐变上时仍滚动', () => {
|
|
47
|
+
const input = metrics({ chipLeft: 160, chipRight: 200 })
|
|
48
|
+
expect(isChipClear(input)).toBe(false)
|
|
49
|
+
expect(chipRevealScroll(input)).toBe(30)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('压在左侧渐变上时向左滚出遮罩', () => {
|
|
53
|
+
const input = metrics({ chipLeft: 100, chipRight: 140, scrollLeft: 100 })
|
|
54
|
+
expect(isChipClear(input)).toBe(false)
|
|
55
|
+
expect(chipRevealScroll(input)).toBe(70)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('滚出左侧的纸片回到起点', () => {
|
|
59
|
+
const input = metrics({ chipLeft: 0, chipRight: 40, scrollLeft: 100 })
|
|
60
|
+
expect(chipRevealScroll(input)).toBe(0)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('最后一张纸片滚到终点,终点一侧不再预留遮罩', () => {
|
|
64
|
+
const input = metrics({ chipLeft: 720, chipRight: 800, scrollLeft: 400 })
|
|
65
|
+
expect(chipRevealScroll(input)).toBe(600)
|
|
66
|
+
expect(isChipClear(metrics({ chipLeft: 720, chipRight: 800, scrollLeft: 600 }))).toBe(true)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('已经完全可见时保持当前 scrollLeft', () => {
|
|
70
|
+
const input = metrics({ chipLeft: 140, chipRight: 200, scrollLeft: 100 })
|
|
71
|
+
expect(isChipClear(input)).toBe(true)
|
|
72
|
+
expect(chipRevealScroll(input)).toBe(100)
|
|
73
|
+
})
|
|
74
|
+
})
|