36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
|
|
import { mount } from '@vue/test-utils';
|
||
|
|
import { beforeEach, describe, expect, it } from 'vitest';
|
||
|
|
import { nextTick } from 'vue';
|
||
|
|
import App from '../App.vue';
|
||
|
|
import { LOCALE_STORAGE_KEY, i18n } from '../i18n';
|
||
|
|
import { router } from '../router';
|
||
|
|
|
||
|
|
describe('viewer i18n', () => {
|
||
|
|
beforeEach(() => {
|
||
|
|
localStorage.clear();
|
||
|
|
i18n.global.locale.value = 'zh-CN';
|
||
|
|
});
|
||
|
|
|
||
|
|
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(document.title).toBe('现场相册');
|
||
|
|
|
||
|
|
await wrapper.find('button.locale-switcher').trigger('click');
|
||
|
|
await nextTick();
|
||
|
|
expect(wrapper.text()).toContain('Photos coming soon');
|
||
|
|
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');
|
||
|
|
});
|
||
|
|
});
|