cleanup unit tests

This commit is contained in:
Denys Vuika
2023-02-13 13:06:53 -05:00
committed by Yasa-Nataliya
parent 88305cec95
commit 93f4fac38d
2 changed files with 18 additions and 31 deletions

View File

@@ -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<HeaderActionsComponent>;
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();

View File

@@ -23,7 +23,7 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
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<AppStore>, 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();
}
}