-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add languages unit tests. make languageId lookup case insensitive.
- Loading branch information
PhotoNomad0
committed
Jul 1, 2024
1 parent
ecfb56e
commit 3446059
Showing
2 changed files
with
83 additions
and
1 deletion.
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,79 @@ | ||
/* eslint-env jest */ | ||
import * as Languages from '../languages'; | ||
|
||
describe('Test Languages',()=>{ | ||
const minimumLangCount = 9000; | ||
|
||
test('getLanguage() should work with mixed and lower case', () => { | ||
const codes = ['sr-latn', 'sr-Latn', 'SR-LATN', 'ur-deva', 'ur-Deva', 'UR-DEVA', 'ZH']; | ||
|
||
for (let languageId of codes) { | ||
const languageData = Languages.getLanguage({languageId}); | ||
expect(languageData).toBeTruthy(); | ||
expect(languageData.languageId.toLowerCase()).toEqual(languageId.toLowerCase()); | ||
} | ||
}); | ||
|
||
test('getLanguages() should work', () => { | ||
const languages = Languages.getLanguages(); | ||
const langCount = languages.length; | ||
expect(langCount).toBeLessThan(minimumLangCount * 1.2); | ||
|
||
// make sure fields are valid and in sequence | ||
for (let i = 1; i < langCount; i++) { | ||
const lang = languages[i - 1]; | ||
expect(lang.languageId.length).toBeGreaterThan(0); | ||
const languageName = lang.languageName || lang.localized | ||
if (!languageName.length) { | ||
console.log(`invalid languageName ${languageName} for languageId ${lang.languageId}`) | ||
} | ||
expect(lang.localized.length).toBeGreaterThan(0); | ||
if (!lang.localized.length) { | ||
console.log(`invalid localized ${lang.localized} for languageId ${lang.languageId}`) | ||
} | ||
expect(lang.localized.length).toBeGreaterThan(0); | ||
const directionValid = lang.direction === 'ltr' || lang.direction === 'rtl' | ||
if (!lang.localized.length) { | ||
console.log(`invalid direction ${lang.direction} for languageId ${lang.languageId}`) | ||
} | ||
expect(directionValid).toBeTruthy(); | ||
} | ||
}); | ||
|
||
test('getLanguages() verify no dupes among language codes.', () => { | ||
let languages = Languages.getLanguages(); | ||
let localLanguageCodes = languages.map(language => language.languageId); | ||
|
||
const sorted = localLanguageCodes.sort(); | ||
let dupsFound = 0; | ||
|
||
for ( let idx = 1; idx < sorted.length; idx++ ) { | ||
if ( sorted[idx] == sorted[idx-1]) { | ||
dupsFound++; | ||
} | ||
} | ||
|
||
expect(dupsFound).toBeLessThan(1); | ||
expect(sorted.length).toBeGreaterThan(2000); | ||
}); | ||
|
||
describe('getLanguage()',()=>{ | ||
test('Nepali ne should succeed', () => { | ||
const code = 'ne'; | ||
const name = 'Nepali'; | ||
let foundLanguage = Languages.getLanguage({ languageId: code }); | ||
|
||
expect(foundLanguage.languageName).toEqual(name); | ||
expect(foundLanguage.languageId).toEqual(code); | ||
}); | ||
|
||
test('Nepali npi should succeed', () => { | ||
const code = 'npi'; | ||
const name = 'Nepali'; | ||
let foundLanguage = Languages.getLanguage({ languageId: code }); | ||
|
||
expect(foundLanguage.languageName).toEqual(name); | ||
expect(foundLanguage.languageId).toEqual(code); | ||
}); | ||
}); | ||
}); |
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