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>
|
||||
|
||||
<mat-menu #userMenu="matMenu" [overlapTrigger]="false">
|
||||
<button *ngIf="showLanguagePicker"
|
||||
<button *ngIf="'languagePicker' | adfAppConfig"
|
||||
mat-menu-item [matMenuTriggerFor]="langMenu">
|
||||
{{ 'APP.LANGUAGE' | translate }}
|
||||
</button>
|
||||
|
@@ -25,18 +25,19 @@
|
||||
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { TestBed, async } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
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 {
|
||||
TranslationService, TranslationMock, AlfrescoApiService,
|
||||
AppConfigService, StorageService, PeopleContentService, UserPreferencesService
|
||||
AlfrescoApiService,
|
||||
AppConfigService,
|
||||
StorageService,
|
||||
PeopleContentService,
|
||||
UserPreferencesService,
|
||||
AppConfigPipe
|
||||
} from '@alfresco/adf-core';
|
||||
|
||||
import { CurrentUserComponent } from './current-user.component';
|
||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||
|
||||
describe('CurrentUserComponent', () => {
|
||||
let fixture;
|
||||
@@ -51,17 +52,14 @@ describe('CurrentUserComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
HttpClientModule,
|
||||
TranslateModule.forRoot(),
|
||||
NoopAnimationsModule,
|
||||
MatMenuModule,
|
||||
RouterTestingModule
|
||||
AppTestingModule,
|
||||
MatMenuModule
|
||||
],
|
||||
declarations: [
|
||||
CurrentUserComponent
|
||||
CurrentUserComponent,
|
||||
AppConfigPipe
|
||||
],
|
||||
providers: [
|
||||
{ provide: TranslationService, useClass: TranslationMock },
|
||||
AlfrescoApiService,
|
||||
AppConfigService,
|
||||
StorageService,
|
||||
|
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
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';
|
||||
|
||||
@Component({
|
||||
@@ -38,8 +38,7 @@ export class CurrentUserComponent implements OnInit, OnDestroy {
|
||||
user: any = null;
|
||||
|
||||
constructor(
|
||||
private peopleApi: PeopleContentService,
|
||||
private appConfig: AppConfigService
|
||||
private peopleApi: PeopleContentService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -71,8 +70,4 @@ export class CurrentUserComponent implements OnInit, OnDestroy {
|
||||
const { userFirstName: first, userLastName: last } = this;
|
||||
return [ first[0], last[0] ].join('');
|
||||
}
|
||||
|
||||
get showLanguagePicker() {
|
||||
return this.appConfig.get('languagePicker') || false;
|
||||
}
|
||||
}
|
||||
|
@@ -26,11 +26,8 @@
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
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 {
|
||||
NotificationService, TranslationService, TranslationMock,
|
||||
NodesApiService, AlfrescoApiService, ContentService,
|
||||
UserPreferencesService, LogService, AppConfigService,
|
||||
StorageService, CookieService, ThumbnailService,
|
||||
@@ -39,17 +36,13 @@ import {
|
||||
} from '@alfresco/adf-core';
|
||||
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 { DocumentListService } from '@alfresco/adf-content-services';
|
||||
import { ContentManagementService } from '../../common/services/content-management.service';
|
||||
import { NodePermissionService } from '../../common/services/node-permission.service';
|
||||
|
||||
import { FavoritesComponent } from './favorites.component';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { appReducer } from '../../store/reducers/app.reducer';
|
||||
import { INITIAL_STATE } from '../../store/states/app.state';
|
||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||
|
||||
describe('FavoritesComponent', () => {
|
||||
let fixture: ComponentFixture<FavoritesComponent>;
|
||||
@@ -90,13 +83,9 @@ describe('FavoritesComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppTestingModule,
|
||||
MatMenuModule,
|
||||
NoopAnimationsModule,
|
||||
HttpClientModule,
|
||||
TranslateModule.forRoot(),
|
||||
RouterTestingModule,
|
||||
MatSnackBarModule, MatIconModule,
|
||||
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE })
|
||||
],
|
||||
declarations: [
|
||||
DataTableComponent,
|
||||
@@ -108,14 +97,12 @@ describe('FavoritesComponent', () => {
|
||||
AppConfigPipe
|
||||
],
|
||||
providers: [
|
||||
{ provide: TranslationService, useClass: TranslationMock },
|
||||
AuthenticationService,
|
||||
UserPreferencesService,
|
||||
AppConfigService, StorageService, CookieService,
|
||||
AlfrescoApiService,
|
||||
CustomResourcesService,
|
||||
LogService,
|
||||
NotificationService,
|
||||
ContentManagementService,
|
||||
ContentService,
|
||||
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