import 'reflect-metadata'; import { requiredMocks, } from './../../../../test-mocks'; requiredMocks(jest); import { Http } from '@angular/http'; import { BrandSettingsInterface, } from './../../../models/index'; import { TranslateBrandingLoaderService, } from './translate-branding-loader.service'; import * as mock from './../../../mocks/index'; const initMockHttp = mock.http(jest); const initTranslateBrandingLoaderService = ( http?: Http, brandSettings?: BrandSettingsInterface, cdnUrl?: string, ) => { return new TranslateBrandingLoaderService( http, brandSettings, cdnUrl, ); }; describe('getTranslation', () => { // tslint:disable-next-line test('If the brandSettings have a matching alternativeTranslation, it calls http.get with the translationUrl', () => { const brandSettings = { alternativeTranslations: { test: 'abc', } as { [key: string]: string }, } as BrandSettingsInterface; const http = initMockHttp(); const translateBrandingLoaderService = initTranslateBrandingLoaderService( http, brandSettings, ); translateBrandingLoaderService.getTranslation( 'test', ); expect(http.get) .toHaveBeenCalledWith('abc'); }); // tslint:disable-next-line test('If the brandSettings have no matching alternativeTranslation, it calls http.get with the url based on the language selected', () => { const brandSettings = {} as BrandSettingsInterface; const http = initMockHttp(); const translateBrandingLoaderService = initTranslateBrandingLoaderService( http, brandSettings, 'testUrl', ); translateBrandingLoaderService.getTranslation( 'test', ); expect(http.get) .toHaveBeenCalledWith('testUrl/translations/test.json'); }); });