diff --git a/lib/content-services/karma.conf.js b/lib/content-services/karma.conf.js index 8a67ff3caf..fafa3944b7 100644 --- a/lib/content-services/karma.conf.js +++ b/lib/content-services/karma.conf.js @@ -3,41 +3,43 @@ module.exports = function (config) { config.set({ - basePath: '', + basePath: '../../', files: [ - {pattern: '../../node_modules/core-js/client/core.js', included: true, watched: false}, - {pattern: '../../node_modules/tslib/tslib.js', included: true, watched: false}, - {pattern: '../../node_modules/hammerjs/hammer.min.js', included: true, watched: false}, - {pattern: '../../node_modules/hammerjs/hammer.min.js.map', included: false, watched: false}, + {pattern: 'node_modules/core-js/client/core.js', included: true, watched: false}, + {pattern: 'node_modules/tslib/tslib.js', included: true, watched: false}, + {pattern: 'node_modules/hammerjs/hammer.min.js', included: true, watched: false}, + {pattern: 'node_modules/hammerjs/hammer.min.js.map', included: false, watched: false}, // pdf-js - {pattern: '../../node_modules/pdfjs-dist/build/pdf.js', included: true, watched: false}, - {pattern: '../../node_modules/pdfjs-dist/build/pdf.worker.js', included: true, watched: false}, - {pattern: '../../node_modules/pdfjs-dist/web/pdf_viewer.js', included: true, watched: false}, + {pattern: 'node_modules/pdfjs-dist/build/pdf.js', included: true, watched: false}, + {pattern: 'node_modules/pdfjs-dist/build/pdf.worker.js', included: true, watched: false}, + {pattern: 'node_modules/pdfjs-dist/web/pdf_viewer.js', included: true, watched: false}, { - pattern: '../../node_modules/@angular/material/prebuilt-themes/indigo-pink.css', + pattern: 'node_modules/@angular/material/prebuilt-themes/indigo-pink.css', included: true, watched: false }, - {pattern: '../../node_modules/alfresco-js-api/dist/alfresco-js-api.min.js', included: true, watched: false}, - {pattern: '../../node_modules/moment/min/moment.min.js', included: true, watched: false}, + {pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.min.js', included: true, watched: false}, + {pattern: 'node_modules/moment/min/moment.min.js', included: true, watched: false}, - {pattern: './i18n/**/en.json', included: false, served: true, watched: false}, + {pattern: 'lib/content-services/i18n/**/en.json', included: false, served: true, watched: false}, + {pattern: 'lib/core/i18n/**/en.json', included: false, served: true, watched: false}, - {pattern: './**/*.ts', included: false, served: true, watched: false}, + {pattern: 'lib/content-services/**/*.ts', included: false, served: true, watched: false}, - {pattern: './app.config.json', included: false, served: true, watched: false}, + {pattern: 'lib/config/app.config.json', included: false, served: true, watched: false}, ], frameworks: ['jasmine-ajax', 'jasmine', '@angular-devkit/build-angular'], proxies: { - '/base/assets/' :'/base/assets/', - '/assets/adf-content-services/i18n/en.json': '/base/i18n/en.json', - '/app.config.json': '/base/app.config.json' + '/base/assets/' :'/base/lib/content-services/assets/', + '/assets/adf-content-services/i18n/en.json': '/base/lib/content-services/i18n/en.json', + '/assets/adf-core/i18n/en.json': '/base/lib/core/i18n/en.json', + '/app.config.json': '/base/lib/config/app.config.json', }, plugins: [ diff --git a/lib/core/core.module.ts b/lib/core/core.module.ts index ab28312765..68034226f2 100644 --- a/lib/core/core.module.ts +++ b/lib/core/core.module.ts @@ -100,8 +100,8 @@ import { ViewUtilService } from './viewer/services/view-util.service'; import { LoginDialogService } from './services/login-dialog.service'; import { ExternalAlfrescoApiService } from './services/external-alfresco-api.service'; -export function createTranslateLoader(http: HttpClient, logService: LogService) { - return new TranslateLoaderService(http, logService); +export function createTranslateLoader(http: HttpClient) { + return new TranslateLoaderService(http); } export function providers() { diff --git a/lib/core/karma.conf.js b/lib/core/karma.conf.js index 2e19e7e067..a42b62dafd 100644 --- a/lib/core/karma.conf.js +++ b/lib/core/karma.conf.js @@ -28,11 +28,11 @@ module.exports = function (config) { {pattern: 'lib/core/i18n/**/en.json', included: false, served: true, watched: false}, - {pattern: 'lib/core/./**/*.ts', included: false, served: true, watched: false}, + {pattern: 'lib/core/**/*.ts', included: false, served: true, watched: false}, {pattern: 'lib/core/assets/**/*.svg', included: false, served: true, watched: false}, {pattern: 'lib/config/app.config.json', included: false, served: true, watched: false}, - {pattern: 'lib/core//viewer/assets/fake-test-file.pdf', included: false, served: true, watched: false}, + {pattern: 'lib/core/viewer/assets/fake-test-file.pdf', included: false, served: true, watched: false}, {pattern: 'lib/core/viewer/assets/fake-test-file.txt', included: false, served: true, watched: false}, { pattern: 'lib/core//viewer/assets/fake-test-password-file.pdf', diff --git a/lib/core/mock/translation.service.mock.ts b/lib/core/mock/translation.service.mock.ts index 34015859b7..7a591154a8 100644 --- a/lib/core/mock/translation.service.mock.ts +++ b/lib/core/mock/translation.service.mock.ts @@ -34,17 +34,13 @@ export class TranslationMock implements TranslationService { onLangChange: new EventEmitter() }; - addTranslationFolder() { + addTranslationFolder() {} - } + onTranslationChanged() {} - onTranslationChanged() { + use(): any {} - } - - use(): any { - - } + loadTranslation() {} get(key: string | Array, interpolateParams?: Object): Observable { return of(key); diff --git a/lib/core/services/translate-loader.service.ts b/lib/core/services/translate-loader.service.ts index ab9c417297..7413f93f3b 100644 --- a/lib/core/services/translate-loader.service.ts +++ b/lib/core/services/translate-loader.service.ts @@ -19,11 +19,10 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { TranslateLoader } from '@ngx-translate/core'; -import { Observable, forkJoin } from 'rxjs'; +import { Observable, forkJoin, throwError } from 'rxjs'; import { ComponentTranslationModel } from '../models/component.model'; import { ObjectUtils } from '../utils/object-utils'; -import { LogService } from './log.service'; -import { map } from 'rxjs/operators'; +import { map, catchError } from 'rxjs/operators'; @Injectable() export class TranslateLoaderService implements TranslateLoader { @@ -33,8 +32,7 @@ export class TranslateLoaderService implements TranslateLoader { private providers: ComponentTranslationModel[] = []; private queue: string [][] = []; - constructor(private http: HttpClient, - private logService: LogService) { + constructor(private http: HttpClient) { } registerProvider(name: string, path: string) { @@ -59,21 +57,16 @@ export class TranslateLoaderService implements TranslateLoader { if (!this.isComponentInQueue(lang, component.name)) { this.queue[lang].push(component.name); - const loader = Observable.create(observer => { - const translationUrl = `${component.path}/${this.prefix}/${lang}${this.suffix}?v=${Date.now()}`; + const translationUrl = `${component.path}/${this.prefix}/${lang}${this.suffix}?v=${Date.now()}`; - this.http.get(translationUrl).pipe(map((res: Response) => { - component.json[lang] = res; - })).subscribe((result) => { - observer.next(result); - observer.complete(); - }, () => { - observer.next(''); - observer.complete(); - }); - }); - - observableBatch.push(loader); + observableBatch.push( + this.http.get(translationUrl).pipe( + map((res: Response) => { + component.json[lang] = res; + }), + catchError(() => throwError(`Error loading ${translationUrl}`)) + ) + ); } }); @@ -114,7 +107,7 @@ export class TranslateLoaderService implements TranslateLoader { } getTranslation(lang: string): Observable { - let observableBatch = this.getComponentToFetch(lang); + const observableBatch = this.getComponentToFetch(lang); return Observable.create(observer => { if (observableBatch.length > 0) { @@ -126,13 +119,14 @@ export class TranslateLoaderService implements TranslateLoader { } observer.complete(); }, - (err: any) => { - this.logService.error(err); + (err) => { + observer.error(err); }); } else { let fullTranslation = this.getFullTranslationJSON(lang); if (fullTranslation) { observer.next(fullTranslation); + observer.complete(); } } }); diff --git a/lib/core/services/translation.service.ts b/lib/core/services/translation.service.ts index 6207fe4ac0..b1ca4feabc 100644 --- a/lib/core/services/translation.service.ts +++ b/lib/core/services/translation.service.ts @@ -62,22 +62,29 @@ export class TranslationService { addTranslationFolder(name: string = '', path: string = '') { if (!this.customLoader.providerRegistered(name)) { this.customLoader.registerProvider(name, path); + if (this.userLang) { - this.translate.getTranslation(this.userLang).subscribe(() => { - this.translate.use(this.userLang); - this.onTranslationChanged(this.userLang); - } - ); + this.loadTranslation(this.userLang, this.defaultLang); } else { - this.translate.getTranslation(this.defaultLang).subscribe(() => { - this.translate.use(this.defaultLang); - this.onTranslationChanged(this.defaultLang); - } - ); + this.loadTranslation(this.defaultLang); } } } + loadTranslation(lang: string, fallback?: string) { + this.translate.getTranslation(lang).subscribe( + () => { + this.translate.use(lang); + this.onTranslationChanged(lang); + }, + () => { + if (fallback && fallback !== lang) { + this.loadTranslation(fallback); + } + } + ); + } + /** * Triggers a notification callback when the translation language changes. * @param lang The new language code diff --git a/lib/process-services/attachment/process-attachment-list.component.spec.ts b/lib/process-services/attachment/process-attachment-list.component.spec.ts index 1715510ffb..e4aba93084 100644 --- a/lib/process-services/attachment/process-attachment-list.component.spec.ts +++ b/lib/process-services/attachment/process-attachment-list.component.spec.ts @@ -309,6 +309,10 @@ describe('Custom CustomEmptyTemplateComponent', () => { fixture.detectChanges(); }); + afterEach(() => { + fixture.destroy(); + }); + it('should render the custom template', async(() => { fixture.whenStable().then(() => { fixture.detectChanges(); diff --git a/lib/process-services/attachment/task-attachment-list.component.spec.ts b/lib/process-services/attachment/task-attachment-list.component.spec.ts index 6b61efb99f..615ba5d972 100644 --- a/lib/process-services/attachment/task-attachment-list.component.spec.ts +++ b/lib/process-services/attachment/task-attachment-list.component.spec.ts @@ -336,6 +336,10 @@ describe('Custom CustomEmptyTemplateComponent', () => { fixture.detectChanges(); }); + afterEach(() => { + fixture.destroy(); + }); + it('should render the custom template', async(() => { fixture.whenStable().then(() => { fixture.detectChanges(); diff --git a/lib/process-services/karma.conf.js b/lib/process-services/karma.conf.js index f03a1ef131..eafdfddc61 100644 --- a/lib/process-services/karma.conf.js +++ b/lib/process-services/karma.conf.js @@ -3,50 +3,53 @@ module.exports = function (config) { config.set({ - basePath: '', + basePath: '../../', files: [ - {pattern: '../../node_modules/core-js/client/core.js', included: true, watched: false}, - {pattern: '../../node_modules/tslib/tslib.js', included: true, watched: false}, - {pattern: '../../node_modules/hammerjs/hammer.min.js', included: true, watched: false}, - {pattern: '../../node_modules/hammerjs/hammer.min.js.map', included: false, watched: false}, + {pattern: 'node_modules/core-js/client/core.js', included: true, watched: false}, + {pattern: 'node_modules/tslib/tslib.js', included: true, watched: false}, + {pattern: 'node_modules/hammerjs/hammer.min.js', included: true, watched: false}, + {pattern: 'node_modules/hammerjs/hammer.min.js.map', included: false, watched: false}, // pdf-js - {pattern: '../../node_modules/pdfjs-dist/build/pdf.js', included: true, watched: false}, - {pattern: '../../node_modules/pdfjs-dist/build/pdf.worker.js', included: true, watched: false}, - {pattern: '../../node_modules/pdfjs-dist/web/pdf_viewer.js', included: true, watched: false}, + {pattern: 'node_modules/pdfjs-dist/build/pdf.js', included: true, watched: false}, + {pattern: 'node_modules/pdfjs-dist/build/pdf.worker.js', included: true, watched: false}, + {pattern: 'node_modules/pdfjs-dist/web/pdf_viewer.js', included: true, watched: false}, { - pattern: '../../node_modules/@angular/material/prebuilt-themes/indigo-pink.css', + pattern: 'node_modules/@angular/material/prebuilt-themes/indigo-pink.css', included: true, watched: false }, - {pattern: '../../node_modules/chart.js/dist/Chart.js', included: true, watched: false}, - {pattern: '../../node_modules/raphael/raphael.min.js', included: true, watched: false}, + {pattern: 'node_modules/chart.js/dist/Chart.js', included: true, watched: false}, + {pattern: 'node_modules/raphael/raphael.min.js', included: true, watched: false}, { - pattern: './node_modules/ng2-charts/bundles/ng2-charts.umd.js', + pattern: 'node_modules/ng2-charts/bundles/ng2-charts.umd.js', included: false, served: true, watched: false }, - {pattern: '../../node_modules/alfresco-js-api/dist/alfresco-js-api.min.js', included: true, watched: false}, - {pattern: '../../node_modules/moment/min/moment.min.js', included: true, watched: false}, + {pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.min.js', included: true, watched: false}, + {pattern: 'node_modules/moment/min/moment.min.js', included: true, watched: false}, - {pattern: './i18n/**/en.json', included: false, served: true, watched: false}, + {pattern: 'lib/core/i18n/**/en.json', included: false, served: true, watched: false}, + {pattern: 'lib/content-services/i18n/**/en.json', included: false, served: true, watched: false}, + {pattern: 'lib/process-services/i18n/**/en.json', included: false, served: true, watched: false}, - {pattern: './**/*.ts', included: false, served: true, watched: false}, - - {pattern: './app.config.json', included: false, served: true, watched: false}, + {pattern: 'lib/process-services/**/*.ts', included: false, served: true, watched: false}, + {pattern: 'lib/config/app.config.json', included: false, served: true, watched: false} ], frameworks: ['jasmine-ajax', 'jasmine', '@angular-devkit/build-angular'], proxies: { '/base/assets/' :'/base/assets/', - '/assets/adf-process-services/i18n/en.json': '/base/i18n/en.json', - '/app.config.json': '/base/app.config.json' + '/assets/adf-core/i18n/en.json': '/base/lib/core/i18n/en.json', + '/assets/adf-content-services/i18n/en.json': '/base/lib/content-services/i18n/en.json', + '/assets/adf-process-services/i18n/en.json': '/base/lib/process-services/i18n/en.json', + '/app.config.json': '/base/lib/config/app.config.json' }, plugins: [ diff --git a/lib/process-services/process-list/components/process-list.component.spec.ts b/lib/process-services/process-list/components/process-list.component.spec.ts index f7109c9f5a..f641b23484 100644 --- a/lib/process-services/process-list/components/process-list.component.spec.ts +++ b/lib/process-services/process-list/components/process-list.component.spec.ts @@ -516,7 +516,7 @@ describe('CustomProcessListComponent', () => { class EmptyTemplateComponent { } -describe('Custom EmptyTemplateComponent', () => { +describe('Process List: Custom EmptyTemplateComponent', () => { let fixture: ComponentFixture; setupTestBed({ @@ -530,6 +530,10 @@ describe('Custom EmptyTemplateComponent', () => { fixture.detectChanges(); }); + afterEach(() => { + fixture.destroy(); + }); + it('should render the custom template', async(() => { fixture.whenStable().then(() => { fixture.detectChanges(); diff --git a/lib/process-services/task-list/components/task-list.component.spec.ts b/lib/process-services/task-list/components/task-list.component.spec.ts index 2caefbf31d..7b8155a4b3 100644 --- a/lib/process-services/task-list/components/task-list.component.spec.ts +++ b/lib/process-services/task-list/components/task-list.component.spec.ts @@ -16,7 +16,7 @@ */ import { Component, SimpleChange, ViewChild, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; +import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { AppConfigService, setupTestBed, CoreModule } from '@alfresco/adf-core'; import { DataRowEvent, ObjectDataRow } from '@alfresco/adf-core'; @@ -24,6 +24,8 @@ import { TaskListService } from '../services/tasklist.service'; import { TaskListComponent } from './task-list.component'; import { ProcessTestingModule } from '../../testing/process.testing.module'; import { fakeGlobalTask, fakeCutomSchema } from '../../mock'; +import { TranslateService } from '@ngx-translate/core'; +import { of } from 'rxjs'; declare let jasmine: any; @@ -74,6 +76,7 @@ describe('TaskListComponent', () => { afterEach(() => { jasmine.Ajax.uninstall(); + fixture.destroy(); }); it('should use the default schemaColumn as default', () => { @@ -543,6 +546,10 @@ describe('CustomTaskListComponent', () => { component = fixture.componentInstance; }); + afterEach(() => { + fixture.destroy(); + }); + it('should create instance of CustomTaskListComponent', () => { expect(component instanceof CustomTaskListComponent).toBe(true, 'should create CustomTaskListComponent'); }); @@ -568,8 +575,9 @@ describe('CustomTaskListComponent', () => { class EmptyTemplateComponent { } -describe('Custom EmptyTemplateComponent', () => { +describe('Task List: Custom EmptyTemplateComponent', () => { let fixture: ComponentFixture; + let translateService: TranslateService; setupTestBed({ imports: [ProcessTestingModule], @@ -578,15 +586,23 @@ describe('Custom EmptyTemplateComponent', () => { }); beforeEach(() => { + translateService = TestBed.get(TranslateService); + spyOn(translateService, 'get').and.callFake((key) => { + return of(key); + }); + fixture = TestBed.createComponent(EmptyTemplateComponent); fixture.detectChanges(); }); - it('should render the custom template', async(() => { - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('#custom-id'))).not.toBeNull(); - expect(fixture.debugElement.query(By.css('.adf-empty-content'))).toBeNull(); - }); + afterEach(() => { + fixture.destroy(); + }); + + it('should render the custom template', fakeAsync(() => { + fixture.detectChanges(); + tick(100); + expect(fixture.debugElement.query(By.css('#custom-id'))).not.toBeNull(); + expect(fixture.debugElement.query(By.css('.adf-empty-content'))).toBeNull(); })); }); diff --git a/lib/process-services/task-list/components/task-standalone.component.spec.ts b/lib/process-services/task-list/components/task-standalone.component.spec.ts index 2764c0fde0..8c5730a0fa 100644 --- a/lib/process-services/task-list/components/task-standalone.component.spec.ts +++ b/lib/process-services/task-list/components/task-standalone.component.spec.ts @@ -31,12 +31,16 @@ describe('TaskStandaloneComponent', () => { ] }); - beforeEach(async(() => { + beforeEach(() => { fixture = TestBed.createComponent(TaskStandaloneComponent); component = fixture.componentInstance; element = fixture.nativeElement; fixture.detectChanges(); - })); + }); + + afterEach(() => { + fixture.destroy(); + }); it('should show Completed message if isCompleted is true', async(() => { component.isCompleted = true;