diff --git a/projects/aca-content/src/lib/components/header-actions/header-actions.component.spec.ts b/projects/aca-content/src/lib/components/header-actions/header-actions.component.spec.ts index d3fead020..4348f8f4e 100644 --- a/projects/aca-content/src/lib/components/header-actions/header-actions.component.spec.ts +++ b/projects/aca-content/src/lib/components/header-actions/header-actions.component.spec.ts @@ -24,14 +24,16 @@ import { of } from 'rxjs'; import { By } from '@angular/platform-browser'; import { CoreModule } from '@alfresco/adf-core'; import { AppHeaderActionsModule } from './header-actions.module'; +import { RouterTestingModule } from '@angular/router/testing'; +import { Router } from '@angular/router'; describe('HeaderActionsComponent', () => { - let component: HeaderActionsComponent; let fixture: ComponentFixture; + let router: Router; beforeEach(() => { TestBed.configureTestingModule({ - imports: [AppTestingModule, CoreModule.forRoot(), AppHeaderActionsModule], + imports: [AppTestingModule, CoreModule.forRoot(), AppHeaderActionsModule, RouterTestingModule], declarations: [HeaderActionsComponent] }); @@ -61,8 +63,9 @@ describe('HeaderActionsComponent', () => { ]) ); + router = TestBed.inject(Router); + fixture = TestBed.createComponent(HeaderActionsComponent); - component = fixture.componentInstance; fixture.detectChanges(); }); @@ -70,7 +73,7 @@ describe('HeaderActionsComponent', () => { const getUploadButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id="upload-button"]')).nativeElement; it('total number of buttons in header should be 2 if route is personal-files', async () => { - spyOn(component, 'isPersonalFilesRoute').and.returnValue(true); + spyOnProperty(router, 'url').and.returnValue('/personal-files'); fixture.detectChanges(); await fixture.whenStable(); @@ -83,7 +86,7 @@ describe('HeaderActionsComponent', () => { }); it('total number of buttons in header should be 1 if route is libraries', async () => { - spyOn(component, 'isLibrariesRoute').and.returnValue(true); + spyOnProperty(router, 'url').and.returnValue('/libraries'); fixture.detectChanges(); await fixture.whenStable(); @@ -95,7 +98,7 @@ describe('HeaderActionsComponent', () => { }); it('should render menu items when create menu is opened', async () => { - spyOn(component, 'isPersonalFilesRoute').and.returnValue(true); + spyOnProperty(router, 'url').and.returnValue('/personal-files'); fixture.detectChanges(); await fixture.whenStable(); @@ -112,7 +115,7 @@ describe('HeaderActionsComponent', () => { }); it('should render menu items when upload menu is opened', async () => { - spyOn(component, 'isPersonalFilesRoute').and.returnValue(true); + spyOnProperty(router, 'url').and.returnValue('/personal-files'); fixture.detectChanges(); await fixture.whenStable(); diff --git a/projects/aca-content/src/lib/components/header-actions/header-actions.component.ts b/projects/aca-content/src/lib/components/header-actions/header-actions.component.ts index c3371dbd5..bbfcc5383 100644 --- a/projects/aca-content/src/lib/components/header-actions/header-actions.component.ts +++ b/projects/aca-content/src/lib/components/header-actions/header-actions.component.ts @@ -23,7 +23,7 @@ * along with Alfresco. If not, see . */ -import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; +import { Component, OnDestroy, ViewEncapsulation } from '@angular/core'; import { Router } from '@angular/router'; import { Store } from '@ngrx/store'; import { ContentManagementService } from '../../services/content-management.service'; @@ -36,53 +36,37 @@ import { SetCurrentFolderAction, AppStore } from '@alfresco/aca-shared/store'; styleUrls: ['./header-actions.component.scss'], encapsulation: ViewEncapsulation.None }) -export class HeaderActionsComponent extends PageComponent implements OnInit, OnDestroy { +export class HeaderActionsComponent extends PageComponent implements OnDestroy { constructor(private router: Router, store: Store, content: ContentManagementService, extensions: AppExtensionService) { super(store, extensions, content); } - ngOnInit() { - super.ngOnInit(); - } - ngOnDestroy() { this.store.dispatch(new SetCurrentFolderAction(null)); super.ngOnDestroy(); } - isPersonalFilesRoute(): boolean { + private isPersonalFilesRoute(): boolean { return this.router.url.includes('/personal-files'); } - isFavoriteLibrariesRoute(): boolean { + private isFavoriteLibrariesRoute(): boolean { return this.router.url.includes('/favorite/libraries'); } - isLibrariesRoute(): boolean { + private isLibrariesRoute(): boolean { return this.router.url.includes('/libraries'); } canShowCreateButton(): boolean { - if (this.isPersonalFilesRoute() || this.isFavoriteLibrariesRoute() || this.isLibrariesRoute()) { - return true; - } else { - return false; - } + return this.isPersonalFilesRoute() || this.isFavoriteLibrariesRoute() || this.isLibrariesRoute(); } canShowUploadButton(): boolean { - if (this.isPersonalFilesRoute()) { - return true; - } else { - return false; - } + return this.isPersonalFilesRoute(); } canShowSearchSeparator(): boolean { - if (this.isPersonalFilesRoute() || this.isFavoriteLibrariesRoute() || this.isLibrariesRoute()) { - return true; - } else { - return false; - } + return this.canShowUploadButton() || this.canShowCreateButton(); } }