-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
41 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {expect, test} from "@playwright/test"; | ||
|
||
const localeCodes = ['uk', 'en'] as const | ||
|
||
const locales = await Promise.all(localeCodes.map(async code => ({ | ||
code, | ||
messages: (await import(`../dist/_locales/${code}/messages.json`, {assert: {type: 'json'}})).default | ||
}))) | ||
|
||
test('All keys in all localizations must be the same', () => { | ||
const expectedKeys = Object.keys(locales[0].messages) | ||
for (let i = 1; i < locales.length; i++) { | ||
expect(Object.keys(locales[i].messages), `Locale "${locales[i].code}" doesn't match locale "${locales[0].code}"`).toEqual(expectedKeys) | ||
} | ||
}) | ||
|
||
|
||
test.only('Messages do not have to have the same values in different locales', () => { | ||
|
||
const messagesMap: Record<string, { code: typeof localeCodes[number], value: string }[]> = {} | ||
|
||
for (const {code, messages} of locales) { | ||
for (const messagesKey in messages) { | ||
|
||
if (!messagesMap[messagesKey]) { | ||
messagesMap[messagesKey] = [] | ||
} | ||
|
||
if (messagesMap[messagesKey].length) { | ||
for (const localeToCompare of messagesMap[messagesKey]) { | ||
expect(localeToCompare.value, `Locale "${code}" have equal value for key "${messagesKey}" in locale "${localeToCompare.code}"`).not.toEqual(messages[messagesKey].message) | ||
} | ||
} | ||
|
||
messagesMap[messagesKey].push({ | ||
code, | ||
value: messages[messagesKey].message | ||
}) | ||
} | ||
} | ||
}) |