style(admin): 京东数据库页两颗下拉换 el-select——弹层圆角与亚马逊面统一(2026-11-17 用户口径「和亚马逊不统一」):分组下拉带搜索(admin-filter 同壳 42px/9px),分类筛选保留「全部分类」行同语义;删原生 select 死样式,工具栏位宽 200px 由页内钉;挂载测试换「点开→点选项」真实交互+组件树读选项(35 例全绿,vue-tsc 0 错,node --test 1922/1924 唯一红=date-range-order 在册环境红与本次无关)

This commit is contained in:
2026-11-17 12:57:16 +08:00
parent ee613db05b
commit 80060912ca
3 changed files with 83 additions and 69 deletions
@@ -18,8 +18,9 @@
* 跑法:`npx vitest run tests/mount/jd-database-page.mount.test.ts`
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { createPinia, setActivePinia, type Pinia } from 'pinia'
import { ElOption, ElSelect } from 'element-plus'
import JdDatabasePage from '@/pages/jd/JdDatabasePage.vue'
import OldPagination from '@/components/OldPagination.vue'
@@ -107,12 +108,44 @@ beforeEach(() => {
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
jdApi.fetchJdProductList.mockImplementation(() => Promise.resolve(payload))
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia] } })
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
await flushPromises()
await flushPromises()
return wrapper
}
// ---------------- el-select 交互助手(2026-11-17 两颗下拉换 el-select,与亚马逊面统一) ----------------
// aria-label 经 EP 的 ariaLabel prop 落在内层 combobox input 上;选项弹层 teleport 到 body,
// 但 ElOption/ElSelect 组件仍在挂载树里 ⇒ 选项清单走组件树读,点选走「点开→点选项」真实路径。
/** 按 aria-label 找对应的 ElSelect 组件实例(页面有两颗下拉,靠内层 input 的 aria-label 区分)。 */
function selectByLabel(wrapper: VueWrapper<Element>, label: string) {
const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists())
expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy()
return found!
}
/** 读某颗下拉的全部选项文案(label prop;组件树查询不受弹层 teleport 影响)。 */
function optionLabels(wrapper: VueWrapper<Element>, label: string): string[] {
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('label') as string)
}
/** 点开指定下拉并点选目标文案的选项(触发 update:modelValue + change,与真实用户一致)。
* 面板按内层 input 的 aria-controls 圈定,避免另一颗(可能仍挂着的)弹层串台。 */
async function pickSelectOption(wrapper: VueWrapper<Element>, label: string, optionText: string): Promise<void> {
const input = wrapper.get(`[aria-label="${label}"]`)
await input.trigger('click')
await flushPromises()
const contentId = input.attributes('aria-controls')
const scope = (contentId && document.getElementById(contentId)) ?? document.body
const items = [...scope.querySelectorAll('.el-select-dropdown__item')]
.filter((el) => !el.classList.contains('is-hidden'))
const target = items.find((el) => (el.textContent ?? '').trim() === optionText)
expect(target, `下拉应弹出「${optionText}」选项`).toBeTruthy()
await new DOMWrapper(target as Element).trigger('click')
await flushPromises()
}
/** 批量编辑分类(2026-11-17 用户口径「店铺分类弹窗删了,加个批量编辑分类」):
* 勾选跨页累计记忆(翻页/重取不清)→ 对话框选目标分类归入或移出 → 按 (ids, groupId,
* ownerGroupId) 提交;成功后清勾选并重取。旧弹窗的「勾选翻页即清」口径同日废止。 */
@@ -121,7 +154,7 @@ describe('批量编辑分类(店铺分类弹窗 2026-11-17 下线后的替代
jdApi.fetchJdProductList
.mockImplementationOnce(() => Promise.resolve({ items: [item(1)], total: 40, page: 1, pageSize: 20 }))
.mockImplementation(() => Promise.resolve({ items: [item(2)], total: 40, page: 2, pageSize: 20 }))
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia] } })
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
await flushPromises()
await flushPromises()
const deleteBtn = () => wrapper.get('.jd-delete-btn')
@@ -264,7 +297,7 @@ describe('分类管理入口(V204 独立页并入京东数据库页)', () =>
: Promise.resolve([{ id: 8, name: '裤装', sortOrder: 1, productCount: 1 }])
})
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
expect(wrapper.get('[aria-label="筛选店铺分类"]').text()).toContain('裙装', '首屏下拉含首取分类')
expect(optionLabels(wrapper, '筛选店铺分类')).toContain('裙装', '首屏下拉含首取分类')
await wrapper.findAll('button').find((b) => b.text() === '分类管理')!.trigger('click')
await flushPromises()
@@ -276,9 +309,8 @@ describe('分类管理入口(V204 独立页并入京东数据库页)', () =>
await flushPromises()
expect(jdApi.deleteJdProductGroup, '删除按钮属于当前列表行').toHaveBeenCalledWith(8)
// changed → 父页 loadGroupOptions:下拉按新列表重取(最后一次调用拿到删后列表)。
const select = wrapper.get('[aria-label="筛选店铺分类"]')
expect(select.text()).toContain('裤装', '下拉刷新出新一轮分类')
expect(select.text()).not.toContain('裙装', '删掉的分类不再出现在筛选下拉')
expect(optionLabels(wrapper, '筛选店铺分类')).toContain('裤装', '下拉刷新出新一轮分类')
expect(optionLabels(wrapper, '筛选店铺分类')).not.toContain('裙装', '删掉的分类不再出现在筛选下拉')
wrapper.unmount()
})
})
@@ -418,7 +450,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(textInputs).toHaveLength(2, '商品编码+标题关键字两个文本筛选框(店铺/商品状态已下线)')
await textInputs[0].setValue('JD-1001')
await textInputs[1].setValue('保温杯')
await wrapper.get('[aria-label="筛选店铺分类"]').setValue('7')
await pickSelectOption(wrapper, '筛选店铺分类', '甲组')
const dateInputs = wrapper.findAll('input[type="date"]')
await dateInputs[0].setValue('2026-11-01')
await dateInputs[1].setValue('2026-11-09')
@@ -541,9 +573,8 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
it('重置把筛选面回空并回第一页重取', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
const select = wrapper.get('[aria-label="筛选店铺分类"]')
expect(select.text()).toContain('全部分类')
await select.setValue('7')
expect(optionLabels(wrapper, '筛选店铺分类')[0]).toBe('全部分类', '「全部分类」常驻列表首位(与旧原生下拉同语义)')
await pickSelectOption(wrapper, '筛选店铺分类', '甲组')
await wrapper.get('.cat-trigger').trigger('click')
await wrapper.get('.cat-search').setValue('艺考')
await wrapper.get('.cat-col-search .cat-row').trigger('click')
@@ -558,7 +589,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore)
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last).toMatchObject({ productCode: '', titleKeyword: '', groupId: '', category: '', page: 1 }, '重置后筛选全空、回第一页')
expect((select.element as HTMLSelectElement).value).toBe('')
expect(selectByLabel(wrapper, '筛选店铺分类').props('modelValue')).toBe('', '重置后分类筛选回「全部分类」')
})
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
@@ -845,12 +876,12 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
const picker = wrapper.get('[aria-label="当前分组"]')
// 2026-11-16 用户口径「做成分组」:分组在筛选行里是带标签的表单控件(与其他筛选同壳同圆角),
// 不再是工具栏裸下拉——钉住形状,防止搬回工具栏或丢标签。
const groupField = (picker.element as HTMLSelectElement).closest('.form-group')
const groupField = picker.element.closest('.form-group')
expect(groupField?.querySelector('label')?.textContent).toBe('分组')
expect(picker.findAll('option').map((o) => o.text())).toEqual(['甲公司 / A组', '甲公司 / B组'],
expect(optionLabels(wrapper, '当前分组')).toEqual(['甲公司 / A组', '甲公司 / B组'],
'跨公司组名由后端拼进 label,前端不解析公司字段')
await picker.setValue('12')
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
await flushPromises()
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(12)
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12, page: 1 },
@@ -876,13 +907,12 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
],
})
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
const picker = wrapper.get('[aria-label="当前分组"]')
await picker.setValue('12')
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12 })
await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
await flushPromises()
expect((picker.element as HTMLSelectElement).value).toBe('12', '重置不清当前分组(作用域语义,搬进筛选行也不变)')
expect(selectByLabel(wrapper, '当前分组').props('modelValue')).toBe(12, '重置不清当前分组(作用域语义,搬进筛选行也不变)')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12 },
'重置后的重取仍带当前分组')
wrapper.unmount()
@@ -893,7 +923,7 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 })
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false)
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有分组就没有可锁定的组名')
expect(wrapper.find('[aria-label="筛选店铺分类"]').text()).toContain('全部分类', '分类筛选只剩「全部分类」')
expect(optionLabels(wrapper, '筛选店铺分类')).toEqual(['全部分类'], '分类筛选只剩「全部分类」')
expect(wrapper.findAll('tbody tr')[0].findAll('td')[1].text()).toBe('未分类')
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '没有分组就没有可写的分类面')
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()