From ed2f91ee7cd5613e420eef80b0f7f15637e1c3d4 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Wed, 21 Feb 2018 13:21:59 +0000 Subject: [PATCH] [ACA-1137] Spike - Improving speed of unit tests (#193) * improve tests * improve tests * improve tests * improve tests --- .../directives/node-copy.directive.spec.ts | 40 +++++++++++++++++-- .../common/directives/node-copy.directive.ts | 2 +- .../services/node-actions.service.spec.ts | 32 +++++++++++++-- .../preview/preview.component.spec.ts | 28 +++++++++++-- 4 files changed, 89 insertions(+), 13 deletions(-) diff --git a/src/app/common/directives/node-copy.directive.spec.ts b/src/app/common/directives/node-copy.directive.spec.ts index f56990b65..a09b5dc54 100644 --- a/src/app/common/directives/node-copy.directive.spec.ts +++ b/src/app/common/directives/node-copy.directive.spec.ts @@ -29,11 +29,20 @@ import { By } from '@angular/platform-browser'; import { Observable } from 'rxjs/Rx'; -import { TranslationService, NodesApiService, NotificationService } from '@alfresco/adf-core'; +import { + TranslationService, NodesApiService, NotificationService, AlfrescoApiService, TranslationMock, + AppConfigService, StorageService, CookieService, ContentService, AuthenticationService, + UserPreferencesService, LogService, ThumbnailService +} from '@alfresco/adf-core'; +import { TranslateModule } from '@ngx-translate/core'; +import { HttpClientModule } from '@angular/common/http'; -import { CommonModule } from '../common.module'; import { NodeActionsService } from '../services/node-actions.service'; import { NodeCopyDirective } from './node-copy.directive'; +import { ContentManagementService } from '../services/content-management.service'; +import { MatSnackBarModule, MatDialogModule, MatIconModule } from '@angular/material'; +import { DocumentListService } from '@alfresco/adf-content-services'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; @Component({ template: '
' @@ -54,10 +63,33 @@ describe('NodeCopyDirective', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [ - CommonModule + NoopAnimationsModule, + HttpClientModule, + TranslateModule.forRoot(), + MatSnackBarModule, + MatDialogModule, + MatIconModule ], declarations: [ - TestComponent + TestComponent, + NodeCopyDirective + ], + providers: [ + AlfrescoApiService, + AuthenticationService, + AppConfigService, + StorageService, + ContentService, + UserPreferencesService, + LogService, + CookieService, + NotificationService, + NodesApiService, + NodeActionsService, + { provide: TranslationService, useClass: TranslationMock }, + ContentManagementService, + DocumentListService, + ThumbnailService ] }); diff --git a/src/app/common/directives/node-copy.directive.ts b/src/app/common/directives/node-copy.directive.ts index bd68d573f..656865820 100644 --- a/src/app/common/directives/node-copy.directive.ts +++ b/src/app/common/directives/node-copy.directive.ts @@ -104,7 +104,7 @@ export class NodeCopyDirective { } catch (err) { /* Do nothing, keep the original message */ } } - const undo = (numberOfCopiedItems > 0) ? this.translation.translate.instant('APP.ACTIONS.UNDO') : ''; + const undo = (numberOfCopiedItems > 0) ? this.translation.instant('APP.ACTIONS.UNDO') : ''; const withUndo = (numberOfCopiedItems > 0) ? '_WITH_UNDO' : ''; this.translation.get(i18nMessageString, { success: numberOfCopiedItems, failed: failedItems }).subscribe(message => { diff --git a/src/app/common/services/node-actions.service.spec.ts b/src/app/common/services/node-actions.service.spec.ts index 3b17c02a1..71749b605 100644 --- a/src/app/common/services/node-actions.service.spec.ts +++ b/src/app/common/services/node-actions.service.spec.ts @@ -24,15 +24,21 @@ */ import { TestBed, async } from '@angular/core/testing'; -import { MatDialog } from '@angular/material'; +import { MatDialog, MatDialogModule, MatIconModule } from '@angular/material'; import { OverlayModule } from '@angular/cdk/overlay'; import { Observable } from 'rxjs/Rx'; -import { AlfrescoApiService, NodesApiService, TranslationService } from '@alfresco/adf-core'; +import { + TranslationMock, AlfrescoApiService, NodesApiService, + TranslationService, ContentService, AuthenticationService, + UserPreferencesService, AppConfigService, StorageService, + CookieService, LogService, ThumbnailService +} from '@alfresco/adf-core'; import { DocumentListService } from '@alfresco/adf-content-services'; -import { CommonModule } from '../common.module'; import { NodeActionsService } from './node-actions.service'; import { MinimalNodeEntryEntity } from 'alfresco-js-api'; +import { TranslateModule } from '@ngx-translate/core'; +import { HttpClientModule } from '@angular/common/http'; class TestNode { entry?: MinimalNodeEntryEntity; @@ -104,8 +110,26 @@ describe('NodeActionsService', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [ - CommonModule, + MatDialogModule, + MatIconModule, + HttpClientModule, + TranslateModule.forRoot(), OverlayModule + ], + providers: [ + AlfrescoApiService, + NodesApiService, + { provide: TranslationService, useClass: TranslationMock }, + AuthenticationService, + UserPreferencesService, + AppConfigService, + CookieService, + LogService, + ThumbnailService, + StorageService, + ContentService, + DocumentListService, + NodeActionsService ] }); diff --git a/src/app/components/preview/preview.component.spec.ts b/src/app/components/preview/preview.component.spec.ts index a181ac4a6..e653a9194 100644 --- a/src/app/components/preview/preview.component.spec.ts +++ b/src/app/components/preview/preview.component.spec.ts @@ -23,14 +23,21 @@ * along with Alfresco. If not, see . */ +import { NO_ERRORS_SCHEMA } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { TestBed, async, ComponentFixture } from '@angular/core/testing'; -import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core'; +import { + AlfrescoApiService, UserPreferencesService, TranslationService, TranslationMock, + AppConfigService, StorageService, CookieService, NotificationService +} from '@alfresco/adf-core'; +import { TranslateModule } from '@ngx-translate/core'; +import { HttpClientModule } from '@angular/common/http'; -import { CommonModule } from '../../common/common.module'; import { PreviewComponent } from './preview.component'; import { Observable } from 'rxjs/Rx'; +import { ContentManagementService } from '../../common/services/content-management.service'; +import { MatSnackBarModule } from '@angular/material'; describe('PreviewComponent', () => { @@ -44,12 +51,25 @@ describe('PreviewComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ + HttpClientModule, RouterTestingModule, - CommonModule + TranslateModule.forRoot(), + MatSnackBarModule + ], + providers: [ + { provide: TranslationService, useClass: TranslationMock }, + AlfrescoApiService, + AppConfigService, + StorageService, + CookieService, + NotificationService, + UserPreferencesService, + ContentManagementService ], declarations: [ PreviewComponent - ] + ], + schemas: [ NO_ERRORS_SCHEMA ] }) .compileComponents().then(() => { fixture = TestBed.createComponent(PreviewComponent);