mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[ACS-10732] After switching the language and reloading, the app reverts many components back to English. (#5116)
This commit is contained in:
+40
-4
@@ -22,18 +22,30 @@
|
|||||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { SaveSearchSidenavComponent } from './save-search-sidenav.component';
|
import { SaveSearchSidenavComponent } from './save-search-sidenav.component';
|
||||||
import { AppTestingModule } from '../../../../testing/app-testing.module';
|
import { AppTestingModule } from '../../../../testing/app-testing.module';
|
||||||
|
import { EventEmitter } from '@angular/core';
|
||||||
import { Observable, of } from 'rxjs';
|
import { Observable, of } from 'rxjs';
|
||||||
import { SavedSearchesContextService } from '../../../../services/saved-searches-context.service';
|
import { SavedSearchesContextService } from '../../../../services/saved-searches-context.service';
|
||||||
import { SavedSearch } from '@alfresco/adf-content-services';
|
import { SavedSearch } from '@alfresco/adf-content-services';
|
||||||
import { NavBarLinkRef } from '@alfresco/adf-extensions';
|
import { NavBarLinkRef } from '@alfresco/adf-extensions';
|
||||||
|
import { TranslationService } from '@alfresco/adf-core';
|
||||||
|
import { LangChangeEvent } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
interface TranslationServiceMock {
|
||||||
|
instant: jasmine.Spy<(key: string) => string>;
|
||||||
|
translate: {
|
||||||
|
onLangChange: EventEmitter<LangChangeEvent>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
describe('SaveSearchSidenavComponent', () => {
|
describe('SaveSearchSidenavComponent', () => {
|
||||||
let fixture: ComponentFixture<SaveSearchSidenavComponent>;
|
let fixture: ComponentFixture<SaveSearchSidenavComponent>;
|
||||||
let component: SaveSearchSidenavComponent;
|
let component: SaveSearchSidenavComponent;
|
||||||
let savedSearchesService: SavedSearchesContextService;
|
let savedSearchesService: SavedSearchesContextService;
|
||||||
|
let translationServiceMock: TranslationServiceMock;
|
||||||
|
const langChangeEmitter = new EventEmitter<LangChangeEvent>();
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const mockService: Partial<SavedSearchesContextService> = {
|
const mockService: Partial<SavedSearchesContextService> = {
|
||||||
@@ -43,12 +55,24 @@ describe('SaveSearchSidenavComponent', () => {
|
|||||||
return of([]);
|
return of([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
translationServiceMock = {
|
||||||
|
instant: jasmine.createSpy('instant').and.callFake((key: string) => key),
|
||||||
|
translate: {
|
||||||
|
onLangChange: langChangeEmitter
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [AppTestingModule, SaveSearchSidenavComponent],
|
imports: [AppTestingModule, SaveSearchSidenavComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
provide: SavedSearchesContextService,
|
provide: SavedSearchesContextService,
|
||||||
useValue: mockService
|
useValue: mockService
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: TranslationService,
|
||||||
|
useValue: translationServiceMock
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -81,11 +105,11 @@ describe('SaveSearchSidenavComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set navbar object with children is searches are saved', fakeAsync(() => {
|
it('should set navbar object with children if searches are saved', () => {
|
||||||
spyOnProperty(savedSearchesService, 'savedSearches$', 'get').and.returnValue(of([{ name: '1', order: 0, encodedUrl: 'abc' }]));
|
spyOnProperty(savedSearchesService, 'savedSearches$', 'get').and.returnValue(of([{ name: '1', order: 0, encodedUrl: 'abc' }]));
|
||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
tick(100);
|
|
||||||
expect(component.item.children[0]).toEqual({
|
expect(component.item.children[0]).toEqual({
|
||||||
icon: '',
|
icon: '',
|
||||||
title: '1',
|
title: '1',
|
||||||
@@ -94,7 +118,19 @@ describe('SaveSearchSidenavComponent', () => {
|
|||||||
url: 'search?q=abc',
|
url: 'search?q=abc',
|
||||||
id: 'search1'
|
id: 'search1'
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
it('should update title when language changes', () => {
|
||||||
|
spyOnProperty(savedSearchesService, 'savedSearches$', 'get').and.returnValue(of([{ name: '1', order: 0, encodedUrl: 'abc' }]));
|
||||||
|
translationServiceMock.instant.and.returnValue('Translated Title (1)');
|
||||||
|
|
||||||
|
component.ngOnInit();
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
langChangeEmitter.emit({ lang: 'de', translations: {} });
|
||||||
|
|
||||||
|
expect(component.item.title).toBe('Translated Title (1)');
|
||||||
|
});
|
||||||
|
|
||||||
describe('onActionClicked', () => {
|
describe('onActionClicked', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
+2
-7
@@ -24,11 +24,10 @@
|
|||||||
|
|
||||||
import { Component, DestroyRef, inject, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, DestroyRef, inject, OnInit, ViewEncapsulation } from '@angular/core';
|
||||||
import { SavedSearch } from '@alfresco/adf-content-services';
|
import { SavedSearch } from '@alfresco/adf-content-services';
|
||||||
import { TranslationService, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core';
|
import { TranslationService } from '@alfresco/adf-core';
|
||||||
import { NavBarLinkRef } from '@alfresco/adf-extensions';
|
import { NavBarLinkRef } from '@alfresco/adf-extensions';
|
||||||
import { ExpandMenuComponent } from '../../../sidenav/components/expand-menu.component';
|
import { ExpandMenuComponent } from '../../../sidenav/components/expand-menu.component';
|
||||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
import { delay } from 'rxjs/operators';
|
|
||||||
import { SavedSearchesContextService } from '../../../../services/saved-searches-context.service';
|
import { SavedSearchesContextService } from '../../../../services/saved-searches-context.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -47,7 +46,6 @@ export class SaveSearchSidenavComponent implements OnInit {
|
|||||||
|
|
||||||
private readonly manageSearchesId = 'manage-saved-searches';
|
private readonly manageSearchesId = 'manage-saved-searches';
|
||||||
private readonly destroyRef = inject(DestroyRef);
|
private readonly destroyRef = inject(DestroyRef);
|
||||||
private readonly userPreferenceService = inject(UserPreferencesService);
|
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.savedSearchesService.init();
|
this.savedSearchesService.init();
|
||||||
@@ -56,10 +54,7 @@ export class SaveSearchSidenavComponent implements OnInit {
|
|||||||
this.savedSearchCount = savedSearches.length;
|
this.savedSearchCount = savedSearches.length;
|
||||||
this.savedSearches = savedSearches;
|
this.savedSearches = savedSearches;
|
||||||
});
|
});
|
||||||
this.userPreferenceService
|
this.translationService.translate.onLangChange.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
|
||||||
.select(UserPreferenceValues.Locale)
|
|
||||||
.pipe(takeUntilDestroyed(this.destroyRef), delay(10))
|
|
||||||
.subscribe(() => {
|
|
||||||
if (this.item) {
|
if (this.item) {
|
||||||
this.item.title = this.translationService.instant('APP.BROWSE.SEARCH.SAVE_SEARCH.NAVBAR.TITLE', { number: this.savedSearchCount });
|
this.item.title = this.translationService.instant('APP.BROWSE.SEARCH.SAVE_SEARCH.NAVBAR.TITLE', { number: this.savedSearchCount });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user