feat(GOV-009): 建立 Vue 前端工程基线
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { createPinia } from 'pinia';
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { createMemoryHistory } from 'vue-router';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import App from './App.vue';
|
||||
import { createAppRouter } from './router';
|
||||
|
||||
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 股市场分析工具');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
import { NConfigProvider, NGlobalStyle, NMessageProvider } from 'naive-ui';
|
||||
|
||||
const appTitle = import.meta.env.VITE_APP_TITLE || 'A 股市场分析工具';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NConfigProvider>
|
||||
<NGlobalStyle />
|
||||
<NMessageProvider>
|
||||
<div class="app-shell">
|
||||
<header class="app-header" aria-label="应用导航">
|
||||
<span class="app-mark" aria-hidden="true">A</span>
|
||||
<strong>{{ appTitle }}</strong>
|
||||
</header>
|
||||
<main id="main-content" class="app-main">
|
||||
<RouterView />
|
||||
</main>
|
||||
</div>
|
||||
</NMessageProvider>
|
||||
</NConfigProvider>
|
||||
</template>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { createPinia } from 'pinia';
|
||||
import type { App } from 'vue';
|
||||
|
||||
import { createAppRouter } from './router';
|
||||
|
||||
export function installAppProviders(app: App) {
|
||||
app.use(createPinia());
|
||||
app.use(createAppRouter());
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import {
|
||||
createRouter,
|
||||
createWebHistory,
|
||||
type RouterHistory,
|
||||
type RouteRecordRaw,
|
||||
} from 'vue-router';
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: {
|
||||
template: '<section aria-label="应用就绪"><p>工程基线已就绪</p></section>',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export function createAppRouter(history: RouterHistory = createWebHistory()) {
|
||||
return createRouter({ history, routes });
|
||||
}
|
||||
Reference in New Issue
Block a user