diff --git a/test/Translator.spec.ts b/test/Translator.spec.ts index 00b7b8cf..df4aeefa 100644 --- a/test/Translator.spec.ts +++ b/test/Translator.spec.ts @@ -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