mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
ACS-8761 Noop Auth Module for unit testing ergonomics (#10195)
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { StorageFeaturesService } from './storage-features.service';
|
||||
import { CoreTestingModule, StorageService } from '../../../../src/public-api';
|
||||
import { StorageService } from '../../../../src/public-api';
|
||||
import { FlagSet, WritableFeaturesServiceConfigToken } from '../interfaces/features.interface';
|
||||
import { skip, take } from 'rxjs/operators';
|
||||
|
||||
@@ -41,7 +41,6 @@ describe('StorageFeaturesService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{ provide: StorageService, useValue: mockStorage },
|
||||
{
|
||||
@@ -49,8 +48,7 @@ describe('StorageFeaturesService', () => {
|
||||
useValue: {
|
||||
storageKey: 'storage-key-test'
|
||||
}
|
||||
},
|
||||
StorageFeaturesService
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
@@ -170,11 +168,6 @@ describe('StorageFeaturesService', () => {
|
||||
|
||||
describe('if flags are not present in LocalStorage and no configuration is provided', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
providers: [StorageFeaturesService]
|
||||
});
|
||||
|
||||
storageFeaturesService = TestBed.inject(StorageFeaturesService);
|
||||
});
|
||||
|
||||
|
@@ -30,7 +30,7 @@ import {
|
||||
import { FlagSetParser } from './flagset.parser';
|
||||
import { StorageService } from '@alfresco/adf-core';
|
||||
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class StorageFeaturesService implements IFeaturesService, IWritableFeaturesService {
|
||||
private currentFlagState: WritableFlagChangeset = {};
|
||||
private flags = new BehaviorSubject<WritableFlagChangeset>({});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { ObjectUtils } from '../common/utils/object-utils';
|
||||
import { Observable, ReplaySubject } from 'rxjs';
|
||||
import { map, distinctUntilChanged, take } from 'rxjs/operators';
|
||||
@@ -63,6 +63,9 @@ export enum Status {
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AppConfigService {
|
||||
protected http = inject(HttpClient);
|
||||
protected extensionService = inject(ExtensionService);
|
||||
|
||||
config: any = {
|
||||
application: {
|
||||
name: 'Alfresco ADF Application'
|
||||
@@ -80,11 +83,11 @@ export class AppConfigService {
|
||||
return this.status === Status.LOADED;
|
||||
}
|
||||
|
||||
constructor(protected http: HttpClient, protected extensionService: ExtensionService) {
|
||||
constructor() {
|
||||
this.onLoadSubject = new ReplaySubject();
|
||||
this.onLoad = this.onLoadSubject.asObservable();
|
||||
|
||||
extensionService.setup$.subscribe((config) => {
|
||||
this.extensionService.setup$.subscribe((config) => {
|
||||
this.onExtensionsLoaded(config);
|
||||
});
|
||||
}
|
||||
|
@@ -16,25 +16,23 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { StorageService } from '../common/services/storage.service';
|
||||
import { AppConfigService, AppConfigValues } from './app-config.service';
|
||||
import { ExtensionService } from '@alfresco/adf-extensions';
|
||||
|
||||
@Injectable()
|
||||
export class DebugAppConfigService extends AppConfigService {
|
||||
constructor(private storage: StorageService, http: HttpClient, extensionService: ExtensionService) {
|
||||
super(http, extensionService);
|
||||
constructor(private storage: StorageService) {
|
||||
super();
|
||||
}
|
||||
|
||||
/** @override */
|
||||
get<T>(key: string, defaultValue?: T): T {
|
||||
if (key === AppConfigValues.OAUTHCONFIG) {
|
||||
return (JSON.parse(this.storage.getItem(key)) || super.get<T>(key, defaultValue));
|
||||
return JSON.parse(this.storage.getItem(key)) || super.get<T>(key, defaultValue);
|
||||
} else if (key === AppConfigValues.APPLICATION) {
|
||||
return undefined;
|
||||
} else {
|
||||
return (this.storage.getItem(key) as any || super.get<T>(key, defaultValue));
|
||||
return (this.storage.getItem(key) as any) || super.get<T>(key, defaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatChipHarness, MatChipListboxHarness } from '@angular/material/chips/testing';
|
||||
import { MatButtonHarness } from '@angular/material/button/testing';
|
||||
import { MatIconHarness } from '@angular/material/icon/testing';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('CardViewArrayItemComponent', () => {
|
||||
let loader: HarnessLoader;
|
||||
@@ -51,7 +51,7 @@ describe('CardViewArrayItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, CardViewArrayItemComponent]
|
||||
imports: [NoopTranslateModule, CardViewArrayItemComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewArrayItemComponent);
|
||||
service = TestBed.inject(CardViewUpdateService);
|
||||
|
@@ -28,8 +28,7 @@ import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatChipHarness } from '@angular/material/chips/testing';
|
||||
import { addMinutes } from 'date-fns';
|
||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('CardViewDateItemComponent', () => {
|
||||
let loader: HarnessLoader;
|
||||
@@ -39,7 +38,7 @@ describe('CardViewDateItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, MatSnackBarModule, CardViewDateItemComponent]
|
||||
imports: [NoopTranslateModule, CardViewDateItemComponent]
|
||||
});
|
||||
appConfigService = TestBed.inject(AppConfigService);
|
||||
appConfigService.config.dateValues = {
|
||||
|
@@ -39,6 +39,8 @@ import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatChipsModule } from '@angular/material/chips';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
|
||||
@Component({
|
||||
providers: [
|
||||
@@ -49,7 +51,16 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
],
|
||||
selector: 'adf-card-view-dateitem',
|
||||
standalone: true,
|
||||
imports: [CommonModule, TranslateModule, MatIconModule, MatDatetimepickerModule, MatChipsModule, MatFormFieldModule],
|
||||
imports: [
|
||||
CommonModule,
|
||||
TranslateModule,
|
||||
MatIconModule,
|
||||
MatDatetimepickerModule,
|
||||
MatChipsModule,
|
||||
MatFormFieldModule,
|
||||
MatDatepickerModule,
|
||||
MatSnackBarModule
|
||||
],
|
||||
templateUrl: './card-view-dateitem.component.html',
|
||||
styleUrls: ['./card-view-dateitem.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
|
@@ -20,7 +20,7 @@ import { By } from '@angular/platform-browser';
|
||||
import { CardViewKeyValuePairsItemModel } from '../../models/card-view-keyvaluepairs.model';
|
||||
import { CardViewKeyValuePairsItemComponent } from './card-view-keyvaluepairsitem.component';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('CardViewKeyValuePairsItemComponent', () => {
|
||||
let fixture: ComponentFixture<CardViewKeyValuePairsItemComponent>;
|
||||
@@ -31,7 +31,7 @@ describe('CardViewKeyValuePairsItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, CardViewKeyValuePairsItemComponent]
|
||||
imports: [NoopTranslateModule, CardViewKeyValuePairsItemComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewKeyValuePairsItemComponent);
|
||||
cardViewUpdateService = TestBed.inject(CardViewUpdateService);
|
||||
|
@@ -21,7 +21,7 @@ import { By } from '@angular/platform-browser';
|
||||
import { CardViewMapItemModel } from '../../models/card-view-mapitem.model';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { CardViewMapItemComponent } from './card-view-mapitem.component';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('CardViewMapItemComponent', () => {
|
||||
let service: CardViewUpdateService;
|
||||
@@ -33,7 +33,7 @@ describe('CardViewMapItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, CardViewMapItemComponent]
|
||||
imports: [NoopTranslateModule, CardViewMapItemComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewMapItemComponent);
|
||||
service = TestBed.inject(CardViewUpdateService);
|
||||
|
@@ -25,7 +25,8 @@ import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatSelectHarness } from '@angular/material/select/testing';
|
||||
import { MatFormFieldHarness } from '@angular/material/form-field/testing';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
describe('CardViewSelectItemComponent', () => {
|
||||
let loader: HarnessLoader;
|
||||
@@ -59,7 +60,7 @@ describe('CardViewSelectItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, CardViewSelectItemComponent]
|
||||
imports: [NoopTranslateModule, NoopAnimationsModule, CardViewSelectItemComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewSelectItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -20,7 +20,6 @@ import { By } from '@angular/platform-browser';
|
||||
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
|
||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||
import { CardViewTextItemComponent } from './card-view-textitem.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { CardViewItemFloatValidator } from '../../validators/card-view-item-float.validator';
|
||||
import { CardViewItemIntValidator } from '../../validators/card-view-item-int.validator';
|
||||
import { CardViewIntItemModel } from '../../models/card-view-intitem.model';
|
||||
@@ -33,6 +32,8 @@ import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatChipHarness, MatChipGridHarness } from '@angular/material/chips/testing';
|
||||
import { MatInputHarness } from '@angular/material/input/testing';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
describe('CardViewTextItemComponent', () => {
|
||||
let loader: HarnessLoader;
|
||||
@@ -111,7 +112,7 @@ describe('CardViewTextItemComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, CardViewTextItemComponent]
|
||||
imports: [NoopTranslateModule, NoopAnimationsModule, CardViewTextItemComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(CardViewTextItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -30,6 +30,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
|
||||
export const DEFAULT_SEPARATOR = ', ';
|
||||
const templateTypes = {
|
||||
@@ -52,7 +53,8 @@ const templateTypes = {
|
||||
MatChipsModule,
|
||||
MatIconModule,
|
||||
FormsModule,
|
||||
MatButtonModule
|
||||
MatButtonModule,
|
||||
MatSnackBarModule
|
||||
],
|
||||
templateUrl: './card-view-textitem.component.html',
|
||||
styleUrls: ['./card-view-textitem.component.scss'],
|
||||
|
@@ -28,9 +28,10 @@ import { CardViewItemDispatcherComponent } from '../card-view-item-dispatcher/ca
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatSelectHarness } from '@angular/material/select/testing';
|
||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
import { MatDialogModule } from '@angular/material/dialog';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
|
||||
describe('CardViewComponent', () => {
|
||||
let loader: HarnessLoader;
|
||||
@@ -39,7 +40,7 @@ describe('CardViewComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, MatSnackBarModule, MatDialogModule, CardViewComponent]
|
||||
imports: [NoopTranslateModule, NoopAnimationsModule, MatSnackBarModule, MatDialogModule, CardViewComponent]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(CardViewComponent);
|
||||
|
@@ -73,8 +73,8 @@ export class CommentsComponent implements OnChanges {
|
||||
return;
|
||||
}
|
||||
|
||||
this.commentsService.get(this.id).subscribe(
|
||||
(comments: CommentModel[]) => {
|
||||
this.commentsService.get(this.id).subscribe({
|
||||
next: (comments) => {
|
||||
if (!this.isArrayInstance(comments)) {
|
||||
return;
|
||||
}
|
||||
@@ -82,10 +82,10 @@ export class CommentsComponent implements OnChanges {
|
||||
comments = this.sortedComments(comments);
|
||||
this.comments.push(...comments);
|
||||
},
|
||||
(err) => {
|
||||
error: (err) => {
|
||||
this.error.emit(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
addComment() {
|
||||
@@ -95,18 +95,18 @@ export class CommentsComponent implements OnChanges {
|
||||
|
||||
this.beingAdded = true;
|
||||
|
||||
this.commentsService.add(this.id, this.message).subscribe(
|
||||
(res: CommentModel) => {
|
||||
this.commentsService.add(this.id, this.message).subscribe({
|
||||
next: (res) => {
|
||||
this.addToComments(res);
|
||||
this.resetMessage();
|
||||
},
|
||||
(err) => {
|
||||
error: (err) => {
|
||||
this.error.emit(err);
|
||||
},
|
||||
() => {
|
||||
complete: () => {
|
||||
this.beingAdded = false;
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
clearMessage(event: Event): void {
|
||||
@@ -135,7 +135,7 @@ export class CommentsComponent implements OnChanges {
|
||||
}
|
||||
|
||||
private sortedComments(comments: CommentModel[]): CommentModel[] {
|
||||
return comments.sort((comment1: CommentModel, comment2: CommentModel) => {
|
||||
return comments.sort((comment1, comment2) => {
|
||||
const date1 = new Date(comment1.created);
|
||||
const date2 = new Date(comment2.created);
|
||||
|
||||
|
@@ -17,24 +17,21 @@
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AppConfigService, Status } from '../../app-config/app-config.service';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { ExtensionService } from '@alfresco/adf-extensions';
|
||||
|
||||
@Injectable()
|
||||
export class AppConfigServiceMock extends AppConfigService {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
config: any = {
|
||||
application: {
|
||||
name: 'Alfresco ADF Application',
|
||||
storagePrefix: 'ADF_APP'
|
||||
},
|
||||
ecmHost: 'http://{hostname}{:port}/ecm',
|
||||
bpmHost: 'http://{hostname}{:port}/bpm',
|
||||
logLevel: 'silent'
|
||||
};
|
||||
|
||||
constructor(http: HttpClient, extensionService: ExtensionService) {
|
||||
super(http, extensionService);
|
||||
this.config = {
|
||||
application: {
|
||||
name: 'Alfresco ADF Application',
|
||||
storagePrefix: 'ADF_APP'
|
||||
},
|
||||
ecmHost: 'http://{hostname}{:port}/ecm',
|
||||
bpmHost: 'http://{hostname}{:port}/bpm',
|
||||
logLevel: 'silent'
|
||||
};
|
||||
}
|
||||
|
||||
load(callback?: (...args: any[]) => any): Promise<any> {
|
||||
|
@@ -1,29 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DirectionalityConfigService } from './directionality-config.service';
|
||||
|
||||
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
||||
/**
|
||||
* Creates a factory for Angular modules
|
||||
*
|
||||
* @param directionalityConfigService service dependency
|
||||
* @returns a factory function
|
||||
*/
|
||||
export function directionalityConfigFactory(directionalityConfigService: DirectionalityConfigService) {
|
||||
return () => directionalityConfigService;
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
import { DirectionalityConfigService } from './directionality-config.service';
|
||||
import { directionalityConfigFactory } from './directionality-config-factory';
|
||||
import { APP_INITIALIZER } from '@angular/core';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('DirectionalityConfigService', () => {
|
||||
let userPreferencesService: UserPreferencesService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [NoopTranslateModule],
|
||||
providers: [
|
||||
UserPreferencesService,
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: directionalityConfigFactory,
|
||||
deps: [DirectionalityConfigService],
|
||||
multi: true
|
||||
}
|
||||
]
|
||||
});
|
||||
userPreferencesService = TestBed.inject(UserPreferencesService);
|
||||
});
|
||||
|
||||
it('should set document direction on textOrientation event to `rtl`', () => {
|
||||
userPreferencesService.set('textOrientation', 'rtl');
|
||||
expect(document.body.getAttribute('dir')).toBe('rtl');
|
||||
});
|
||||
|
||||
it('should set document direction on textOrientation event to `ltr`', () => {
|
||||
userPreferencesService.set('textOrientation', 'ltr');
|
||||
expect(document.body.getAttribute('dir')).toBe('ltr');
|
||||
});
|
||||
});
|
@@ -1,42 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable, Inject, Renderer2, RendererFactory2 } from '@angular/core';
|
||||
import { Directionality, Direction } from '@angular/cdk/bidi';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DirectionalityConfigService {
|
||||
constructor(
|
||||
@Inject(DOCUMENT) private document: any,
|
||||
private rendererFactory: RendererFactory2,
|
||||
private userPreferencesService: UserPreferencesService,
|
||||
private directionality: Directionality
|
||||
) {
|
||||
const renderer: Renderer2 = this.rendererFactory.createRenderer(null, null);
|
||||
|
||||
this.userPreferencesService
|
||||
.select('textOrientation')
|
||||
.subscribe((direction: Direction) => {
|
||||
renderer.setAttribute(this.document.body, 'dir', direction);
|
||||
(this.directionality as any).value = direction;
|
||||
});
|
||||
}
|
||||
}
|
@@ -18,9 +18,7 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { AppConfigService } from '../../app-config/app-config.service';
|
||||
import { StorageService } from '../../common/services/storage.service';
|
||||
import { CoreTestingModule } from '../../testing';
|
||||
import { RedirectAuthService } from '../../auth';
|
||||
import { EMPTY } from 'rxjs';
|
||||
import { NoopAuthModule, NoopTranslateModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('StorageService', () => {
|
||||
let storage: StorageService;
|
||||
@@ -31,48 +29,41 @@ describe('StorageService', () => {
|
||||
describe('with prefix', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
providers: [{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, init: () => [] } }]
|
||||
imports: [NoopTranslateModule, NoopAuthModule]
|
||||
});
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
storage = TestBed.inject(StorageService);
|
||||
});
|
||||
|
||||
it('should get the prefix for the storage from app config', (done) => {
|
||||
appConfig.load().then(() => {
|
||||
expect(storage.prefix).toBe('ADF_APP_');
|
||||
done();
|
||||
});
|
||||
it('should get the prefix for the storage from app config', async () => {
|
||||
await appConfig.load();
|
||||
expect(storage.prefix).toBe('ADF_APP_');
|
||||
});
|
||||
|
||||
it('should set a property with the prefix in the local storage', (done) => {
|
||||
appConfig.load().then(() => {
|
||||
storage.clear();
|
||||
storage.setItem(key, value);
|
||||
const storageKey = localStorage.key(0);
|
||||
expect(storageKey).toBe('ADF_APP_' + key);
|
||||
expect(localStorage.getItem(storageKey)).toBe(value);
|
||||
done();
|
||||
});
|
||||
it('should set a property with the prefix in the local storage', async () => {
|
||||
await appConfig.load();
|
||||
|
||||
storage.clear();
|
||||
storage.setItem(key, value);
|
||||
const storageKey = localStorage.key(0);
|
||||
expect(storageKey).toBe('ADF_APP_' + key);
|
||||
expect(localStorage.getItem(storageKey)).toBe(value);
|
||||
});
|
||||
|
||||
it('should be able to get a property from the local storage', (done) => {
|
||||
it('should be able to get a property from the local storage', async () => {
|
||||
storage.clear();
|
||||
|
||||
appConfig.load().then(() => {
|
||||
storage.setItem(key, value);
|
||||
await appConfig.load();
|
||||
storage.setItem(key, value);
|
||||
|
||||
expect(storage.getItem(key)).toBe(value);
|
||||
done();
|
||||
});
|
||||
expect(storage.getItem(key)).toBe(value);
|
||||
});
|
||||
});
|
||||
|
||||
describe('without prefix', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
providers: [{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, init: () => [] } }]
|
||||
imports: [NoopAuthModule]
|
||||
});
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
|
||||
@@ -84,20 +75,16 @@ describe('StorageService', () => {
|
||||
storage = TestBed.inject(StorageService);
|
||||
});
|
||||
|
||||
it('should set an empty prefix when the it is not defined in the app config', (done) => {
|
||||
appConfig.load().then(() => {
|
||||
expect(storage.prefix).toBe('');
|
||||
done();
|
||||
});
|
||||
it('should set an empty prefix when the it is not defined in the app config', async () => {
|
||||
await appConfig.load();
|
||||
expect(storage.prefix).toBe('');
|
||||
});
|
||||
|
||||
it('should set a property without a prefix in the local storage', (done) => {
|
||||
appConfig.load().then(() => {
|
||||
storage.setItem(key, value);
|
||||
it('should set a property without a prefix in the local storage', async () => {
|
||||
await appConfig.load();
|
||||
storage.setItem(key, value);
|
||||
|
||||
expect(localStorage.getItem(key)).toBe(value);
|
||||
done();
|
||||
});
|
||||
expect(localStorage.getItem(key)).toBe(value);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -33,9 +33,7 @@ describe('UserPreferencesService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [NoopTranslateModule],
|
||||
providers: [
|
||||
{ provide: AppConfigService, useClass: AppConfigServiceMock }
|
||||
]
|
||||
providers: [{ provide: AppConfigService, useClass: AppConfigServiceMock }]
|
||||
});
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
appConfig.config = {
|
||||
@@ -56,6 +54,16 @@ describe('UserPreferencesService', () => {
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
it('should set document direction on textOrientation event to `rtl`', () => {
|
||||
preferences.set('textOrientation', 'rtl');
|
||||
expect(document.body.getAttribute('dir')).toBe('rtl');
|
||||
});
|
||||
|
||||
it('should set document direction on textOrientation event to `ltr`', () => {
|
||||
preferences.set('textOrientation', 'ltr');
|
||||
expect(document.body.getAttribute('dir')).toBe('ltr');
|
||||
});
|
||||
|
||||
describe(' with pagination config', () => {
|
||||
it('should get default pagination from app config', (done) => {
|
||||
appConfig.config.pagination.size = 0;
|
||||
|
@@ -15,13 +15,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { inject, Injectable, RendererFactory2 } from '@angular/core';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Observable, BehaviorSubject } from 'rxjs';
|
||||
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||
import { LanguageItem } from './language-item.interface';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { Directionality, Direction } from '@angular/cdk/bidi';
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
export enum UserPreferenceValues {
|
||||
@@ -35,6 +37,9 @@ export enum UserPreferenceValues {
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserPreferencesService {
|
||||
private document = inject(DOCUMENT);
|
||||
private rendererFactory = inject(RendererFactory2);
|
||||
private directionality = inject(Directionality);
|
||||
|
||||
defaults = {
|
||||
paginationSize: 25,
|
||||
@@ -47,17 +52,20 @@ export class UserPreferencesService {
|
||||
private onChangeSubject: BehaviorSubject<any>;
|
||||
onChange: Observable<any>;
|
||||
|
||||
constructor(
|
||||
public translate: TranslateService,
|
||||
private appConfig: AppConfigService,
|
||||
private storage: StorageService
|
||||
) {
|
||||
constructor(public translate: TranslateService, private appConfig: AppConfigService, private storage: StorageService) {
|
||||
this.onChangeSubject = new BehaviorSubject(this.userPreferenceStatus);
|
||||
this.onChange = this.onChangeSubject.asObservable();
|
||||
|
||||
this.appConfig.onLoad.subscribe(() => {
|
||||
this.initUserPreferenceStatus();
|
||||
});
|
||||
|
||||
const renderer = this.rendererFactory.createRenderer(null, null);
|
||||
|
||||
this.select('textOrientation').subscribe((direction: Direction) => {
|
||||
renderer.setAttribute(this.document.body, 'dir', direction);
|
||||
(this.directionality as any).value = direction;
|
||||
});
|
||||
}
|
||||
|
||||
private initUserPreferenceStatus() {
|
||||
@@ -87,11 +95,10 @@ export class UserPreferencesService {
|
||||
* @returns Notification callback
|
||||
*/
|
||||
select<T = any>(property: string): Observable<T> {
|
||||
return this.onChange
|
||||
.pipe(
|
||||
map((userPreferenceStatus) => userPreferenceStatus[property]),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
return this.onChange.pipe(
|
||||
map((userPreferenceStatus) => userPreferenceStatus[property]),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,10 +127,7 @@ export class UserPreferencesService {
|
||||
if (!property) {
|
||||
return;
|
||||
}
|
||||
this.storage.setItem(
|
||||
this.getPropertyKey(property),
|
||||
value
|
||||
);
|
||||
this.storage.setItem(this.getPropertyKey(property), value);
|
||||
this.userPreferenceStatus[property] = value;
|
||||
this.onChangeSubject.next(this.userPreferenceStatus);
|
||||
}
|
||||
@@ -152,9 +156,7 @@ export class UserPreferencesService {
|
||||
if (!property) {
|
||||
return false;
|
||||
}
|
||||
return this.storage.hasItem(
|
||||
this.getPropertyKey(property)
|
||||
);
|
||||
return this.storage.hasItem(this.getPropertyKey(property));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,10 +245,12 @@ export class UserPreferencesService {
|
||||
}
|
||||
|
||||
private getLanguageByKey(key: string): LanguageItem {
|
||||
return (
|
||||
this.appConfig
|
||||
.get<Array<LanguageItem>>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY, [{ key: 'en' } as LanguageItem])
|
||||
.find((language) => key.includes(language.key)) || { key: 'en' } as LanguageItem
|
||||
);
|
||||
const defaultLanguage = { key: 'en' } as LanguageItem;
|
||||
|
||||
const registeredLanguages = this.appConfig.get<Array<LanguageItem>>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY);
|
||||
if (registeredLanguages && Array.isArray(registeredLanguages)) {
|
||||
return registeredLanguages.find((language) => key.includes(language.key)) || defaultLanguage;
|
||||
}
|
||||
return defaultLanguage;
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
import { Overlay } from '@angular/cdk/overlay';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { ContextMenuOverlayService } from './context-menu-overlay.service';
|
||||
import { Injector } from '@angular/core';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
@@ -35,7 +34,6 @@ describe('ContextMenuOverlayService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
providers: [Overlay]
|
||||
});
|
||||
overlay = TestBed.inject(Overlay);
|
||||
|
@@ -39,8 +39,6 @@ import { CORE_DIRECTIVES } from './directives/directive.module';
|
||||
import { CORE_PIPES } from './pipes/pipe.module';
|
||||
import { TranslationService } from './translation/translation.service';
|
||||
import { TranslateLoaderService } from './translation/translate-loader.service';
|
||||
import { directionalityConfigFactory } from './common/services/directionality-config-factory';
|
||||
import { DirectionalityConfigService } from './common/services/directionality-config.service';
|
||||
import { SEARCH_TEXT_INPUT_DIRECTIVES } from './search-text/search-text-input.module';
|
||||
import { AdfHttpClient } from '@alfresco/adf-core/api';
|
||||
import { AuthenticationInterceptor, Authentication } from '@alfresco/adf-core/auth';
|
||||
@@ -145,12 +143,6 @@ export class CoreModule {
|
||||
deps: [AppConfigService, StorageService, AdfHttpClient, StoragePrefixFactory],
|
||||
multi: true
|
||||
},
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: directionalityConfigFactory,
|
||||
deps: [DirectionalityConfigService],
|
||||
multi: true
|
||||
},
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: AuthenticationInterceptor, multi: true },
|
||||
{ provide: Authentication, useClass: AuthenticationService },
|
||||
{
|
||||
|
@@ -20,11 +20,11 @@ import { ColumnsSelectorComponent } from './columns-selector.component';
|
||||
import { DataColumn } from '../../data/data-column.model';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { MatMenuTrigger } from '@angular/material/menu';
|
||||
import { CoreTestingModule } from '../../../testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { MatCheckboxHarness } from '@angular/material/checkbox/testing';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('ColumnsSelectorComponent', () => {
|
||||
let fixture: ComponentFixture<ColumnsSelectorComponent>;
|
||||
@@ -40,8 +40,8 @@ describe('ColumnsSelectorComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, ColumnsSelectorComponent]
|
||||
}).compileComponents();
|
||||
imports: [NoopTranslateModule, ColumnsSelectorComponent]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ColumnsSelectorComponent);
|
||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||
|
@@ -17,14 +17,13 @@
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { EmptyListComponent } from './empty-list.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
|
||||
describe('EmptyListComponentComponent', () => {
|
||||
let fixture: ComponentFixture<EmptyListComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule]
|
||||
imports: [EmptyListComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(EmptyListComponent);
|
||||
});
|
||||
|
@@ -18,7 +18,6 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ObjectDataTableAdapter } from '../../data/object-datatable-adapter';
|
||||
import { ObjectDataColumn } from '../../data/object-datacolumn.model';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { JsonCellComponent } from './json-cell.component';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
@@ -34,7 +33,7 @@ describe('JsonCellComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule]
|
||||
imports: [JsonCellComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(JsonCellComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation, Input } from '@angular/core';
|
||||
import { DataTableCellComponent } from '../datatable-cell/datatable-cell.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import { EditJsonDialogComponent, EditJsonDialogSettings } from '../../../dialogs/edit-json/edit-json.dialog';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
@@ -25,7 +25,7 @@ import { MatButtonModule } from '@angular/material/button';
|
||||
@Component({
|
||||
selector: 'adf-json-cell',
|
||||
standalone: true,
|
||||
imports: [CommonModule, MatButtonModule],
|
||||
imports: [CommonModule, MatButtonModule, MatDialogModule],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
template: `
|
||||
<ng-container *ngIf="value$ | async as value; else editEmpty">
|
||||
|
@@ -19,7 +19,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ObjectDataTableAdapter } from '../../data/object-datatable-adapter';
|
||||
import { ObjectDataColumn } from '../../data/object-datacolumn.model';
|
||||
import { LocationCellComponent } from './location-cell.component';
|
||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
describe('LocationCellComponent', () => {
|
||||
let component: LocationCellComponent;
|
||||
@@ -30,10 +30,7 @@ describe('LocationCellComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
LocationCellComponent,
|
||||
CoreTestingModule
|
||||
]
|
||||
imports: [RouterTestingModule, LocationCellComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(LocationCellComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -52,12 +49,9 @@ describe('LocationCellComponent', () => {
|
||||
}
|
||||
};
|
||||
|
||||
columnData = { format: '/files', type: 'location', key: 'path'};
|
||||
columnData = { format: '/files', type: 'location', key: 'path' };
|
||||
|
||||
dataTableAdapter = new ObjectDataTableAdapter(
|
||||
[rowData],
|
||||
[ new ObjectDataColumn(columnData) ]
|
||||
);
|
||||
dataTableAdapter = new ObjectDataTableAdapter([rowData], [new ObjectDataColumn(columnData)]);
|
||||
|
||||
component.link = [];
|
||||
component.column = dataTableAdapter.getColumns()[0];
|
||||
@@ -78,7 +72,7 @@ describe('LocationCellComponent', () => {
|
||||
it('should set router link', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.link).toEqual([ columnData.format , rowData.path.elements[2].id ]);
|
||||
expect(component.link).toEqual([columnData.format, rowData.path.elements[2].id]);
|
||||
});
|
||||
|
||||
it('should NOT set router link when format NOT provided', () => {
|
||||
@@ -99,7 +93,7 @@ describe('LocationCellComponent', () => {
|
||||
expect(value).toBe('');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not setup cell when path is missing required properties', (done) => {
|
||||
rowData.path = { someProp: '' };
|
||||
|
@@ -16,16 +16,8 @@
|
||||
*/
|
||||
|
||||
import { DataColumnComponent } from './data-column.component';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
describe('DataColumnListComponent', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule]
|
||||
});
|
||||
});
|
||||
|
||||
it('should setup screen reader title for thumbnails', () => {
|
||||
const component = new DataColumnComponent();
|
||||
component.key = '$thumbnail';
|
||||
|
@@ -18,7 +18,6 @@
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { DataTableComponent } from '../components/datatable/datatable.component';
|
||||
import { LoadingContentTemplateDirective } from './loading-template.directive';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
|
||||
describe('LoadingContentTemplateDirective', () => {
|
||||
let fixture: ComponentFixture<DataTableComponent>;
|
||||
@@ -27,7 +26,7 @@ describe('LoadingContentTemplateDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule]
|
||||
imports: [DataTableComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(DataTableComponent);
|
||||
dataTable = fixture.componentInstance;
|
||||
|
@@ -18,7 +18,6 @@
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { DataTableComponent } from '../components/datatable/datatable.component';
|
||||
import { NoContentTemplateDirective } from './no-content-template.directive';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
|
||||
describe('NoContentTemplateDirective', () => {
|
||||
let fixture: ComponentFixture<DataTableComponent>;
|
||||
@@ -27,7 +26,7 @@ describe('NoContentTemplateDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule]
|
||||
imports: [DataTableComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(DataTableComponent);
|
||||
dataTable = fixture.componentInstance;
|
||||
|
@@ -16,16 +16,17 @@
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CoreTestingModule, UnsavedChangesDialogComponent, UnsavedChangesGuard } from '@alfresco/adf-core';
|
||||
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
|
||||
import { MatDialog, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { UnsavedChangesDialogComponent } from './unsaved-changes-dialog.component';
|
||||
import { UnsavedChangesGuard } from './unsaved-changes.guard';
|
||||
|
||||
describe('UnsavedChangesGuard', () => {
|
||||
let guard: UnsavedChangesGuard;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule]
|
||||
imports: [MatDialogModule]
|
||||
});
|
||||
guard = TestBed.inject(UnsavedChangesGuard);
|
||||
});
|
||||
|
@@ -20,21 +20,22 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { HighlightTransformService } from '../common/services/highlight-transform.service';
|
||||
import { HighlightDirective } from './highlight.directive';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
|
||||
/* spellchecker: disable */
|
||||
const template: string = `
|
||||
<div id="outerDiv1" adf-highlight adf-highlight-selector=".highlightable" adf-highlight-class="highlight-for-free-willy">
|
||||
<div id="innerDiv11" class="highlightable">Lorem ipsum salana-eyong-aysis dolor sit amet</div>
|
||||
<div id="innerDiv12">Lorem ipsum salana-eyong-aysis dolor sit amet</div>
|
||||
<div id="innerDiv13" class="highlightable">consectetur adipiscing elit</div>
|
||||
<div id="innerDiv14" class="highlightable">sed do eiusmod salana-eyong-aysis tempor incididunt</div>
|
||||
</div>
|
||||
<div id="outerDiv2" adf-highlight adf-highlight-selector=".highlightable">
|
||||
<div id="innerDiv21" class="highlightable">Lorem ipsum salana-eyong-aysis dolor sit amet</div>
|
||||
</div>`;
|
||||
|
||||
@Component({ selector: 'adf-test-component', template })
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
standalone: true,
|
||||
imports: [HighlightDirective],
|
||||
template: ` <div id="outerDiv1" adf-highlight adf-highlight-selector=".highlightable" adf-highlight-class="highlight-for-free-willy">
|
||||
<div id="innerDiv11" class="highlightable">Lorem ipsum salana-eyong-aysis dolor sit amet</div>
|
||||
<div id="innerDiv12">Lorem ipsum salana-eyong-aysis dolor sit amet</div>
|
||||
<div id="innerDiv13" class="highlightable">consectetur adipiscing elit</div>
|
||||
<div id="innerDiv14" class="highlightable">sed do eiusmod salana-eyong-aysis tempor incididunt</div>
|
||||
</div>
|
||||
<div id="outerDiv2" adf-highlight adf-highlight-selector=".highlightable">
|
||||
<div id="innerDiv21" class="highlightable">Lorem ipsum salana-eyong-aysis dolor sit amet</div>
|
||||
</div>`
|
||||
})
|
||||
class TestComponent {
|
||||
@ViewChildren(HighlightDirective) public highlightDirectives;
|
||||
}
|
||||
@@ -45,8 +46,7 @@ describe('HighlightDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
imports: [TestComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -22,12 +22,14 @@ import { of, throwError } from 'rxjs';
|
||||
import { AuthenticationService } from '../auth/services/authentication.service';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { LogoutDirective } from './logout.directive';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { NoopAuthModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('LogoutDirective', () => {
|
||||
describe('No input', () => {
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
standalone: true,
|
||||
imports: [LogoutDirective],
|
||||
template: '<button adf-logout></button>'
|
||||
})
|
||||
class TestComponent {
|
||||
@@ -42,8 +44,7 @@ describe('LogoutDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
imports: [NoopAuthModule, TestComponent]
|
||||
});
|
||||
router = TestBed.inject(Router);
|
||||
authService = TestBed.inject(AuthenticationService);
|
||||
@@ -104,6 +105,8 @@ describe('LogoutDirective', () => {
|
||||
describe('redirectUri', () => {
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
standalone: true,
|
||||
imports: [LogoutDirective],
|
||||
template: '<button adf-logout redirectUri="/myCustomUri"></button>'
|
||||
})
|
||||
class TestComponent {
|
||||
@@ -117,8 +120,7 @@ describe('LogoutDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
imports: [NoopAuthModule, TestComponent]
|
||||
});
|
||||
router = TestBed.inject(Router);
|
||||
authService = TestBed.inject(AuthenticationService);
|
||||
@@ -141,6 +143,8 @@ describe('LogoutDirective', () => {
|
||||
describe('enableRedirect', () => {
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
standalone: true,
|
||||
imports: [LogoutDirective],
|
||||
template: '<button adf-logout [enableRedirect]="false"></button>'
|
||||
})
|
||||
class TestComponent {
|
||||
@@ -154,8 +158,7 @@ describe('LogoutDirective', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
imports: [NoopAuthModule, TestComponent]
|
||||
});
|
||||
router = TestBed.inject(Router);
|
||||
authService = TestBed.inject(AuthenticationService);
|
||||
|
@@ -19,27 +19,23 @@ import { Component } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatTabChangeEvent } from '@angular/material/tabs';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { InfoDrawerComponent } from './info-drawer.component';
|
||||
import { of } from 'rxjs';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { InfoDrawerComponent, InfoDrawerTabComponent } from './info-drawer.component';
|
||||
import { ESCAPE } from '@angular/cdk/keycodes';
|
||||
import { HarnessLoader } from '@angular/cdk/testing';
|
||||
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||
import { MatTabGroupHarness } from '@angular/material/tabs/testing';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
describe('InfoDrawerComponent', () => {
|
||||
let element: HTMLElement;
|
||||
let component: InfoDrawerComponent;
|
||||
let translateService: TranslateService;
|
||||
let fixture: ComponentFixture<InfoDrawerComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule]
|
||||
imports: [NoopTranslateModule, InfoDrawerComponent]
|
||||
});
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
spyOn(translateService, 'get').and.callFake((key) => of(key));
|
||||
|
||||
fixture = TestBed.createComponent(InfoDrawerComponent);
|
||||
element = fixture.nativeElement;
|
||||
@@ -86,6 +82,8 @@ describe('InfoDrawerComponent', () => {
|
||||
});
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [InfoDrawerTabComponent, InfoDrawerComponent],
|
||||
template: `
|
||||
<adf-info-drawer [selectedIndex]="tabIndex" [icon]="icon" title="Fake Title Custom">
|
||||
<adf-info-drawer-tab label="Tab1"></adf-info-drawer-tab>
|
||||
@@ -102,18 +100,14 @@ class CustomInfoDrawerComponent extends InfoDrawerComponent {
|
||||
describe('Custom InfoDrawer', () => {
|
||||
let fixture: ComponentFixture<CustomInfoDrawerComponent>;
|
||||
let component: CustomInfoDrawerComponent;
|
||||
let translateService: TranslateService;
|
||||
let loader: HarnessLoader;
|
||||
|
||||
const getNodeIcon = () => fixture.debugElement.queryAll(By.css('[info-drawer-node-icon]'));
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [CustomInfoDrawerComponent]
|
||||
imports: [NoopAnimationsModule, NoopTranslateModule, CustomInfoDrawerComponent]
|
||||
});
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
spyOn(translateService, 'get').and.callFake((key) => of(key));
|
||||
|
||||
fixture = TestBed.createComponent(CustomInfoDrawerComponent);
|
||||
fixture.detectChanges();
|
||||
@@ -170,6 +164,8 @@ describe('Custom InfoDrawer', () => {
|
||||
});
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [InfoDrawerComponent],
|
||||
template: ` <adf-info-drawer [showHeader]="showHeader" [icon]="icon" title="Fake Visibility Info Drawer Title"> </adf-info-drawer> `
|
||||
})
|
||||
class VisibilityInfoDrawerComponent extends InfoDrawerComponent {
|
||||
@@ -184,8 +180,7 @@ describe('Header visibility InfoDrawer', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [VisibilityInfoDrawerComponent]
|
||||
imports: [NoopTranslateModule, VisibilityInfoDrawerComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(VisibilityInfoDrawerComponent);
|
||||
fixture.detectChanges();
|
||||
|
@@ -16,21 +16,20 @@
|
||||
*/
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatIcon, MatIconModule } from '@angular/material/icon';
|
||||
import { MAT_SNACK_BAR_DATA, MatSnackBarModule, MatSnackBarRef } from '@angular/material/snack-bar';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIcon } from '@angular/material/icon';
|
||||
import { MAT_SNACK_BAR_DATA, MatSnackBarRef } from '@angular/material/snack-bar';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { SnackbarContentComponent } from './snackbar-content.component';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { CoreTestingModule, NoopTranslateModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('SnackbarContentComponent', () => {
|
||||
let component: SnackbarContentComponent;
|
||||
let fixture: ComponentFixture<SnackbarContentComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SnackbarContentComponent],
|
||||
imports: [CoreTestingModule, MatIconModule, MatSnackBarModule, MatButtonModule],
|
||||
imports: [NoopTranslateModule, CoreTestingModule],
|
||||
providers: [
|
||||
{
|
||||
provide: MatSnackBarRef,
|
||||
@@ -43,7 +42,7 @@ describe('SnackbarContentComponent', () => {
|
||||
useValue: {}
|
||||
}
|
||||
]
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(SnackbarContentComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
@@ -20,10 +20,13 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { of } from 'rxjs';
|
||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
||||
import { NoopTranslateModule } from '../../testing/noop-translate.module';
|
||||
import { EmptyContentComponent } from './empty-content.component';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
standalone: true,
|
||||
imports: [EmptyContentComponent],
|
||||
template: `
|
||||
<adf-empty-content icon="delete" [title]="'CUSTOM_TITLE'" [subtitle]="'CUSTOM_SUBTITLE'">
|
||||
<div class="adf-empty-content__text">SUBTITLE-1</div>
|
||||
@@ -40,8 +43,7 @@ describe('EmptyContentComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestComponent]
|
||||
imports: [NoopTranslateModule, TestComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
translateService = TestBed.inject(TranslateService);
|
||||
@@ -52,8 +54,8 @@ describe('EmptyContentComponent', () => {
|
||||
await fixture.whenStable();
|
||||
|
||||
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
|
||||
expect(title).toBeDefined('title element not found');
|
||||
expect(title.nativeElement.textContent).toContain('CUSTOM_TITLE', 'incorrect title value');
|
||||
expect(title).toBeDefined();
|
||||
expect(title.nativeElement.textContent).toContain('CUSTOM_TITLE');
|
||||
});
|
||||
|
||||
it('should translate title and subtitle', async () => {
|
||||
@@ -74,19 +76,19 @@ describe('EmptyContentComponent', () => {
|
||||
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
|
||||
const subtitle = fixture.debugElement.query(By.css('.adf-empty-content__subtitle'));
|
||||
|
||||
expect(title).toBeDefined('title element not found');
|
||||
expect(title.nativeElement.textContent).toContain('ENG_CUSTOM_TITLE', 'incorrect title value');
|
||||
expect(title).toBeDefined();
|
||||
expect(title.nativeElement.textContent).toContain('ENG_CUSTOM_TITLE');
|
||||
|
||||
expect(subtitle).toBeDefined('subtitle element not found');
|
||||
expect(subtitle.nativeElement.textContent).toContain('ENG_CUSTOM_SUBTITLE', 'incorrect subtitle value');
|
||||
expect(subtitle).toBeDefined();
|
||||
expect(subtitle.nativeElement.textContent).toContain('ENG_CUSTOM_SUBTITLE');
|
||||
});
|
||||
|
||||
it('should render multiple subtitle elements', () => {
|
||||
const subTitles = fixture.debugElement.queryAll(By.css('.adf-empty-content__text'));
|
||||
|
||||
expect(subTitles.length).toBe(3);
|
||||
expect(subTitles[0].nativeElement.textContent).toContain('SUBTITLE-1', 'missing SUBTITLE-1');
|
||||
expect(subTitles[1].nativeElement.textContent).toContain('SUBTITLE-2', 'missing SUBTITLE-2');
|
||||
expect(subTitles[2].nativeElement.textContent).toContain('SUBTITLE-3', 'missing SUBTITLE-3');
|
||||
expect(subTitles[0].nativeElement.textContent).toContain('SUBTITLE-1');
|
||||
expect(subTitles[1].nativeElement.textContent).toContain('SUBTITLE-2');
|
||||
expect(subTitles[2].nativeElement.textContent).toContain('SUBTITLE-3');
|
||||
});
|
||||
});
|
||||
|
@@ -15,45 +15,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NgModule, APP_INITIALIZER } from '@angular/core';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { CoreModule } from '../core.module';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { AppConfigServiceMock } from '../common/mock/app-config.service.mock';
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { CookieService } from '../common/services/cookie.service';
|
||||
import { CookieServiceMock } from '../mock/cookie.service.mock';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { directionalityConfigFactory } from '../common/services/directionality-config-factory';
|
||||
import { DirectionalityConfigService } from '../common/services/directionality-config.service';
|
||||
import { AuthModule, RedirectAuthService } from '../auth';
|
||||
import { EMPTY, of } from 'rxjs';
|
||||
import { NoopTranslateModule } from './noop-translate.module';
|
||||
import { UserPreferencesService } from '../common/services/user-preferences.service';
|
||||
import { NoopAuthModule } from './noop-auth.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
AuthModule.forRoot({ useHash: true }),
|
||||
NoopAnimationsModule,
|
||||
RouterTestingModule,
|
||||
HttpClientModule,
|
||||
CoreModule.forRoot(),
|
||||
NoopTranslateModule
|
||||
],
|
||||
providers: [
|
||||
DatePipe,
|
||||
UserPreferencesService,
|
||||
{ provide: AppConfigService, useClass: AppConfigServiceMock },
|
||||
{ provide: CookieService, useClass: CookieServiceMock },
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: directionalityConfigFactory,
|
||||
deps: [DirectionalityConfigService],
|
||||
multi: true
|
||||
},
|
||||
{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, init: () => {}, onTokenReceived: of() } }
|
||||
],
|
||||
exports: [NoopAnimationsModule, CoreModule, RouterTestingModule]
|
||||
imports: [NoopAnimationsModule, CoreModule.forRoot(), NoopTranslateModule, NoopAuthModule]
|
||||
})
|
||||
export class CoreTestingModule {}
|
||||
|
@@ -18,3 +18,4 @@
|
||||
export * from './core.testing.module';
|
||||
export * from './core.story.module';
|
||||
export * from './noop-translate.module';
|
||||
export * from './noop-auth.module';
|
||||
|
53
lib/core/src/lib/testing/noop-auth.module.ts
Normal file
53
lib/core/src/lib/testing/noop-auth.module.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { APP_INITIALIZER, Injectable, NgModule } from '@angular/core';
|
||||
import { AuthModule, RedirectAuthService } from '../auth';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { AppConfigService, StoragePrefixFactory } from '../app-config';
|
||||
import { AppConfigServiceMock, CookieService, StorageService } from '../common';
|
||||
import { CookieServiceMock } from '../mock';
|
||||
import { EMPTY, of } from 'rxjs';
|
||||
import { loadAppConfig } from '../app-config/app-config.loader';
|
||||
import { AdfHttpClient } from '@alfresco/adf-core/api';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class NoopRedirectAuthService extends RedirectAuthService {
|
||||
onLogin = EMPTY;
|
||||
onTokenReceived = of();
|
||||
|
||||
init(): Promise<boolean> {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
imports: [AuthModule.forRoot({ useHash: true }), HttpClientTestingModule, RouterTestingModule],
|
||||
providers: [
|
||||
{ provide: AppConfigService, useClass: AppConfigServiceMock },
|
||||
{ provide: CookieService, useClass: CookieServiceMock },
|
||||
{ provide: RedirectAuthService, useClass: NoopRedirectAuthService },
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: loadAppConfig,
|
||||
deps: [AppConfigService, StorageService, AdfHttpClient, StoragePrefixFactory],
|
||||
multi: true
|
||||
}
|
||||
]
|
||||
})
|
||||
export class NoopAuthModule {}
|
@@ -15,13 +15,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { EventEmitter, NgModule } from '@angular/core';
|
||||
import { EventEmitter, Injectable, NgModule } from '@angular/core';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { TranslationService } from '../translation/translation.service';
|
||||
import { LangChangeEvent } from '../mock';
|
||||
import { Observable, of } from 'rxjs';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class NoopTranslationService implements TranslationService {
|
||||
defaultLang: string = 'en';
|
||||
userLang: string;
|
||||
|
@@ -16,16 +16,15 @@
|
||||
*/
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { ToolbarComponent } from './toolbar.component';
|
||||
import { TOOLBAR_DIRECTIVES } from './toolbar.module';
|
||||
import { NoopTranslateModule } from '@alfresco/adf-core';
|
||||
|
||||
describe('ToolbarComponent', () => {
|
||||
let fixture: ComponentFixture<ToolbarComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, ...TOOLBAR_DIRECTIVES]
|
||||
imports: [NoopTranslateModule, ToolbarComponent]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(ToolbarComponent);
|
||||
|
@@ -19,11 +19,12 @@ import { Component } from '@angular/core';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { ViewerComponent } from '../viewer.component';
|
||||
import { ViewerMoreActionsComponent } from '../viewer-more-actions.component';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-viewer-container-more-actions',
|
||||
standalone: true,
|
||||
imports: [ViewerComponent, MatIconModule, MatMenuModule],
|
||||
imports: [ViewerComponent, MatIconModule, MatMenuModule, ViewerMoreActionsComponent],
|
||||
template: `
|
||||
<adf-viewer>
|
||||
<adf-viewer-more-actions>
|
||||
@@ -31,7 +32,7 @@ import { ViewerComponent } from '../viewer.component';
|
||||
<mat-icon>dialpad</mat-icon>
|
||||
<span>Action One</span>
|
||||
</button>
|
||||
<button mat-menu-item disabled>
|
||||
<button mat-menu-item [disabled]="true">
|
||||
<mat-icon>voicemail</mat-icon>
|
||||
<span>Action Two</span>
|
||||
</button>
|
||||
|
@@ -19,11 +19,12 @@ import { Component } from '@angular/core';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { ViewerComponent } from '../viewer.component';
|
||||
import { ViewerOpenWithComponent } from '../viewer-open-with.component';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-viewer-container-open-with',
|
||||
standalone: true,
|
||||
imports: [ViewerComponent, MatIconModule, MatMenuModule],
|
||||
imports: [ViewerComponent, MatIconModule, MatMenuModule, ViewerOpenWithComponent],
|
||||
template: `
|
||||
<adf-viewer>
|
||||
<adf-viewer-open-with>
|
||||
@@ -31,7 +32,7 @@ import { ViewerComponent } from '../viewer.component';
|
||||
<mat-icon>dialpad</mat-icon>
|
||||
<span>Option 1</span>
|
||||
</button>
|
||||
<button mat-menu-item disabled>
|
||||
<button mat-menu-item [disabled]="true">
|
||||
<mat-icon>voicemail</mat-icon>
|
||||
<span>Option 2</span>
|
||||
</button>
|
||||
|
@@ -17,11 +17,12 @@
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
import { ViewerComponent } from '../viewer.component';
|
||||
import { ViewerSidebarComponent } from '../viewer-sidebar.component';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-viewer-container-sidebar',
|
||||
standalone: true,
|
||||
imports: [ViewerComponent],
|
||||
imports: [ViewerComponent, ViewerSidebarComponent],
|
||||
template: `
|
||||
<adf-viewer>
|
||||
<adf-viewer-sidebar>
|
||||
|
@@ -19,11 +19,12 @@ import { Component } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { ViewerComponent } from '../viewer.component';
|
||||
import { ViewerToolbarActionsComponent } from '../viewer-toolbar-actions.component';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-viewer-container-toolbar-actions',
|
||||
standalone: true,
|
||||
imports: [ViewerComponent, MatIconModule, MatButtonModule],
|
||||
imports: [ViewerComponent, MatIconModule, MatButtonModule, ViewerToolbarActionsComponent],
|
||||
template: `
|
||||
<adf-viewer>
|
||||
<adf-viewer-toolbar-actions>
|
||||
|
@@ -17,11 +17,12 @@
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
import { ViewerComponent } from '../viewer.component';
|
||||
import { ViewerToolbarComponent } from '../viewer-toolbar.component';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-viewer-container-toolbar',
|
||||
standalone: true,
|
||||
imports: [ViewerComponent],
|
||||
imports: [ViewerComponent, ViewerToolbarComponent],
|
||||
template: `
|
||||
<adf-viewer>
|
||||
<adf-viewer-toolbar>
|
||||
|
@@ -33,11 +33,14 @@ declare const pdfjsLib: any;
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-dialog-component',
|
||||
standalone: true,
|
||||
template: ''
|
||||
})
|
||||
class TestDialogComponent {}
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [PdfViewerComponent],
|
||||
template: ` <adf-pdf-viewer [allowThumbnails]="true" [showToolbar]="true" [urlFile]="urlFile"></adf-pdf-viewer> `
|
||||
})
|
||||
class UrlTestComponent {
|
||||
@@ -52,6 +55,8 @@ class UrlTestComponent {
|
||||
}
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [PdfViewerComponent],
|
||||
template: ` <adf-pdf-viewer [allowThumbnails]="true" [showToolbar]="true" [urlFile]="urlFile"></adf-pdf-viewer> `
|
||||
})
|
||||
class UrlTestPasswordComponent {
|
||||
@@ -66,6 +71,8 @@ class UrlTestPasswordComponent {
|
||||
}
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [PdfViewerComponent],
|
||||
template: ` <adf-pdf-viewer [allowThumbnails]="true" [showToolbar]="true" [blobFile]="blobFile"></adf-pdf-viewer> `
|
||||
})
|
||||
class BlobTestComponent {
|
||||
@@ -105,10 +112,9 @@ describe('Test PdfViewer component', () => {
|
||||
let change: any;
|
||||
let dialog: MatDialog;
|
||||
|
||||
beforeEach((done) => {
|
||||
beforeEach(async () => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule],
|
||||
declarations: [TestDialogComponent, UrlTestComponent, UrlTestPasswordComponent, BlobTestComponent],
|
||||
imports: [CoreTestingModule, UrlTestComponent, TestDialogComponent, UrlTestPasswordComponent, BlobTestComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: MatDialog,
|
||||
@@ -129,9 +135,7 @@ describe('Test PdfViewer component', () => {
|
||||
component.inputPage('1');
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
done();
|
||||
});
|
||||
await fixture.whenStable();
|
||||
});
|
||||
|
||||
describe('User interaction', () => {
|
||||
@@ -371,28 +375,6 @@ describe('Test PdfViewer component', () => {
|
||||
});
|
||||
});
|
||||
}, 55000);
|
||||
|
||||
it('should check if page fits to documentContainer', (done) => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent, 'checkPageFitInContainer');
|
||||
componentUrlTestComponent.pdfViewerComponent.scalePage('auto');
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.checkPageFitInContainer).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should check if document has overflow', (done) => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent, 'setScaleUpdatePages');
|
||||
componentUrlTestComponent.pdfViewerComponent.scalePage('auto');
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.setScaleUpdatePages).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -425,14 +407,13 @@ describe('Test PdfViewer component', () => {
|
||||
document.body.removeChild(elementUrlTestComponent);
|
||||
});
|
||||
|
||||
it('should use the custom zoom if it is present in the app.config', (done) => {
|
||||
it('should use the custom zoom if it is present in the app.config', async () => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScale).toBe(0.8);
|
||||
done();
|
||||
});
|
||||
await fixtureUrlTestComponent.whenStable();
|
||||
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScale).toBe(0.8);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -531,15 +512,12 @@ describe('Test PdfViewer component', () => {
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
|
||||
beforeEach((done) => {
|
||||
beforeEach(async () => {
|
||||
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
||||
elementUrlTestComponent = fixtureUrlTestComponent.nativeElement;
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
done();
|
||||
});
|
||||
await fixtureUrlTestComponent.whenStable();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -586,15 +564,12 @@ describe('Test PdfViewer component', () => {
|
||||
let fixtureBlobTestComponent: ComponentFixture<BlobTestComponent>;
|
||||
let elementBlobTestComponent: HTMLElement;
|
||||
|
||||
beforeEach((done) => {
|
||||
beforeEach(async () => {
|
||||
fixtureBlobTestComponent = TestBed.createComponent(BlobTestComponent);
|
||||
elementBlobTestComponent = fixtureBlobTestComponent.nativeElement;
|
||||
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
fixtureBlobTestComponent.whenStable().then(() => {
|
||||
done();
|
||||
});
|
||||
await fixtureBlobTestComponent.whenStable();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -681,44 +656,38 @@ describe('Test PdfViewer component', () => {
|
||||
document.body.removeChild(fixtureUrlTestPasswordComponent.nativeElement);
|
||||
});
|
||||
|
||||
it('should try to access protected pdf', (done) => {
|
||||
it('should try to access protected pdf', async () => {
|
||||
componentUrlTestPasswordComponent.pdfViewerComponent.onPdfPassword(() => {}, pdfjsLib.PasswordResponses.NEED_PASSWORD);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(dialog.open).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should raise dialog asking for password', async () => {
|
||||
componentUrlTestPasswordComponent.pdfViewerComponent.onPdfPassword(() => {}, pdfjsLib.PasswordResponses.NEED_PASSWORD);
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(dialog.open).toHaveBeenCalledTimes(1);
|
||||
done();
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open['calls'].all()[0].args[1].data).toEqual({
|
||||
reason: pdfjsLib.PasswordResponses.NEED_PASSWORD
|
||||
});
|
||||
});
|
||||
|
||||
it('should raise dialog asking for password', (done) => {
|
||||
componentUrlTestPasswordComponent.pdfViewerComponent.onPdfPassword(() => {}, pdfjsLib.PasswordResponses.NEED_PASSWORD);
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open['calls'].all()[0].args[1].data).toEqual({
|
||||
reason: pdfjsLib.PasswordResponses.NEED_PASSWORD
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('it should raise dialog with incorrect password', (done) => {
|
||||
it('it should raise dialog with incorrect password', async () => {
|
||||
componentUrlTestPasswordComponent.pdfViewerComponent.onPdfPassword(() => {}, pdfjsLib.PasswordResponses.INCORRECT_PASSWORD);
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(dialog.open['calls'].all()[0].args[1].data).toEqual({
|
||||
reason: pdfjsLib.PasswordResponses.INCORRECT_PASSWORD
|
||||
});
|
||||
done();
|
||||
await fixture.whenStable();
|
||||
expect(dialog.open['calls'].all()[0].args[1].data).toEqual({
|
||||
reason: pdfjsLib.PasswordResponses.INCORRECT_PASSWORD
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Close password dialog ', () => {
|
||||
beforeEach((done) => {
|
||||
beforeEach(async () => {
|
||||
fixtureUrlTestPasswordComponent = TestBed.createComponent(UrlTestPasswordComponent);
|
||||
componentUrlTestPasswordComponent = fixtureUrlTestPasswordComponent.componentInstance;
|
||||
|
||||
@@ -732,25 +701,18 @@ describe('Test PdfViewer component', () => {
|
||||
spyOn(componentUrlTestPasswordComponent.pdfViewerComponent.close, 'emit');
|
||||
|
||||
fixtureUrlTestPasswordComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestPasswordComponent.whenStable().then(() => {
|
||||
done();
|
||||
});
|
||||
await fixtureUrlTestPasswordComponent.whenStable();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(fixtureUrlTestPasswordComponent.nativeElement);
|
||||
});
|
||||
|
||||
it('should try to access protected pdf', (done) => {
|
||||
it('should try to access protected pdf', async () => {
|
||||
componentUrlTestPasswordComponent.pdfViewerComponent.onPdfPassword(() => {}, pdfjsLib.PasswordResponses.NEED_PASSWORD);
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(componentUrlTestPasswordComponent.pdfViewerComponent.close.emit).toHaveBeenCalledWith();
|
||||
done();
|
||||
});
|
||||
await fixture.whenStable();
|
||||
expect(componentUrlTestPasswordComponent.pdfViewerComponent.close.emit).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -20,16 +20,18 @@ import { Location } from '@angular/common';
|
||||
import { SpyLocation } from '@angular/common/testing';
|
||||
import { Component, TemplateRef, ViewChild } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { CoreTestingModule } from '../../../testing';
|
||||
import { NoopTranslateModule } from '../../../testing';
|
||||
import { RenderingQueueServices } from '../../services/rendering-queue.services';
|
||||
import { ViewerRenderComponent } from './viewer-render.component';
|
||||
import { ViewerExtensionDirective } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-double-viewer',
|
||||
standalone: true,
|
||||
imports: [ViewerExtensionDirective, ViewerRenderComponent],
|
||||
template: `
|
||||
<adf-viewer-render [urlFile]="urlFileViewer1" [viewerTemplateExtensions]="viewerTemplateExtensions" #viewer1></adf-viewer-render>
|
||||
<adf-viewer-render [urlFile]="urlFileViewer2" #viewer2></adf-viewer-render>
|
||||
@@ -70,8 +72,7 @@ describe('ViewerComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [CoreTestingModule, MatButtonModule, MatIconModule],
|
||||
declarations: [DoubleViewerComponent],
|
||||
imports: [NoopTranslateModule, NoopAnimationsModule, MatDialogModule, ViewerRenderComponent, DoubleViewerComponent],
|
||||
providers: [RenderingQueueServices, { provide: Location, useClass: SpyLocation }, MatDialog]
|
||||
});
|
||||
fixture = TestBed.createComponent(ViewerRenderComponent);
|
||||
|
@@ -22,5 +22,5 @@ import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@ang
|
||||
|
||||
// First, initialize the Angular testing environment.
|
||||
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
|
||||
teardown: { destroyAfterEach: false }
|
||||
teardown: { destroyAfterEach: true }
|
||||
});
|
||||
|
Reference in New Issue
Block a user