mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-09-17 14:21:14 +00:00
fix unit tests
This commit is contained in:
committed by
Yasa-Nataliya
parent
a4c640d757
commit
1dd1a513b5
@@ -11,9 +11,9 @@
|
||||
margin-left: 24px;
|
||||
|
||||
adf-toolbar-divider {
|
||||
width: 24px !important;
|
||||
height: 32px !important;
|
||||
margin: 4px 0 0 12px !important;
|
||||
width: 24px;
|
||||
height: 32px;
|
||||
margin: 4px 0 0 12px;
|
||||
}
|
||||
|
||||
& > button {
|
||||
|
@@ -28,9 +28,6 @@ import { AppHeaderActionsModule } from './header-actions.module';
|
||||
describe('HeaderActionsComponent', () => {
|
||||
let component: HeaderActionsComponent;
|
||||
let fixture: ComponentFixture<HeaderActionsComponent>;
|
||||
let extensionService: AppExtensionService;
|
||||
let getCreateActionsSpy: jasmine.Spy;
|
||||
let getUploadActionsSpy: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@@ -38,12 +35,8 @@ describe('HeaderActionsComponent', () => {
|
||||
declarations: [HeaderActionsComponent]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(HeaderActionsComponent);
|
||||
component = fixture.componentInstance;
|
||||
extensionService = TestBed.inject(AppExtensionService);
|
||||
|
||||
getCreateActionsSpy = spyOn(extensionService, 'getCreateActions');
|
||||
getCreateActionsSpy.and.returnValue(
|
||||
const extensionService = TestBed.inject(AppExtensionService);
|
||||
spyOn(extensionService, 'getCreateActions').and.returnValue(
|
||||
of([
|
||||
{
|
||||
id: 'action1',
|
||||
@@ -58,8 +51,7 @@ describe('HeaderActionsComponent', () => {
|
||||
])
|
||||
);
|
||||
|
||||
getUploadActionsSpy = spyOn(extensionService, 'getUploadActions');
|
||||
getUploadActionsSpy.and.returnValue(
|
||||
spyOn(extensionService, 'getUploadActions').and.returnValue(
|
||||
of([
|
||||
{
|
||||
id: 'action3',
|
||||
@@ -74,67 +66,63 @@ describe('HeaderActionsComponent', () => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
const getCreateButton = (): HTMLButtonElement => fixture.debugElement.query(By.css('[data-automation-id="create-button"]')).nativeElement;
|
||||
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);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const buttons = fixture.debugElement.queryAll(By.css('.action-bar > .aca-mat-button'));
|
||||
const createButton: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="create-button"]')).nativeElement;
|
||||
const uploadButton: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="upload-button"]')).nativeElement;
|
||||
|
||||
expect(buttons.length).toBe(2);
|
||||
expect(createButton).toBeTruthy();
|
||||
expect(uploadButton).toBeTruthy();
|
||||
expect(getCreateButton()).toBeTruthy();
|
||||
expect(getUploadButton()).toBeTruthy();
|
||||
});
|
||||
|
||||
it('total number of buttons in header should be 1 if route is libraries', async () => {
|
||||
spyOn(component, 'isLibrariesRoute').and.returnValue(true);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const buttons = fixture.debugElement.queryAll(By.css('.action-bar > .aca-mat-button'));
|
||||
const createButton: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="create-button"]')).nativeElement;
|
||||
|
||||
expect(buttons.length).toBe(1);
|
||||
expect(createButton).toBeTruthy();
|
||||
expect(getCreateButton()).toBeTruthy();
|
||||
});
|
||||
|
||||
async function clickCreateMenu() {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const button: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="create-button"]')).nativeElement;
|
||||
button.click();
|
||||
}
|
||||
|
||||
async function clickUploadMenu() {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const button: HTMLButtonElement = fixture.debugElement.query(By.css('[data-automation-id="upload-button"]')).nativeElement;
|
||||
button.click();
|
||||
}
|
||||
|
||||
it('should render menu items when create menu is opened', async () => {
|
||||
spyOn(component, 'isPersonalFilesRoute').and.returnValue(true);
|
||||
await clickCreateMenu();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
getCreateButton().click();
|
||||
|
||||
const menuItems = fixture.debugElement.queryAll(By.css('.app-toolbar-menu-item'));
|
||||
expect(menuItems.length).toBe(2);
|
||||
|
||||
const menuItemOne: HTMLSpanElement = (menuItems[0].nativeElement as HTMLButtonElement).querySelector('[data-automation-id="menu-item-title"]');
|
||||
const menuItemTwo: HTMLSpanElement = (menuItems[1].nativeElement as HTMLButtonElement).querySelector('[data-automation-id="menu-item-title"]');
|
||||
const menuItemOne = (menuItems[0].nativeElement as HTMLButtonElement).querySelector<HTMLSpanElement>('[data-automation-id="menu-item-title"]');
|
||||
const menuItemTwo = (menuItems[1].nativeElement as HTMLButtonElement).querySelector<HTMLSpanElement>('[data-automation-id="menu-item-title"]');
|
||||
expect(menuItemOne.innerText).toBe('create action one');
|
||||
expect(menuItemTwo.innerText).toBe('create action two');
|
||||
});
|
||||
|
||||
it('should render menu items when upload menu is opened', async () => {
|
||||
spyOn(component, 'isPersonalFilesRoute').and.returnValue(true);
|
||||
await clickUploadMenu();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
getUploadButton().click();
|
||||
|
||||
const menuItems = fixture.debugElement.queryAll(By.css('.app-toolbar-menu-item'));
|
||||
expect(menuItems.length).toBe(1);
|
||||
|
||||
const menuItemOne: HTMLSpanElement = (menuItems[0].nativeElement as HTMLButtonElement).querySelector('[data-automation-id="menu-item-title"]');
|
||||
const menuItemOne = (menuItems[0].nativeElement as HTMLButtonElement).querySelector<HTMLSpanElement>('[data-automation-id="menu-item-title"]');
|
||||
expect(menuItemOne.innerText).toBe('upload action one');
|
||||
});
|
||||
});
|
||||
|
@@ -135,7 +135,9 @@ export class SearchInputComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
onMenuOpened() {
|
||||
this.searchInputControl.searchInput.nativeElement.focus();
|
||||
if (this.searchInputControl) {
|
||||
this.searchInputControl.searchInput?.nativeElement?.focus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -25,7 +25,6 @@
|
||||
|
||||
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
import { SearchResultsComponent } from './search-results.component';
|
||||
import { AppTestingModule } from '../../../testing/app-testing.module';
|
||||
import { AppSearchResultsModule } from '../search-results.module';
|
||||
import { AppConfigService, CoreModule, TranslationService } from '@alfresco/adf-core';
|
||||
import { Store } from '@ngrx/store';
|
||||
@@ -34,7 +33,9 @@ import { Pagination, SearchRequest } from '@alfresco/js-api';
|
||||
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
import { AppTestingModule } from '../../../testing/app-testing.module';
|
||||
import { AppService } from '@alfresco/aca-shared';
|
||||
|
||||
describe('SearchComponent', () => {
|
||||
let component: SearchResultsComponent;
|
||||
@@ -50,8 +51,15 @@ describe('SearchComponent', () => {
|
||||
beforeEach(() => {
|
||||
params = new BehaviorSubject({ q: 'TYPE: "cm:folder" AND %28=cm: name: email OR cm: name: budget%29' });
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), CoreModule.forRoot(), AppTestingModule, AppSearchResultsModule],
|
||||
imports: [TranslateModule.forRoot(), AppTestingModule, CoreModule.forRoot(), AppSearchResultsModule],
|
||||
providers: [
|
||||
{
|
||||
provide: AppService,
|
||||
useValue: {
|
||||
appNavNarMode$: new BehaviorSubject('expanded'),
|
||||
toggleAppNavBar$: new Subject()
|
||||
}
|
||||
},
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
|
@@ -27,7 +27,8 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { SidenavComponent } from './sidenav.component';
|
||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||
import { AppExtensionService } from '@alfresco/aca-shared';
|
||||
import { AppExtensionService, AppService } from '@alfresco/aca-shared';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
|
||||
describe('SidenavComponent', () => {
|
||||
let fixture: ComponentFixture<SidenavComponent>;
|
||||
@@ -38,6 +39,15 @@ describe('SidenavComponent', () => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppTestingModule],
|
||||
declarations: [SidenavComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: AppService,
|
||||
useValue: {
|
||||
appNavNarMode$: new BehaviorSubject('expanded'),
|
||||
toggleAppNavBar$: new Subject()
|
||||
}
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
||||
|
@@ -6,12 +6,11 @@
|
||||
* agreement is prohibited.
|
||||
*/
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { AppConfigModule } from '@alfresco/adf-core';
|
||||
import { ViewProfileComponent } from './view-profile.component';
|
||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Router } from '@angular/router';
|
||||
import { ViewProfileModule } from './view-profile.module';
|
||||
|
||||
describe('ViewProfileComponent', () => {
|
||||
let fixture: ComponentFixture<ViewProfileComponent>;
|
||||
@@ -20,8 +19,7 @@ describe('ViewProfileComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppTestingModule, AppConfigModule, FormsModule, ReactiveFormsModule],
|
||||
declarations: [ViewProfileComponent]
|
||||
imports: [AppTestingModule, ViewProfileModule]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ViewProfileComponent);
|
||||
|
@@ -28,9 +28,10 @@ import { ViewProfileComponent } from './view-profile.component';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { CoreModule } from '@alfresco/adf-core';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule, CoreModule.forChild()],
|
||||
imports: [CommonModule, RouterModule, CoreModule.forChild(), MatDividerModule],
|
||||
declarations: [ViewProfileComponent]
|
||||
})
|
||||
export class ViewProfileModule {}
|
||||
|
Reference in New Issue
Block a user