lang: unit tests in django/await first loading of dict
This commit is contained in:
parent
b398134101
commit
157383748f
@ -8,10 +8,10 @@ export default class LanguageManager {
|
||||
this.currentLang = 'en'
|
||||
this.chosenLang = localStorage.getItem('preferedLanguage') || this.currentLang;
|
||||
if (this.chosenLang !== this.currentLang && this.availableLanguages.includes(this.chosenLang)) {
|
||||
this.translatePage();
|
||||
this.loading = this.translatePage();
|
||||
this.currentLang = this.chosenLang;
|
||||
} else {
|
||||
this.loadDict(this.chosenLang);
|
||||
this.loading = this.loadDict(this.chosenLang);
|
||||
}
|
||||
document.getElementById('languageDisplay').innerHTML =
|
||||
document.querySelector(`#languageSelector > [value=${this.currentLang}]`)?.innerHTML;
|
||||
@ -61,6 +61,10 @@ export default class LanguageManager {
|
||||
this.dict = await response.json();
|
||||
}
|
||||
|
||||
async waitLoading() {
|
||||
await this.loading;
|
||||
}
|
||||
|
||||
get(key, defaultTxt) {
|
||||
if (!this.dict)
|
||||
return defaultTxt;
|
||||
|
@ -49,7 +49,10 @@ const navigateTo = async (uri) => {
|
||||
}
|
||||
};
|
||||
|
||||
const reloadView = async _ => renderView(lastView);
|
||||
const reloadView = async _ => {
|
||||
await lastView?.leavePage();
|
||||
await renderView(lastView);
|
||||
}
|
||||
|
||||
async function renderView(view)
|
||||
{
|
||||
@ -142,10 +145,12 @@ document.addEventListener("DOMContentLoaded", async () => {
|
||||
});
|
||||
|
||||
//Languages
|
||||
await lang.waitLoading();
|
||||
Array.from(document.getElementById('languageSelector').children).forEach(el => {
|
||||
el.onclick = async _ => {
|
||||
if (await lang.changeLanguage(el.value))
|
||||
return;
|
||||
console.log(lang);
|
||||
document.querySelector('#languageSelector > .active')?.classList.remove('active');
|
||||
el.classList.add('active');
|
||||
};
|
||||
|
@ -1,3 +1,24 @@
|
||||
from django.test import TestCase
|
||||
import json
|
||||
from os import listdir
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from django.contrib.staticfiles import finders
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
class DictionnariesTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.client = Client();
|
||||
self.directory = finders.find('js/lang/');
|
||||
|
||||
def test_lang(self):
|
||||
keys = None
|
||||
|
||||
json_files = listdir(self.directory);
|
||||
for file in json_files:
|
||||
with open(f'{self.directory}/{file}') as f:
|
||||
data: dict = json.load(f);
|
||||
if (keys is None):
|
||||
keys = set(data.keys());
|
||||
else:
|
||||
self.assertEqual(set(data.keys()), keys);
|
||||
|
Loading…
Reference in New Issue
Block a user