feat(viewer): album page with locale fallback and timezone display

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-18 09:52:22 +08:00
parent 04b5641901
commit adc45b1563
15 changed files with 879 additions and 61 deletions
+21 -12
View File
@@ -1,27 +1,36 @@
import { mount } from '@vue/test-utils';
import { beforeEach, describe, expect, it } from 'vitest';
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, i18n } from '../i18n';
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(() => {
beforeEach(async () => {
localStorage.clear();
i18n.global.locale.value = 'zh-CN';
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 () => {
await router.push('/a/tok-i18n');
await router.isReady();
const wrapper = mount(App, { global: { plugins: [router, i18n] } });
expect(wrapper.text()).toContain('照片即将上线');
expect(wrapper.text()).toContain('打开相册链接即可观看');
expect(document.title).toBe('现场相册');
await wrapper.find('button.locale-switcher').trigger('click');
await nextTick();
expect(wrapper.text()).toContain('Photos coming soon');
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');
@@ -29,7 +38,7 @@ describe('viewer i18n', () => {
// 切回 zh-CN 同样生效
await wrapper.find('button.locale-switcher').trigger('click');
await nextTick();
expect(wrapper.text()).toContain('照片即将上线');
expect(wrapper.text()).toContain('打开相册链接即可观看');
expect(localStorage.getItem(LOCALE_STORAGE_KEY)).toBe('zh-CN');
});
});