Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tests for i18n #79

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/__tests__/components/i18n.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import i18n from '../../i18n'

const translationEN = i18n.getDataByLanguage('en')
const translationDE = i18n.getDataByLanguage('de')

test('recursively iterate all object keys of i18 EN and DE, checks if the same namespaces exists, if namespaces have the same length', () => {
const isPlainObj = obj => Object.prototype.toString.call(obj) === '[object Object]'
const equal = (a, b) => {
const keysa = Object.keys(a).sort()
const keysb = Object.keys(b).sort()

if (keysa.length !== keysb.length) {
return false
}

if (keysa.toString() !== keysb.toString()) {
return false
}

return keysa.every(key => {
const valuea = a[key]
const valueb = b[key]
const typea = typeof valuea
const typeb = typeof valueb

if (typea !== typeb) { return false }
if (typea === 'string') { return true }
if (!isPlainObj(valuea) || !isPlainObj(valueb)) { return false }

return equal(valuea, valueb)
})
}

expect(equal(translationEN, translationDE)).toBe(true)
})