adc45b1563
Co-Authored-By: Claude Code <noreply@anthropic.com>
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import { mount, type VueWrapper } from '@vue/test-utils';
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
import { nextTick } from 'vue';
|
|
import App from '../App.vue';
|
|
import { LOCALE_STORAGE_KEY, createViewerI18n } from '../i18n';
|
|
import { router } from '../router';
|
|
|
|
// i18n 切换机制(顶栏 chrome 层):活动页级的「切换语言 → 重取内容」由
|
|
// activity.spec.ts 覆盖,此处聚焦首页 chrome(无需 api mock)。
|
|
// 逐挂载独立 i18n + 逐用例卸载(背景见 activity.spec.ts 头注)。
|
|
let i18n: ReturnType<typeof createViewerI18n>;
|
|
let wrapper: VueWrapper;
|
|
|
|
describe('viewer i18n', () => {
|
|
beforeEach(async () => {
|
|
localStorage.clear();
|
|
i18n = createViewerI18n('zh-CN');
|
|
await router.push('/');
|
|
await router.isReady();
|
|
wrapper = mount(App, { global: { plugins: [router, i18n] } });
|
|
});
|
|
|
|
afterEach(() => {
|
|
wrapper.unmount();
|
|
});
|
|
|
|
it('switching locale re-renders messages and persists the choice', async () => {
|
|
expect(wrapper.text()).toContain('打开相册链接即可观看');
|
|
expect(document.title).toBe('现场相册');
|
|
|
|
await wrapper.find('button.locale-switcher').trigger('click');
|
|
await nextTick();
|
|
expect(wrapper.text()).toContain('Open an album link to start viewing');
|
|
expect(document.title).toBe('Live Gallery');
|
|
expect(document.documentElement.getAttribute('lang')).toBe('en');
|
|
expect(localStorage.getItem(LOCALE_STORAGE_KEY)).toBe('en');
|
|
|
|
// 切回 zh-CN 同样生效
|
|
await wrapper.find('button.locale-switcher').trigger('click');
|
|
await nextTick();
|
|
expect(wrapper.text()).toContain('打开相册链接即可观看');
|
|
expect(localStorage.getItem(LOCALE_STORAGE_KEY)).toBe('zh-CN');
|
|
});
|
|
});
|