feat(phase3): complete loading workbenches

This commit is contained in:
2026-08-10 17:42:17 +08:00
parent 820432a381
commit 1595fbcae2
34 changed files with 1352 additions and 159 deletions
@@ -101,7 +101,7 @@ function tableButtonByText(text: string) {
}
async function clickMoreAction(text: string) {
document.querySelector<HTMLButtonElement>('.el-table__body button[aria-label="更多客户操作"]')?.click()
document.querySelector<HTMLButtonElement>('.el-table__body button[aria-label^="更多客户操作:"]')?.click()
await flushPromises()
const item = [...document.querySelectorAll<HTMLElement>('.el-dropdown-menu__item')]
.find((candidate) => candidate.textContent?.trim() === text && !candidate.classList.contains('is-disabled'))
@@ -455,7 +455,8 @@ describe('CustomersView', () => {
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
await clickMoreAction('重置密码')
tableButtonByText('重置密码')?.click()
await flushPromises()
const password = document.querySelector<HTMLInputElement>('input[autocomplete="new-password"]')
const confirmation = document.querySelector<HTMLInputElement>('input[placeholder="请再次输入新密码"]')
@@ -479,11 +480,10 @@ describe('CustomersView', () => {
useAccessPreviewStore().initializeAfterLogin()
vi.mocked(archivePlatformTenant).mockResolvedValue({ ...fullTenant, status: 'DISABLED' })
const wrapper = mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
const dropdowns = wrapper.findAllComponents({ name: 'ElDropdown' })
expect(dropdowns.length).toBeGreaterThan(0)
dropdowns.at(-1)!.vm.$emit('command', 'delete')
expect(document.querySelector('.el-table__body button[aria-label^="更多客户操作:"]')).toBeNull()
tableButtonByText('删除')?.click()
await flushPromises()
const confirmation = document.querySelector<HTMLInputElement>('input[placeholder="TEN8"]')
@@ -519,9 +519,53 @@ describe('CustomersView', () => {
expect(tableButtonByText('详情')).toBeDefined()
expect(tableButtonByText('编辑')).toBeDefined()
expect(document.querySelector('.el-table__body button[aria-label="更多客户操作"]')).toBeTruthy()
expect(tableButtonByText('重置密码')).toBeUndefined()
await clickMoreAction('重置密码')
expect(document.querySelector('input[autocomplete="new-password"]')).toBeTruthy()
expect(document.querySelector('.el-table__body button[aria-label="更多客户操作:柏悦物流"]')).toBeTruthy()
expect(tableButtonByText('重置密码')).toBeDefined()
expect(tableButtonByText('跳转登录')).toBeUndefined()
await clickMoreAction('跳转登录')
expect(document.body.textContent).toContain('代登录原因')
})
it('uses stable unique customer identities for multiple more-action buttons', async () => {
const auth = useAuthStore()
auth.permissions = [...auth.permissions, 'platform:customer:reset-password', 'platform:customer:impersonate', 'platform:customer:status', 'platform:customer:delete']
useAccessPreviewStore().initializeAfterLogin()
vi.mocked(listPlatformTenants).mockResolvedValue({
records: [
{ ...fullTenant, id: '8', tenantName: '客户甲', tenantCode: 'TEN-A', status: 'ACTIVE' },
{ ...fullTenant, id: '9', tenantName: '', tenantCode: 'TEN-B', status: 'ACTIVE' },
{ ...fullTenant, id: '10', tenantName: '', tenantCode: '', status: 'ACTIVE' },
],
page: 1, size: 10, total: 3, pages: 1,
})
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
const buttons = [...document.querySelectorAll<HTMLButtonElement>('.el-table__body button[aria-label^="更多客户操作:"]')]
expect(buttons.map((button) => button.getAttribute('aria-label'))).toEqual([
'更多客户操作:客户甲',
'更多客户操作:TEN-B',
'更多客户操作:10',
])
expect(buttons.map((button) => button.getAttribute('title'))).toEqual(buttons.map((button) => button.getAttribute('aria-label')))
})
it('falls back to the current customer when all row identifiers are missing', async () => {
const auth = useAuthStore()
auth.permissions = [...auth.permissions, 'platform:customer:reset-password', 'platform:customer:impersonate', 'platform:customer:status', 'platform:customer:delete']
useAccessPreviewStore().initializeAfterLogin()
vi.mocked(listPlatformTenants).mockResolvedValue({
records: [{ ...fullTenant, id: null, tenantName: '', tenantCode: '', status: 'ACTIVE' } as unknown as PlatformTenantResource],
page: 1, size: 10, total: 1, pages: 1,
})
mount(CustomersView, { attachTo: document.body, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
const button = document.querySelector<HTMLButtonElement>('.el-table__body button[aria-label^="更多客户操作:"]')
expect(button?.getAttribute('aria-label')).toBe('更多客户操作:当前客户')
expect(button?.getAttribute('title')).toBe('更多客户操作:当前客户')
expect(button?.getAttribute('aria-label')).not.toMatch(/undefined|null/)
})
})