48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { createPinia } from 'pinia';
|
|
import { mount } from '@vue/test-utils';
|
|
import { createMemoryHistory } from 'vue-router';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
import App from './App.vue';
|
|
import { createAppRouter } from './router';
|
|
|
|
// 应用外壳测试只验证导航和主区域,不应因页面挂载触发真实 Axios 请求。
|
|
vi.mock('@/api/market-overview', () => {
|
|
const response = {
|
|
source: 'tdx',
|
|
status: 'unavailable',
|
|
data: null,
|
|
snapshotId: 'test',
|
|
asOf: '2026-08-18T00:00:00.000Z',
|
|
warnings: ['测试环境未连接 TDX'],
|
|
};
|
|
return {
|
|
default: {
|
|
getSummary: vi.fn().mockResolvedValue(response),
|
|
getIndices: vi.fn().mockResolvedValue(response),
|
|
getBreadth: vi.fn().mockResolvedValue(response),
|
|
getSectors: vi.fn().mockResolvedValue(response),
|
|
getFunds: vi.fn().mockResolvedValue(response),
|
|
},
|
|
};
|
|
});
|
|
|
|
describe('应用外壳', () => {
|
|
it('提供可访问的应用标题和主内容区域', async () => {
|
|
const router = createAppRouter(createMemoryHistory());
|
|
await router.push('/');
|
|
await router.isReady();
|
|
|
|
const wrapper = mount(App, {
|
|
global: {
|
|
plugins: [createPinia(), router],
|
|
},
|
|
});
|
|
|
|
expect(wrapper.get('header').attributes('aria-label')).toBe('应用导航');
|
|
expect(wrapper.get('main').attributes('id')).toBe('main-content');
|
|
expect(wrapper.text()).toContain('A 股市场分析工具');
|
|
expect(wrapper.text()).toContain('市场综合概览');
|
|
});
|
|
});
|