mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
unit testing enhancements (#401)
* app testing module * reduce favorites test dependencies * remove fdescribe * setup store integration for app testing module
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<mat-menu #userMenu="matMenu" [overlapTrigger]="false">
|
<mat-menu #userMenu="matMenu" [overlapTrigger]="false">
|
||||||
<button *ngIf="showLanguagePicker"
|
<button *ngIf="'languagePicker' | adfAppConfig"
|
||||||
mat-menu-item [matMenuTriggerFor]="langMenu">
|
mat-menu-item [matMenuTriggerFor]="langMenu">
|
||||||
{{ 'APP.LANGUAGE' | translate }}
|
{{ 'APP.LANGUAGE' | translate }}
|
||||||
</button>
|
</button>
|
||||||
|
@@ -25,18 +25,19 @@
|
|||||||
|
|
||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { TestBed, async } from '@angular/core/testing';
|
import { TestBed, async } from '@angular/core/testing';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|
||||||
import { MatMenuModule } from '@angular/material';
|
import { MatMenuModule } from '@angular/material';
|
||||||
import {
|
import {
|
||||||
TranslationService, TranslationMock, AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AppConfigService, StorageService, PeopleContentService, UserPreferencesService
|
AppConfigService,
|
||||||
|
StorageService,
|
||||||
|
PeopleContentService,
|
||||||
|
UserPreferencesService,
|
||||||
|
AppConfigPipe
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
|
|
||||||
import { CurrentUserComponent } from './current-user.component';
|
import { CurrentUserComponent } from './current-user.component';
|
||||||
|
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||||
|
|
||||||
describe('CurrentUserComponent', () => {
|
describe('CurrentUserComponent', () => {
|
||||||
let fixture;
|
let fixture;
|
||||||
@@ -51,17 +52,14 @@ describe('CurrentUserComponent', () => {
|
|||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
HttpClientModule,
|
AppTestingModule,
|
||||||
TranslateModule.forRoot(),
|
MatMenuModule
|
||||||
NoopAnimationsModule,
|
|
||||||
MatMenuModule,
|
|
||||||
RouterTestingModule
|
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
CurrentUserComponent
|
CurrentUserComponent,
|
||||||
|
AppConfigPipe
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: TranslationService, useClass: TranslationMock },
|
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
AppConfigService,
|
AppConfigService,
|
||||||
StorageService,
|
StorageService,
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { PeopleContentService, AppConfigService } from '@alfresco/adf-core';
|
import { PeopleContentService } from '@alfresco/adf-core';
|
||||||
import { Subscription } from 'rxjs/Rx';
|
import { Subscription } from 'rxjs/Rx';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -38,8 +38,7 @@ export class CurrentUserComponent implements OnInit, OnDestroy {
|
|||||||
user: any = null;
|
user: any = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private peopleApi: PeopleContentService,
|
private peopleApi: PeopleContentService
|
||||||
private appConfig: AppConfigService
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@@ -71,8 +70,4 @@ export class CurrentUserComponent implements OnInit, OnDestroy {
|
|||||||
const { userFirstName: first, userLastName: last } = this;
|
const { userFirstName: first, userLastName: last } = this;
|
||||||
return [ first[0], last[0] ].join('');
|
return [ first[0], last[0] ].join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
get showLanguagePicker() {
|
|
||||||
return this.appConfig.get('languagePicker') || false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -26,11 +26,8 @@
|
|||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
|
||||||
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
|
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
|
||||||
import {
|
import {
|
||||||
NotificationService, TranslationService, TranslationMock,
|
|
||||||
NodesApiService, AlfrescoApiService, ContentService,
|
NodesApiService, AlfrescoApiService, ContentService,
|
||||||
UserPreferencesService, LogService, AppConfigService,
|
UserPreferencesService, LogService, AppConfigService,
|
||||||
StorageService, CookieService, ThumbnailService,
|
StorageService, CookieService, ThumbnailService,
|
||||||
@@ -39,17 +36,13 @@ import {
|
|||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { DocumentListComponent, CustomResourcesService } from '@alfresco/adf-content-services';
|
import { DocumentListComponent, CustomResourcesService } from '@alfresco/adf-content-services';
|
||||||
|
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|
||||||
import { MatMenuModule, MatSnackBarModule, MatIconModule } from '@angular/material';
|
import { MatMenuModule, MatSnackBarModule, MatIconModule } from '@angular/material';
|
||||||
import { DocumentListService } from '@alfresco/adf-content-services';
|
import { DocumentListService } from '@alfresco/adf-content-services';
|
||||||
import { ContentManagementService } from '../../common/services/content-management.service';
|
import { ContentManagementService } from '../../common/services/content-management.service';
|
||||||
import { NodePermissionService } from '../../common/services/node-permission.service';
|
import { NodePermissionService } from '../../common/services/node-permission.service';
|
||||||
|
|
||||||
import { FavoritesComponent } from './favorites.component';
|
import { FavoritesComponent } from './favorites.component';
|
||||||
import { StoreModule } from '@ngrx/store';
|
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||||
import { appReducer } from '../../store/reducers/app.reducer';
|
|
||||||
import { INITIAL_STATE } from '../../store/states/app.state';
|
|
||||||
|
|
||||||
describe('FavoritesComponent', () => {
|
describe('FavoritesComponent', () => {
|
||||||
let fixture: ComponentFixture<FavoritesComponent>;
|
let fixture: ComponentFixture<FavoritesComponent>;
|
||||||
@@ -90,13 +83,9 @@ describe('FavoritesComponent', () => {
|
|||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
AppTestingModule,
|
||||||
MatMenuModule,
|
MatMenuModule,
|
||||||
NoopAnimationsModule,
|
|
||||||
HttpClientModule,
|
|
||||||
TranslateModule.forRoot(),
|
|
||||||
RouterTestingModule,
|
|
||||||
MatSnackBarModule, MatIconModule,
|
MatSnackBarModule, MatIconModule,
|
||||||
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE })
|
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
DataTableComponent,
|
DataTableComponent,
|
||||||
@@ -108,14 +97,12 @@ describe('FavoritesComponent', () => {
|
|||||||
AppConfigPipe
|
AppConfigPipe
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: TranslationService, useClass: TranslationMock },
|
|
||||||
AuthenticationService,
|
AuthenticationService,
|
||||||
UserPreferencesService,
|
UserPreferencesService,
|
||||||
AppConfigService, StorageService, CookieService,
|
AppConfigService, StorageService, CookieService,
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
CustomResourcesService,
|
CustomResourcesService,
|
||||||
LogService,
|
LogService,
|
||||||
NotificationService,
|
|
||||||
ContentManagementService,
|
ContentManagementService,
|
||||||
ContentService,
|
ContentService,
|
||||||
NodesApiService,
|
NodesApiService,
|
||||||
|
57
src/app/testing/app-testing.module.ts
Normal file
57
src/app/testing/app-testing.module.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
*
|
||||||
|
* This file is part of the Alfresco Example Content Application.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
|
||||||
|
import { TranslatePipeMock } from './translate-pipe.directive';
|
||||||
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { TranslationService, TranslationMock } from '@alfresco/adf-core';
|
||||||
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
|
import { TranslateServiceMock } from './translation.service';
|
||||||
|
import { StoreModule } from '@ngrx/store';
|
||||||
|
import { appReducer } from '../store/reducers/app.reducer';
|
||||||
|
import { INITIAL_STATE } from '../store/states/app.state';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
NoopAnimationsModule,
|
||||||
|
HttpClientModule,
|
||||||
|
RouterTestingModule,
|
||||||
|
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE })
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
TranslatePipeMock
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
TranslatePipeMock
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: TranslationService, useClass: TranslationMock },
|
||||||
|
{ provide: TranslateService, useClass: TranslateServiceMock },
|
||||||
|
{ provide: TranslatePipe, useClass: TranslatePipeMock }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class AppTestingModule {}
|
33
src/app/testing/translate-pipe.directive.ts
Normal file
33
src/app/testing/translate-pipe.directive.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
*
|
||||||
|
* This file is part of the Alfresco Example Content Application.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
|
@Pipe({ name: 'translate' })
|
||||||
|
export class TranslatePipeMock implements PipeTransform {
|
||||||
|
transform(value: any, ...args: any[]) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
34
src/app/testing/translation.service.ts
Normal file
34
src/app/testing/translation.service.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||||
|
*
|
||||||
|
* This file is part of the Alfresco Example Content Application.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class TranslateServiceMock extends TranslateService {
|
||||||
|
constructor() {
|
||||||
|
super(null, null, null, null, null);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user