From c2a1dd9ae5647bd09c73e97acbe921806e9acde9 Mon Sep 17 00:00:00 2001 From: vijayanssettu <88775344+vijayanssettu@users.noreply.github.com> Date: Fri, 28 Apr 2023 19:11:12 +0530 Subject: [PATCH] [ACS-3742] Bug Fixes for new Layout (#3149) * Bug Fixes * Bug Fixes * Bug Fixes * Bug Fixes * implemented review comments * ACS-3742 Renamed title --------- Co-authored-by: Aleksander Sklorz --- .../search-input.component.spec.ts | 29 +++++++++++++++++-- .../search-input/search-input.component.ts | 5 +++- ...search-libraries-results.component.spec.ts | 21 +++++++++++++- .../search-libraries-results.component.ts | 4 ++- .../search/search-navigation.service.spec.ts | 8 +++++ .../search/search-navigation.service.ts | 2 ++ 6 files changed, 64 insertions(+), 5 deletions(-) diff --git a/projects/aca-content/src/lib/components/search/search-input/search-input.component.spec.ts b/projects/aca-content/src/lib/components/search/search-input/search-input.component.spec.ts index 3d19b9bb0b..d63e3608c5 100644 --- a/projects/aca-content/src/lib/components/search/search-input/search-input.component.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-input/search-input.component.spec.ts @@ -28,10 +28,11 @@ import { SearchInputComponent } from './search-input.component'; import { AppTestingModule } from '../../../testing/app-testing.module'; import { Actions, ofType } from '@ngrx/effects'; import { SearchByTermAction, SearchActionTypes, SnackbarErrorAction, SnackbarActionTypes } from '@alfresco/aca-shared/store'; -import { AppHookService } from '@alfresco/aca-shared'; +import { AppHookService, AppService } from '@alfresco/aca-shared'; import { map } from 'rxjs/operators'; import { SearchQueryBuilderService } from '@alfresco/adf-content-services'; import { SearchNavigationService } from '../search-navigation.service'; +import { BehaviorSubject, Subject } from 'rxjs'; describe('SearchInputComponent', () => { let fixture: ComponentFixture; @@ -39,12 +40,22 @@ describe('SearchInputComponent', () => { let actions$: Actions; let appHookService: AppHookService; let searchInputService: SearchNavigationService; + const appServiceMock = { + appNavNarMode$: new BehaviorSubject('collapsed'), + toggleAppNavBar$: new Subject() + }; beforeEach(() => { TestBed.configureTestingModule({ imports: [AppTestingModule], declarations: [SearchInputComponent], - providers: [SearchQueryBuilderService], + providers: [ + { + provide: AppService, + useValue: appServiceMock + }, + SearchQueryBuilderService + ], schemas: [NO_ERRORS_SCHEMA] }); @@ -59,6 +70,13 @@ describe('SearchInputComponent', () => { fixture.destroy(); }); + it('should collapsed sidenav by default', () => { + spyOn(appServiceMock.appNavNarMode$, 'next'); + component.ngOnInit(); + + expect(appServiceMock.appNavNarMode$.next).toHaveBeenCalledWith('collapsed'); + }); + it('should change flag on library400Error event', async () => { fixture.detectChanges(); await fixture.whenStable(); @@ -225,4 +243,11 @@ describe('SearchInputComponent', () => { expect(searchInputService.navigateBack).toHaveBeenCalledWith(); }); }); + + it('should sidenav expanded after the component is destroy', () => { + spyOn(appServiceMock.appNavNarMode$, 'next'); + component.ngOnDestroy(); + + expect(appServiceMock.appNavNarMode$.next).toHaveBeenCalledWith('expanded'); + }); }); diff --git a/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts b/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts index b732dc55c4..e73004fa6a 100644 --- a/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts +++ b/projects/aca-content/src/lib/components/search/search-input/search-input.component.ts @@ -22,7 +22,7 @@ * from Hyland Software. If not, see . */ -import { AppHookService } from '@alfresco/aca-shared'; +import { AppHookService, AppService } from '@alfresco/aca-shared'; import { AppStore, SearchByTermAction, SearchOptionIds, SearchOptionModel, SnackbarErrorAction } from '@alfresco/aca-shared/store'; import { SearchQueryBuilderService } from '@alfresco/adf-content-services'; import { AppConfigService } from '@alfresco/adf-core'; @@ -86,6 +86,7 @@ export class SearchInputComponent implements OnInit, OnDestroy { private router: Router, private store: Store, private appHookService: AppHookService, + private appService: AppService, public searchInputService: SearchNavigationService ) { this.searchOnChange = this.config.get('search.aca:triggeredOnChange', true); @@ -113,6 +114,7 @@ export class SearchInputComponent implements OnInit, OnDestroy { } showInputValue() { + this.appService.appNavNarMode$.next('collapsed'); this.has400LibraryError = false; this.searchedWord = this.getUrlSearchTerm(); @@ -122,6 +124,7 @@ export class SearchInputComponent implements OnInit, OnDestroy { } ngOnDestroy(): void { + this.appService.appNavNarMode$.next('expanded'); this.onDestroy$.next(true); this.onDestroy$.complete(); this.removeContentFilters(); diff --git a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.spec.ts b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.spec.ts index d45417d481..6465a86642 100644 --- a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.spec.ts @@ -29,19 +29,31 @@ import { NO_ERRORS_SCHEMA } from '@angular/core'; import { SearchLibrariesResultsComponent } from './search-libraries-results.component'; import { SearchLibrariesQueryBuilderService } from './search-libraries-query-builder.service'; import { DocumentListComponent } from '@alfresco/adf-content-services'; +import { BehaviorSubject, Subject } from 'rxjs'; +import { AppService } from '@alfresco/aca-shared'; describe('SearchLibrariesResultsComponent', () => { let component: SearchLibrariesResultsComponent; let fixture: ComponentFixture; const emptyPage = { list: { pagination: { totalItems: 0 }, entries: [] } }; + const appServiceMock = { + appNavNarMode$: new BehaviorSubject('collapsed'), + toggleAppNavBar$: new Subject() + }; beforeEach(() => { TestBed.configureTestingModule({ imports: [AppTestingModule, AppConfigModule], declarations: [DataTableComponent, DocumentListComponent, SearchLibrariesResultsComponent], schemas: [NO_ERRORS_SCHEMA], - providers: [SearchLibrariesQueryBuilderService] + providers: [ + { + provide: AppService, + useValue: appServiceMock + }, + SearchLibrariesQueryBuilderService + ] }); fixture = TestBed.createComponent(SearchLibrariesResultsComponent); @@ -54,4 +66,11 @@ describe('SearchLibrariesResultsComponent', () => { expect(component.onSearchResultLoaded).toHaveBeenCalledWith(emptyPage); }); + + it('should collapsed sidenav by default', () => { + spyOn(appServiceMock.appNavNarMode$, 'next'); + component.ngOnInit(); + + expect(appServiceMock.appNavNarMode$.next).toHaveBeenCalledWith('collapsed'); + }); }); diff --git a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts index 97b78869b9..a0e7103da9 100644 --- a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts +++ b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts @@ -30,7 +30,7 @@ import { ActivatedRoute, Params } from '@angular/router'; import { Store } from '@ngrx/store'; import { ContentManagementService } from '../../../services/content-management.service'; import { SearchLibrariesQueryBuilderService } from './search-libraries-query-builder.service'; -import { AppExtensionService, AppHookService, PageComponent } from '@alfresco/aca-shared'; +import { AppExtensionService, AppHookService, AppService, PageComponent } from '@alfresco/aca-shared'; import { DocumentListPresetRef } from '@alfresco/adf-extensions'; @Component({ @@ -52,6 +52,7 @@ export class SearchLibrariesResultsComponent extends PageComponent implements On private librariesQueryBuilder: SearchLibrariesQueryBuilderService, private route: ActivatedRoute, private appHookService: AppHookService, + private appService: AppService, store: Store, extensions: AppExtensionService, content: ContentManagementService @@ -65,6 +66,7 @@ export class SearchLibrariesResultsComponent extends PageComponent implements On } ngOnInit() { + this.appService.appNavNarMode$.next('collapsed'); super.ngOnInit(); this.columns = this.extensions.documentListPresets.searchLibraries || []; diff --git a/projects/aca-content/src/lib/components/search/search-navigation.service.spec.ts b/projects/aca-content/src/lib/components/search/search-navigation.service.spec.ts index 60c4590880..04a4712a83 100644 --- a/projects/aca-content/src/lib/components/search/search-navigation.service.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-navigation.service.spec.ts @@ -62,4 +62,12 @@ describe('SearchNavigationService', () => { expect(routerNavigate).toHaveBeenCalledWith(['/search']); }); + + it('should navigate back to the previous route when call the navigateBack function', () => { + const routerNavigate = spyOn(router, 'navigate'); + service.saveRoute(''); + service.navigateBack(); + + expect(routerNavigate).toHaveBeenCalledWith(['/personal-files']); + }); }); diff --git a/projects/aca-content/src/lib/components/search/search-navigation.service.ts b/projects/aca-content/src/lib/components/search/search-navigation.service.ts index 412816449a..59de18c17c 100644 --- a/projects/aca-content/src/lib/components/search/search-navigation.service.ts +++ b/projects/aca-content/src/lib/components/search/search-navigation.service.ts @@ -44,6 +44,8 @@ export class SearchNavigationService { navigateBack(): void { if (this.previousRoute) { this.router.navigate([this.previousRoute]); + } else { + this.router.navigate(['/personal-files']); } }