111 lines
3.6 KiB
TypeScript
111 lines
3.6 KiB
TypeScript
/**
|
|
* features/workspace/shipping-task-center/ManualUploadEvidenceDialog.spec.ts
|
|
* 用途:锁定人工上传确认弹窗无障碍与无凭据提交契约。
|
|
* 依赖:vitest、@vue/test-utils、vue-i18n、shipping-tasks API mock。
|
|
* 逻辑:打开时具备 dialog 角色;Escape 关闭;无需截图/PDF或回执即可确认;关闭后恢复先前焦点。
|
|
* ElDialog 传送到 body,断言改查 document.body,业务结果不变。
|
|
*/
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { mount, flushPromises } from '@vue/test-utils';
|
|
import { createI18n } from 'vue-i18n';
|
|
import { nextTick } from 'vue';
|
|
import ManualUploadEvidenceDialog from './ManualUploadEvidenceDialog.vue';
|
|
|
|
vi.mock('@/features/workspace/api/shipping-tasks.api', () => ({
|
|
markWorkspaceShippingManualUploaded: vi.fn(async () => ({})),
|
|
}));
|
|
|
|
const messages = {
|
|
'zh-CN': {
|
|
workspace: {
|
|
shippingNotice: {
|
|
actions: { failed: '失败' },
|
|
manualUpload: {
|
|
title: '登记人工上传',
|
|
hint: '请确认 Excel 已上传至货代平台',
|
|
cancel: '取消',
|
|
submit: '确认已上传',
|
|
submitting: '提交中…',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
/**
|
|
* 挂载人工上传登记弹窗。
|
|
*/
|
|
function mountDialog(open = true) {
|
|
const i18n = createI18n({ legacy: false, locale: 'zh-CN', messages });
|
|
return mount(ManualUploadEvidenceDialog, {
|
|
props: {
|
|
open,
|
|
businessNo: 'WVC26082301',
|
|
artifactId: 9,
|
|
},
|
|
attachTo: document.body,
|
|
global: { plugins: [i18n] },
|
|
});
|
|
}
|
|
|
|
describe('ManualUploadEvidenceDialog', () => {
|
|
beforeEach(() => {
|
|
document.body.innerHTML = '';
|
|
});
|
|
|
|
afterEach(() => {
|
|
document.body.innerHTML = '';
|
|
});
|
|
|
|
it('exposes dialog accessibility attributes when open', async () => {
|
|
const wrapper = mountDialog(true);
|
|
await nextTick();
|
|
await flushPromises();
|
|
const marked = document.body.querySelector('[data-testid="manual-upload-evidence-dialog"]');
|
|
const dialog = marked?.getAttribute('role') === 'dialog'
|
|
? marked
|
|
: marked?.closest('[role="dialog"]') || document.body.querySelector('[role="dialog"]');
|
|
expect(dialog?.getAttribute('role')).toBe('dialog');
|
|
expect(dialog?.getAttribute('aria-modal')).toBe('true');
|
|
expect(dialog?.textContent).toContain('登记人工上传');
|
|
wrapper.unmount();
|
|
});
|
|
|
|
it('closes on Escape and restores prior focus', async () => {
|
|
const trigger = document.createElement('button');
|
|
trigger.type = 'button';
|
|
trigger.textContent = 'open';
|
|
document.body.appendChild(trigger);
|
|
trigger.focus();
|
|
expect(document.activeElement).toBe(trigger);
|
|
|
|
const wrapper = mountDialog(true);
|
|
await nextTick();
|
|
await flushPromises();
|
|
|
|
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
|
|
await nextTick();
|
|
await flushPromises();
|
|
|
|
expect(wrapper.emitted('update:open')?.at(-1)).toEqual([false]);
|
|
await wrapper.setProps({ open: false });
|
|
await nextTick();
|
|
await flushPromises();
|
|
expect(document.activeElement).toBe(trigger);
|
|
wrapper.unmount();
|
|
});
|
|
|
|
it('submits with business_no without file evidence or freight receipt', async () => {
|
|
const wrapper = mountDialog(true);
|
|
await nextTick();
|
|
await flushPromises();
|
|
const submit = Array.from(document.body.querySelectorAll('button')).find((btn) => btn.textContent?.includes('确认已上传'));
|
|
expect(submit).toBeTruthy();
|
|
expect(submit!.hasAttribute('disabled')).toBe(false);
|
|
submit!.click();
|
|
await flushPromises();
|
|
expect(wrapper.emitted('success')).toHaveLength(1);
|
|
wrapper.unmount();
|
|
});
|
|
});
|