ACS-8761 Noop Auth Module for unit testing ergonomics (#10195)

This commit is contained in:
Denys Vuika
2024-09-18 08:05:26 -04:00
committed by GitHub
parent 075c6891fe
commit 4d4a1dd6b1
69 changed files with 630 additions and 836 deletions

View File

@@ -27,7 +27,6 @@ import { AspectEntry, Node } from '@alfresco/js-api';
import { NodesApiService } from '../common/services/nodes-api.service';
import { By } from '@angular/platform-browser';
import { AspectListComponent } from './aspect-list.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
const aspectListMock: AspectEntry[] = [
{
@@ -114,7 +113,7 @@ describe('AspectListDialogComponent', () => {
excludedAspects: []
};
await TestBed.configureTestingModule({
imports: [HttpClientTestingModule, ContentTestingModule, MatDialogModule],
imports: [ContentTestingModule, MatDialogModule],
providers: [
{ provide: MAT_DIALOG_DATA, useValue: data },
{

View File

@@ -28,7 +28,6 @@ import { CategoryService } from '../../category';
providedIn: 'root'
})
export class DialogAspectListService {
constructor(
private dialog: MatDialog,
private overlayContainer: OverlayContainer,
@@ -49,8 +48,8 @@ export class DialogAspectListService {
select,
nodeId,
excludedAspects: [
...this.tagService.areTagsEnabled() ? [] : ['cm:taggable'],
...this.categoryService.areCategoriesEnabled() ? [] : ['cm:generalclassifiable']
...(this.tagService.areTagsEnabled() ? [] : ['cm:taggable']),
...(this.categoryService.areCategoriesEnabled() ? [] : ['cm:generalclassifiable'])
]
};
@@ -58,15 +57,17 @@ export class DialogAspectListService {
return select;
}
private openDialog(data: AspectListDialogComponentData, panelClass: string, width: string,
selectorAutoFocusedOnClose?: string) {
this.dialog.open(AspectListDialogComponent, {
data,
panelClass,
width,
role: 'dialog',
disableClose: true
}).afterClosed().subscribe(() => this.focusOnClose(selectorAutoFocusedOnClose));
private openDialog(data: AspectListDialogComponentData, panelClass: string, width: string, selectorAutoFocusedOnClose?: string) {
this.dialog
.open(AspectListDialogComponent, {
data,
panelClass,
width,
role: 'dialog',
disableClose: true
})
.afterClosed()
.subscribe(() => this.focusOnClose(selectorAutoFocusedOnClose));
this.overlayContainer.getContainerElement().setAttribute('role', 'main');
}
@@ -77,7 +78,7 @@ export class DialogAspectListService {
private focusOnClose(selectorAutoFocusedOnClose: string): void {
if (selectorAutoFocusedOnClose) {
document.querySelector<HTMLElement>(selectorAutoFocusedOnClose).focus();
document.querySelector<HTMLElement>(selectorAutoFocusedOnClose)?.focus();
}
}
}

View File

@@ -20,22 +20,17 @@ import { By } from '@angular/platform-browser';
import { Node } from '@alfresco/js-api';
import { ContentMetadataCardComponent } from './content-metadata-card.component';
import { ContentMetadataComponent } from '../content-metadata/content-metadata.component';
import { APP_INITIALIZER, SimpleChange } from '@angular/core';
import { SimpleChange } from '@angular/core';
import { NodeAspectService } from '../../../aspect-list/services/node-aspect.service';
import { ContentMetadataService } from '../../services/content-metadata.service';
import { AllowableOperationsEnum } from '../../../common/models/allowable-operations.enum';
import { of } from 'rxjs';
import { AuthModule, NoopTranslateModule } from '@alfresco/adf-core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { versionCompatibilityFactory } from '../../../version-compatibility/version-compatibility-factory';
import { VersionCompatibilityService } from '../../../version-compatibility';
import { MatDialogModule } from '@angular/material/dialog';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { CategoryService } from '../../../category';
import { TagService } from '../../../tag';
import { PropertyDescriptorsService } from '../../public-api';
import { AlfrescoApiService } from '../../../services/alfresco-api.service';
import { AlfrescoApiServiceMock } from '../../../mock/alfresco-api.service.mock';
import { ContentTestingModule } from '../../../testing/content.testing.module';
describe('ContentMetadataCardComponent', () => {
let component: ContentMetadataCardComponent;
@@ -52,23 +47,7 @@ describe('ContentMetadataCardComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
NoopTranslateModule,
AuthModule.forRoot({ useHash: true }),
MatDialogModule,
MatSnackBarModule,
ContentMetadataCardComponent
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{
provide: APP_INITIALIZER,
useFactory: versionCompatibilityFactory,
deps: [VersionCompatibilityService],
multi: true
}
]
imports: [ContentTestingModule, MatDialogModule, MatSnackBarModule, ContentMetadataCardComponent]
});
fixture = TestBed.createComponent(ContentMetadataCardComponent);
contentMetadataService = TestBed.inject(ContentMetadataService);

View File

@@ -21,22 +21,13 @@ import { By } from '@angular/platform-browser';
import { Category, CategoryPaging, ClassesApi, Node, Tag, TagBody, TagEntry, TagPaging, TagPagingList } from '@alfresco/js-api';
import { ContentMetadataComponent } from './content-metadata.component';
import { ContentMetadataService } from '../../services/content-metadata.service';
import {
AppConfigService,
AuthModule,
CardViewBaseItemModel,
CardViewComponent,
NoopTranslateModule,
NotificationService,
UpdateNotification
} from '@alfresco/adf-core';
import { AppConfigService, CardViewBaseItemModel, CardViewComponent, NotificationService, UpdateNotification } from '@alfresco/adf-core';
import { NodesApiService } from '../../../common/services/nodes-api.service';
import { EMPTY, of, throwError } from 'rxjs';
import { CardViewContentUpdateService } from '../../../common/services/card-view-content-update.service';
import { PropertyGroup } from '../../interfaces/property-group.interface';
import { PropertyDescriptorsService } from '../../services/property-descriptors.service';
import { MatExpansionPanel } from '@angular/material/expansion';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MatDialogModule } from '@angular/material/dialog';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
@@ -45,6 +36,7 @@ import { TagService } from '../../../tag/services/tag.service';
import { CategoryService } from '../../../category/services/category.service';
import { TagsCreatorComponent, TagsCreatorMode } from '../../../tag';
import { CategoriesManagementComponent, CategoriesManagementMode } from '../../../category';
import { ContentTestingModule } from '../../../testing/content.testing.module';
describe('ContentMetadataComponent', () => {
let component: ContentMetadataComponent;
@@ -176,14 +168,7 @@ describe('ContentMetadataComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
NoopTranslateModule,
AuthModule.forRoot({ useHash: true }),
MatDialogModule,
MatSnackBarModule,
ContentMetadataComponent
],
imports: [ContentTestingModule, MatDialogModule, MatSnackBarModule, ContentMetadataComponent],
providers: [
{
provide: TagService,

View File

@@ -17,16 +17,7 @@
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import {
CoreModule,
AppConfigService,
CookieService,
AppConfigServiceMock,
CookieServiceMock,
AuthModule,
NoopTranslateModule
} from '@alfresco/adf-core';
import { CoreModule, NoopTranslateModule, NoopAuthModule } from '@alfresco/adf-core';
import { ContentModule } from '../content.module';
import { versionCompatibilityFactory } from '../version-compatibility/version-compatibility-factory';
import { AlfrescoApiService } from '../services/alfresco-api.service';
@@ -35,19 +26,9 @@ import { MatIconTestingModule } from '@angular/material/icon/testing';
import { AlfrescoApiServiceMock } from '../mock';
@NgModule({
imports: [
AuthModule.forRoot({ useHash: true }),
NoopAnimationsModule,
RouterTestingModule,
CoreModule,
NoopTranslateModule,
ContentModule,
MatIconTestingModule
],
imports: [NoopAnimationsModule, CoreModule, NoopAuthModule, NoopTranslateModule, ContentModule, MatIconTestingModule],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: AppConfigService, useClass: AppConfigServiceMock },
{ provide: CookieService, useClass: CookieServiceMock },
{
provide: APP_INITIALIZER,
useFactory: versionCompatibilityFactory,

View File

@@ -21,29 +21,40 @@ import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testin
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { AppExtensionService, ViewerExtensionRef } from '@alfresco/adf-extensions';
import { ContentInfo, Node, NodeEntry, VersionEntry } from '@alfresco/js-api';
import { AlfrescoViewerComponent, ContentService, NodeActionsService, RenditionService } from '@alfresco/adf-content-services';
import {
AuthModule,
CloseButtonPosition,
EventMock,
ViewUtilService,
ViewerComponent,
VIEWER_DIRECTIVES,
ViewerSidebarComponent,
NoopTranslateModule
NoopTranslateModule,
ViewerToolbarComponent,
ViewerOpenWithComponent,
ViewerMoreActionsComponent,
ViewerToolbarActionsComponent,
NoopAuthModule
} from '@alfresco/adf-core';
import { NodesApiService } from '../../common/services/nodes-api.service';
import { UploadService } from '../../common/services/upload.service';
import { FileModel } from '../../common/models/file.model';
import { throwError } from 'rxjs';
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { Component } from '@angular/core';
import { ESCAPE } from '@angular/cdk/keycodes';
import { By } from '@angular/platform-browser';
import { AlfrescoApiService } from '../../services';
import { AlfrescoApiServiceMock } from '../../mock';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuModule } from '@angular/material/menu';
import { MatButtonModule } from '@angular/material/button';
import { AlfrescoViewerComponent } from './alfresco-viewer.component';
import { RenditionService } from '../../common/services/rendition.service';
import { NodeActionsService } from '../../document-list/services/node-actions.service';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { ContentService } from '../../common/services/content.service';
@Component({
selector: 'adf-viewer-container-toolbar',
standalone: true,
imports: [ViewerToolbarComponent, AlfrescoViewerComponent],
template: `
<adf-alfresco-viewer>
<adf-viewer-toolbar>
@@ -56,22 +67,24 @@ class ViewerWithCustomToolbarComponent {}
@Component({
selector: 'adf-viewer-container-toolbar-actions',
template: `
<adf-alfresco-viewer>
<adf-viewer-toolbar-actions>
<button mat-icon-button id="custom-button">
<mat-icon>alarm</mat-icon>
</button>
</adf-viewer-toolbar-actions>
</adf-alfresco-viewer>
`
standalone: true,
imports: [MatIconModule, MatButtonModule, ViewerToolbarActionsComponent, AlfrescoViewerComponent],
template: `<adf-alfresco-viewer>
<adf-viewer-toolbar-actions>
<button mat-icon-button id="custom-button">
<mat-icon>alarm</mat-icon>
</button>
</adf-viewer-toolbar-actions>
</adf-alfresco-viewer>`
})
class ViewerWithCustomToolbarActionsComponent {}
@Component({
selector: 'adf-viewer-container-sidebar',
standalone: true,
imports: [ViewerSidebarComponent, AlfrescoViewerComponent],
template: `
<adf-alfresco-viewer>
<adf-alfresco-viewer [allowRightSidebar]="true" [showRightSidebar]="true" [nodeId]="'1'">
<adf-viewer-sidebar>
<div class="custom-sidebar"></div>
</adf-viewer-sidebar>
@@ -88,6 +101,8 @@ class DummyDialogComponent {}
@Component({
selector: 'adf-viewer-container-open-with',
standalone: true,
imports: [MatIconModule, MatMenuModule, ViewerOpenWithComponent, AlfrescoViewerComponent],
template: `
<adf-alfresco-viewer>
<adf-viewer-open-with>
@@ -111,24 +126,24 @@ class ViewerWithCustomOpenWithComponent {}
@Component({
selector: 'adf-viewer-container-more-actions',
template: `
<adf-alfresco-viewer>
<adf-viewer-more-actions>
<button mat-menu-item>
<mat-icon>dialpad</mat-icon>
<span>Action One</span>
</button>
<button mat-menu-item [disabled]="true">
<mat-icon>voicemail</mat-icon>
<span>Action Two</span>
</button>
<button mat-menu-item>
<mat-icon>notifications_off</mat-icon>
<span>Action Three</span>
</button>
</adf-viewer-more-actions>
</adf-alfresco-viewer>
`
standalone: true,
imports: [MatIconModule, MatMenuModule, ViewerMoreActionsComponent, AlfrescoViewerComponent],
template: ` <adf-alfresco-viewer>
<adf-viewer-more-actions>
<button mat-menu-item>
<mat-icon>dialpad</mat-icon>
<span>Action One</span>
</button>
<button mat-menu-item [disabled]="true">
<mat-icon>voicemail</mat-icon>
<span>Action Two</span>
</button>
<button mat-menu-item>
<mat-icon>notifications_off</mat-icon>
<span>Action Three</span>
</button>
</adf-viewer-more-actions>
</adf-alfresco-viewer>`
})
class ViewerWithCustomMoreActionsComponent {}
@@ -147,8 +162,12 @@ describe('AlfrescoViewerComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AuthModule.forRoot({ useHash: true }), MatDialogModule, NoopTranslateModule, ...VIEWER_DIRECTIVES],
declarations: [
imports: [
ContentTestingModule,
NoopAuthModule,
MatDialogModule,
NoopTranslateModule,
...VIEWER_DIRECTIVES,
ViewerWithCustomToolbarComponent,
ViewerWithCustomSidebarComponent,
ViewerWithCustomOpenWithComponent,
@@ -157,19 +176,16 @@ describe('AlfrescoViewerComponent', () => {
],
providers: [
ContentService,
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{
provide: RenditionService,
useValue: {
getNodeRendition: () => throwError('thrown'),
getNodeRendition: () => throwError(() => new Error('thrown')),
generateMediaTracksRendition: () => {}
}
},
{ provide: Location, useClass: SpyLocation },
MatDialog,
ViewerSidebarComponent
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
MatDialog
]
});
fixture = TestBed.createComponent(AlfrescoViewerComponent);
element = fixture.nativeElement;
@@ -380,33 +396,39 @@ describe('AlfrescoViewerComponent', () => {
});
});
it('should stop propagation on sidebar keydown event [keydown]', fakeAsync(() => {
it('should stop propagation on sidebar keydown event [keydown]', async () => {
const customFixture = TestBed.createComponent(ViewerWithCustomSidebarComponent);
const customElement: HTMLElement = customFixture.nativeElement;
const escapeKeyboardEvent = new KeyboardEvent('keydown', { key: ESCAPE.toString() });
const stopPropagationSpy = spyOn(escapeKeyboardEvent, 'stopPropagation');
customFixture.detectChanges();
const viewerSidebarElement = customElement.querySelector('adf-viewer-sidebar');
await customFixture.whenStable();
const viewerSidebarElement = customElement.querySelector('.adf-viewer-sidebar');
viewerSidebarElement.dispatchEvent(escapeKeyboardEvent);
customFixture.detectChanges();
expect(stopPropagationSpy).toHaveBeenCalled();
}));
});
it('should stop propagation on sidebar keyup event [keyup]', fakeAsync(() => {
it('should stop propagation on sidebar keyup event [keyup]', async () => {
const customFixture = TestBed.createComponent(ViewerWithCustomSidebarComponent);
const customElement: HTMLElement = customFixture.nativeElement;
const escapeKeyboardEvent = new KeyboardEvent('keyup', { key: ESCAPE.toString() });
const stopPropagationSpy = spyOn(escapeKeyboardEvent, 'stopPropagation');
customFixture.detectChanges();
const viewerSidebarElement = customElement.querySelector('adf-viewer-sidebar');
await customFixture.whenStable();
const viewerSidebarElement = customElement.querySelector('.adf-viewer-sidebar');
viewerSidebarElement.dispatchEvent(escapeKeyboardEvent);
await customFixture.whenStable();
expect(stopPropagationSpy).toHaveBeenCalled();
}));
});
});
describe('error handling', () => {

View File

@@ -22,7 +22,7 @@ import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@ang
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
teardown: { destroyAfterEach: false }
teardown: { destroyAfterEach: true }
});
declare const pdfjsLib: any;