test: add tests concerning the translators cache

This commit is contained in:
Rainer Killinger
2019-04-02 14:48:21 +02:00
committed by Jovan Krunić
parent cf83692e71
commit 6f12fbda94

View File

@@ -218,6 +218,25 @@ export class TranslationSpecInplace {
expect(translator.translate(dish).offers[0].inPlace.categories[1234]('printer')).to.equal('printer');
expect(translator.translate(dish).offers[0].inPlace.categories[1]('printer')).to.not.equal('printer');
}
@test
public changingTranslatorLanguageFlushesItsLRUCache() {
const translatorDE = new SCThingTranslator('de');
expect(translatorDE.translate(dish).name()).to.equal('de-dish-name');
translatorDE.language = 'en';
expect(translatorDE.translate(dish).name()).to.equal('base-dish-name');
}
@test
public forceTranslatorLRUCacheToOverflow() {
const translatorDE = new SCThingTranslator('de');
// Make sure to add more elements to the translator cache than the maximum cache capacity. See Translator.ts
for (let i = 0; i < 201; i++) {
const anotherDish = Object.assign({}, dish);
anotherDish.uid = String(i);
expect(translatorDE.translate(anotherDish).name()).to.equal('de-dish-name');
}
}
}
// tslint:disable:member-ordering no-eval no-unused-expression TranslationSpec