-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebcaeb7
commit 8f7cc04
Showing
11 changed files
with
257 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* | ||
* 语言补丁 | ||
* | ||
* 语言补丁功能需要配置LnaguageLoader | ||
* | ||
* | ||
*/ | ||
|
||
|
||
|
||
import { test, vi, describe, expect, beforeEach } from 'vitest' | ||
import { VoerkaI18nScope } from '../scope' | ||
import { VoerkaI18nManager } from '../manager'; | ||
import { createVoerkaI18nScope, getTestLanguageLoader, getTestStorage, resetVoerkaI18n } from './_utils'; | ||
import { VoerkaI18nOnlyOneAppScopeError } from '@/errors'; | ||
import { VoerkaI18nLanguageLoader } from '@/types'; | ||
|
||
|
||
describe('语言包补丁功能', () => { | ||
beforeEach(() => { | ||
resetVoerkaI18n() | ||
}); | ||
test('appScope加载时加载补丁', async () => { | ||
const storage = getTestStorage() | ||
const languageLoader = getTestLanguageLoader() | ||
|
||
const appScope = createVoerkaI18nScope({ | ||
storage | ||
}) | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
|
||
import { test, vi, describe, expect, beforeEach } from 'vitest' | ||
import { createVoerkaI18nScope, getTestStorage, resetVoerkaI18n } from './_utils'; | ||
|
||
|
||
|
||
describe('保存与恢复语言', () => { | ||
beforeEach(() => { | ||
resetVoerkaI18n() | ||
}); | ||
test('保存与恢复语言配置到存储', async () => { | ||
const storage = getTestStorage() | ||
const scope = createVoerkaI18nScope({storage}); | ||
expect(storage.get()).toBe(undefined); | ||
await scope.change('en') | ||
expect(storage.get()).toBe('en'); | ||
await scope.change('zh') | ||
expect(storage.get()).toBe('zh'); | ||
}); | ||
test('从存储中恢复语言', async () => { | ||
const storage = getTestStorage('en') | ||
const scope = createVoerkaI18nScope({storage}); | ||
await scope.refreshing() | ||
expect(scope.activeLanguage).toBe('en'); | ||
expect(scope.activeMessages).toEqual({ message: 'Hello' }); | ||
}); | ||
test('多个scope从存储中恢复语言', async () => { | ||
const storage = getTestStorage('en') | ||
const libScope1 = createVoerkaI18nScope({id:"a", library:true}); | ||
const libScope2 = createVoerkaI18nScope({id:"b", library:true}); | ||
const libScope3 = createVoerkaI18nScope({id:"c", library:true}); | ||
const appScope = createVoerkaI18nScope({id:"app",storage}); | ||
await appScope.refreshing() | ||
await libScope1.refreshing() | ||
await libScope2.refreshing() | ||
await libScope3.refreshing() | ||
expect(appScope.activeLanguage).toBe('en'); | ||
expect(appScope.activeMessages).toEqual({ message: 'Hello' }); | ||
expect(libScope1.activeLanguage).toBe('en'); | ||
expect(libScope1.activeMessages).toEqual({ message: 'Hello' }); | ||
expect(libScope2.activeLanguage).toBe('en'); | ||
expect(libScope2.activeMessages).toEqual({ message: 'Hello' }); | ||
expect(libScope3.activeLanguage).toBe('en'); | ||
expect(libScope3.activeMessages).toEqual({ message: 'Hello' }); | ||
}); | ||
test('多个libScope在appScope后面注册时从存储中恢复语言', async () => { | ||
const storage = getTestStorage('en') | ||
const appScope = createVoerkaI18nScope({id:"app",storage}); | ||
await appScope.refreshing() | ||
const libScope1 = createVoerkaI18nScope({id:"a", library:true}); | ||
const libScope2 = createVoerkaI18nScope({id:"b", library:true}); | ||
const libScope3 = createVoerkaI18nScope({id:"c", library:true}); | ||
await libScope1.refreshing() | ||
await libScope2.refreshing() | ||
await libScope3.refreshing() | ||
expect(appScope.activeLanguage).toBe('en'); | ||
expect(appScope.activeMessages).toEqual({ message: 'Hello' }); | ||
expect(libScope1.activeLanguage).toBe('en'); | ||
expect(libScope1.activeMessages).toEqual({ message: 'Hello' }); | ||
expect(libScope2.activeLanguage).toBe('en'); | ||
expect(libScope2.activeMessages).toEqual({ message: 'Hello' }); | ||
expect(libScope3.activeLanguage).toBe('en'); | ||
expect(libScope3.activeMessages).toEqual({ message: 'Hello' }); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.