unit test cleanup (#454)

* auth mock

* avoid using jasmine

* cleanup preview tests

* cleanup recent files tests

* cleanup shared files tests

* remove fdescribe

* update tests

* move adf services to single place

* move app specific services to single place

* cleanup directive tests

* cleanup directive tests

* update directive tests
This commit is contained in:
Denys Vuika 2018-06-24 17:33:50 +01:00 committed by GitHub
parent e846d97317
commit ac6e96530f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 223 additions and 543 deletions

View File

@ -26,23 +26,11 @@
import { Component, DebugElement } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Rx';
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 { NodesApiService, NotificationService } from '@alfresco/adf-core';
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';
import { AppTestingModule } from '../../testing/app-testing.module';
@Component({
template: '<div [acaCopyNode]="selection"></div>'
@ -58,38 +46,13 @@ describe('NodeCopyDirective', () => {
let notificationService: NotificationService;
let nodesApiService: NodesApiService;
let service: NodeActionsService;
let translationService: TranslationService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
MatSnackBarModule,
MatDialogModule,
MatIconModule
],
imports: [ AppTestingModule ],
declarations: [
TestComponent,
NodeCopyDirective
],
providers: [
AlfrescoApiService,
AuthenticationService,
AppConfigService,
StorageService,
ContentService,
UserPreferencesService,
LogService,
CookieService,
NotificationService,
NodesApiService,
NodeActionsService,
{ provide: TranslationService, useClass: TranslationMock },
ContentManagementService,
DocumentListService,
ThumbnailService
]
});
@ -99,13 +62,6 @@ describe('NodeCopyDirective', () => {
notificationService = TestBed.get(NotificationService);
nodesApiService = TestBed.get(NodesApiService);
service = TestBed.get(NodeActionsService);
translationService = TestBed.get(TranslationService);
});
beforeEach(() => {
spyOn(translationService, 'get').and.callFake((key) => {
return Observable.of(key);
});
});
describe('Copy node action', () => {

View File

@ -25,14 +25,10 @@
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { CoreModule, AlfrescoApiService } from '@alfresco/adf-core';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Component, DebugElement } from '@angular/core';
import { NodeDeleteDirective } from './node-delete.directive';
import { ContentManagementService } from '../services/content-management.service';
import { StoreModule } from '@ngrx/store';
import { appReducer } from '../../store/reducers/app.reducer';
import { INITIAL_STATE } from '../../store/states/app.state';
import { EffectsModule, Actions, ofType } from '@ngrx/effects';
import { NodeEffects } from '../../store/effects/node.effects';
import {
@ -40,6 +36,7 @@ import {
SnackbarErrorAction, SnackbarWarningAction, SNACKBAR_WARNING
} from '../../store/actions';
import { map } from 'rxjs/operators';
import { AppTestingModule } from '../../testing/app-testing.module';
@Component({
template: '<div [acaDeleteNode]="selection"></div>'
@ -58,16 +55,12 @@ describe('NodeDeleteDirective', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
CoreModule,
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE }),
AppTestingModule,
EffectsModule.forRoot([NodeEffects])
],
declarations: [
NodeDeleteDirective,
TestComponent
],
providers: [
ContentManagementService
]
});

View File

@ -27,20 +27,14 @@ import { Component, DebugElement } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Rx';
import { TranslationService, NodesApiService, NotificationService, CoreModule } from '@alfresco/adf-core';
import { DocumentListService } from '@alfresco/adf-content-services';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NodesApiService, NotificationService, TranslationService } from '@alfresco/adf-core';
import { NodeActionsService } from '../services/node-actions.service';
import { NodeMoveDirective } from './node-move.directive';
import { ContentManagementService } from '../services/content-management.service';
import { StoreModule } from '@ngrx/store';
import { EffectsModule, Actions, ofType } from '@ngrx/effects';
import { appReducer } from '../../store/reducers/app.reducer';
import { NodeEffects } from '../../store/effects/node.effects';
import { INITIAL_STATE } from '../../store/states/app.state';
import { SnackbarErrorAction, SNACKBAR_ERROR } from '../../store/actions';
import { map } from 'rxjs/operators';
import { AppTestingModule } from '../../testing/app-testing.module';
@Component({
template: '<div [acaMoveNode]="selection"></div>'
@ -56,28 +50,23 @@ describe('NodeMoveDirective', () => {
let notificationService: NotificationService;
let nodesApiService: NodesApiService;
let service: NodeActionsService;
let translationService: TranslationService;
let actions$: Actions;
let translationService: TranslationService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
BrowserAnimationsModule,
CoreModule,
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE }),
AppTestingModule,
EffectsModule.forRoot([NodeEffects])
],
declarations: [
NodeMoveDirective,
TestComponent
],
providers: [
DocumentListService,
ContentManagementService,
NodeActionsService
]
});
translationService = TestBed.get(TranslationService);
actions$ = TestBed.get(Actions);
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
@ -85,19 +74,18 @@ describe('NodeMoveDirective', () => {
notificationService = TestBed.get(NotificationService);
nodesApiService = TestBed.get(NodesApiService);
service = TestBed.get(NodeActionsService);
translationService = TestBed.get(TranslationService);
});
beforeEach(() => {
spyOn(translationService, 'get').and.callFake((keysArray) => {
spyOn(translationService, 'instant').and.callFake((keysArray) => {
if (Array.isArray(keysArray)) {
const processedKeys = {};
keysArray.forEach((key) => {
processedKeys[key] = key;
});
return Observable.of(processedKeys);
return processedKeys;
} else {
return Observable.of(keysArray);
return keysArray;
}
});
});

View File

@ -123,7 +123,7 @@ export class NodeMoveDirective {
errorMessage = this.getErrorMessage(info);
}
const undo = (succeeded + partiallySucceeded > 0) ? this.translation.translate.instant('APP.ACTIONS.UNDO') : '';
const undo = (succeeded + partiallySucceeded > 0) ? this.translation.instant('APP.ACTIONS.UNDO') : '';
const withUndo = errorMessage ? '' : '_WITH_UNDO';
failedMessage = errorMessage ? errorMessage : failedMessage;

View File

@ -24,17 +24,13 @@
*/
import { Component, DebugElement } from '@angular/core';
import { TestBed, ComponentFixture, async, fakeAsync, tick } from '@angular/core/testing';
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Rx';
import { AlfrescoApiService, CoreModule } from '@alfresco/adf-core';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { NodePermanentDeleteDirective } from './node-permanent-delete.directive';
import { MatDialogModule, MatDialog } from '@angular/material';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { StoreModule } from '@ngrx/store';
import { INITIAL_STATE } from '../../store/states/app.state';
import { appReducer } from '../../store/reducers/app.reducer';
import { MatDialog } from '@angular/material';
import { Actions, ofType, EffectsModule } from '@ngrx/effects';
import {
SNACKBAR_INFO, SnackbarWarningAction, SnackbarInfoAction,
@ -42,7 +38,7 @@ import {
} from '../../store/actions';
import { map } from 'rxjs/operators';
import { NodeEffects } from '../../store/effects/node.effects';
import { ContentManagementService } from '../services/content-management.service';
import { AppTestingModule } from '../../testing/app-testing.module';
@Component({
template: `<div [acaPermanentDelete]="selection"></div>`
@ -57,43 +53,30 @@ describe('NodePermanentDeleteDirective', () => {
let component: TestComponent;
let alfrescoApiService: AlfrescoApiService;
let dialog: MatDialog;
let actions$: Actions;
beforeEach(async(() => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
CoreModule.forRoot(),
MatDialogModule,
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE }),
AppTestingModule,
EffectsModule.forRoot([NodeEffects])
],
declarations: [
NodePermanentDeleteDirective,
TestComponent
],
providers: [
ContentManagementService
]
})
.compileComponents()
.then(() => {
alfrescoApiService = TestBed.get(AlfrescoApiService);
alfrescoApiService.reset();
actions$ = TestBed.get(Actions);
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodePermanentDeleteDirective));
dialog = TestBed.get(MatDialog);
});
}));
beforeEach(() => {
alfrescoApiService = TestBed.get(AlfrescoApiService);
alfrescoApiService.reset();
actions$ = TestBed.get(Actions);
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodePermanentDeleteDirective));
dialog = TestBed.get(MatDialog);
spyOn(dialog, 'open').and.returnValue({
afterClosed() {
return Observable.of(true);

View File

@ -24,24 +24,17 @@
*/
import { Component, DebugElement } from '@angular/core';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Rx';
import { AlfrescoApiService, TranslationService, CoreModule } from '@alfresco/adf-core';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { NodeRestoreDirective } from './node-restore.directive';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { ContentManagementService } from '../services/content-management.service';
import { StoreModule } from '@ngrx/store';
import { EffectsModule, Actions, ofType } from '@ngrx/effects';
import { appReducer } from '../../store/reducers/app.reducer';
import { INITIAL_STATE } from '../../store/states/app.state';
import { Actions, ofType } from '@ngrx/effects';
import { SnackbarErrorAction,
SNACKBAR_ERROR, SnackbarInfoAction, SNACKBAR_INFO,
NavigateRouteAction, NAVIGATE_ROUTE } from '../../store/actions';
import { map } from 'rxjs/operators';
import { AppTestingModule } from '../../testing/app-testing.module';
@Component({
template: `<div [acaRestoreNode]="selection"></div>`
@ -55,26 +48,16 @@ describe('NodeRestoreDirective', () => {
let element: DebugElement;
let component: TestComponent;
let alfrescoService: AlfrescoApiService;
let translation: TranslationService;
let directiveInstance: NodeRestoreDirective;
let contentManagementService: ContentManagementService;
let actions$: Actions;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
RouterTestingModule,
CoreModule.forRoot(),
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE }),
EffectsModule.forRoot([])
],
imports: [ AppTestingModule ],
declarations: [
NodeRestoreDirective,
TestComponent
],
providers: [
ContentManagementService
]
});
@ -88,9 +71,6 @@ describe('NodeRestoreDirective', () => {
element = fixture.debugElement.query(By.directive(NodeRestoreDirective));
directiveInstance = element.injector.get(NodeRestoreDirective);
translation = TestBed.get(TranslationService);
spyOn(translation, 'instant').and.returnValue(Observable.of('message'));
contentManagementService = TestBed.get(ContentManagementService);
});

View File

@ -26,20 +26,15 @@
import { Observable } from 'rxjs/Rx';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router } from '@angular/router';
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import {
NodesApiService, AlfrescoApiService, ContentService,
UserPreferencesService, LogService, AppConfigService,
StorageService, CookieService, ThumbnailService,
AuthenticationService, TimeAgoPipe, NodeNameTooltipPipe,
NodesApiService,
AlfrescoApiService,
TimeAgoPipe, NodeNameTooltipPipe,
NodeFavoriteDirective, DataTableComponent, AppConfigPipe
} from '@alfresco/adf-core';
import { DocumentListComponent, CustomResourcesService } from '@alfresco/adf-content-services';
import { MatMenuModule, MatSnackBarModule, MatIconModule } from '@angular/material';
import { DocumentListService } from '@alfresco/adf-content-services';
import { DocumentListComponent } 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 { AppTestingModule } from '../../testing/app-testing.module';
@ -80,13 +75,9 @@ describe('FavoritesComponent', () => {
};
});
beforeEach(async(() => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
AppTestingModule,
MatMenuModule,
MatSnackBarModule, MatIconModule,
],
imports: [ AppTestingModule ],
declarations: [
DataTableComponent,
TimeAgoPipe,
@ -96,36 +87,19 @@ describe('FavoritesComponent', () => {
FavoritesComponent,
AppConfigPipe
],
providers: [
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
CustomResourcesService,
LogService,
ContentManagementService,
ContentService,
NodesApiService,
NodePermissionService,
DocumentListService,
ThumbnailService
],
schemas: [ NO_ERRORS_SCHEMA ]
})
.compileComponents().then(() => {
fixture = TestBed.createComponent(FavoritesComponent);
component = fixture.componentInstance;
nodesApi = TestBed.get(NodesApiService);
alfrescoApi = TestBed.get(AlfrescoApiService);
alfrescoApi.reset();
contentService = TestBed.get(ContentManagementService);
router = TestBed.get(Router);
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(FavoritesComponent);
component = fixture.componentInstance;
nodesApi = TestBed.get(NodesApiService);
alfrescoApi = TestBed.get(AlfrescoApiService);
alfrescoApi.reset();
spyOn(alfrescoApi.favoritesApi, 'getFavorites').and.returnValue(Promise.resolve(page));
contentService = TestBed.get(ContentManagementService);
router = TestBed.get(Router);
});
describe('Events', () => {

View File

@ -24,38 +24,25 @@
*/
import { Observable } from 'rxjs/Rx';
import { TestBed, async, fakeAsync, tick } from '@angular/core/testing';
import { TestBed, fakeAsync, tick, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
import { TranslateModule } from '@ngx-translate/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {
NotificationService, TranslationService, TranslationMock,
NodesApiService, AlfrescoApiService, ContentService,
UserPreferencesService, LogService, AppConfigService,
StorageService, CookieService, ThumbnailService, AuthenticationService,
NodesApiService,
TimeAgoPipe, NodeNameTooltipPipe, FileSizePipe, NodeFavoriteDirective,
DataTableComponent, UploadService, AppConfigPipe
} from '@alfresco/adf-core';
import { DocumentListComponent, CustomResourcesService } from '@alfresco/adf-content-services';
import { MatMenuModule, MatSnackBarModule, MatIconModule, MatDialogModule } from '@angular/material';
import { DocumentListService } from '@alfresco/adf-content-services';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { ContentManagementService } from '../../common/services/content-management.service';
import { BrowsingFilesService } from '../../common/services/browsing-files.service';
import { NodeActionsService } from '../../common/services/node-actions.service';
import { NodePermissionService } from '../../common/services/node-permission.service';
import { FilesComponent } from './files.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('FilesComponent', () => {
let node;
let page;
let fixture;
let fixture: ComponentFixture<FilesComponent>;
let component: FilesComponent;
let contentManagementService: ContentManagementService;
let uploadService: UploadService;
@ -64,18 +51,14 @@ describe('FilesComponent', () => {
let browsingFilesService: BrowsingFilesService;
let nodeActionsService: NodeActionsService;
beforeEach(async(() => {
beforeAll(() => {
// testing only functional-wise not time-wise
Observable.prototype.debounceTime = function () { return this; };
});
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
MatMenuModule,
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule,
MatSnackBarModule, MatIconModule,
MatDialogModule,
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE })
],
imports: [ AppTestingModule ],
declarations: [
FilesComponent,
DataTableComponent,
@ -90,40 +73,21 @@ describe('FilesComponent', () => {
{ provide: ActivatedRoute, useValue: {
snapshot: { data: { preferencePrefix: 'prefix' } },
params: Observable.of({ folderId: 'someId' })
} } ,
{ provide: TranslationService, useClass: TranslationMock },
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentManagementService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService,
NodeActionsService,
NodePermissionService,
UploadService,
BrowsingFilesService,
CustomResourcesService
} }
],
schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents()
.then(() => {
fixture = TestBed.createComponent(FilesComponent);
component = fixture.componentInstance;
contentManagementService = TestBed.get(ContentManagementService);
uploadService = TestBed.get(UploadService);
nodesApi = TestBed.get(NodesApiService);
router = TestBed.get(Router);
browsingFilesService = TestBed.get(BrowsingFilesService);
nodeActionsService = TestBed.get(NodeActionsService);
});
}));
fixture = TestBed.createComponent(FilesComponent);
component = fixture.componentInstance;
contentManagementService = TestBed.get(ContentManagementService);
uploadService = TestBed.get(UploadService);
nodesApi = TestBed.get(NodesApiService);
router = TestBed.get(Router);
browsingFilesService = TestBed.get(BrowsingFilesService);
nodeActionsService = TestBed.get(NodeActionsService);
});
beforeEach(() => {
node = { id: 'node-id', isFolder: true };

View File

@ -41,16 +41,10 @@ describe('HeaderComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
AppTestingModule
],
imports: [ AppTestingModule ],
declarations: [
HeaderComponent
],
providers: [
AppConfigService,
PeopleContentService
],
schemas: [ NO_ERRORS_SCHEMA ]
})
.overrideProvider(PeopleContentService, {

View File

@ -24,23 +24,14 @@
*/
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { TranslateModule } from '@ngx-translate/core';
import { HttpClientModule } from '@angular/common/http';
import {
PeopleContentService, AppConfigService,
AuthenticationService, UserPreferencesService, TranslationService,
TranslationMock, StorageService, AlfrescoApiService, CookieService,
LogService
} from '@alfresco/adf-core';
import { PeopleContentService, AppConfigService, UserPreferencesService } from '@alfresco/adf-core';
import { Observable } from 'rxjs/Observable';
import { BrowsingFilesService } from '../../common/services/browsing-files.service';
import { NodePermissionService } from '../../common/services/node-permission.service';
import { LayoutComponent } from './layout.component';
import { SidenavViewsManagerDirective } from './sidenav-views-manager.directive';
import { AppTestingModule } from '../../testing/app-testing.module';
describe('LayoutComponent', () => {
let fixture: ComponentFixture<LayoutComponent>;
@ -58,26 +49,12 @@ describe('LayoutComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule
],
imports: [ AppTestingModule ],
declarations: [
LayoutComponent,
SidenavViewsManagerDirective
],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
AlfrescoApiService,
StorageService,
CookieService,
LogService,
UserPreferencesService,
AuthenticationService,
AppConfigService,
NodePermissionService,
BrowsingFilesService,
{
provide: PeopleContentService,
useValue: {

View File

@ -23,34 +23,21 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
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 {
NotificationService, TranslationService, TranslationMock,
NodesApiService, AlfrescoApiService, ContentService,
UserPreferencesService, LogService, AppConfigService,
StorageService, CookieService, ThumbnailService, AuthenticationService,
NodesApiService, AlfrescoApiService,
TimeAgoPipe, NodeNameTooltipPipe, NodeFavoriteDirective, DataTableComponent, AppConfigPipe
} 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 { DocumentListComponent } from '@alfresco/adf-content-services';
import { ShareDataTableAdapter } from '@alfresco/adf-content-services';
import { LibrariesComponent } from './libraries.component';
import { StoreModule } from '@ngrx/store';
import { appReducer } from '../../store/reducers/app.reducer';
import { INITIAL_STATE } from '../../store/states/app.state';
import { ContentManagementService } from '../../common/services/content-management.service';
import { ExperimentalDirective } from '../../directives/experimental.directive';
import { AppTestingModule } from '../../testing/app-testing.module';
describe('Libraries Routed Component', () => {
describe('LibrariesComponent', () => {
let fixture: ComponentFixture<LibrariesComponent>;
let component: LibrariesComponent;
let nodesApi: NodesApiService;
@ -75,17 +62,9 @@ describe('Libraries Routed Component', () => {
};
});
beforeEach(async(() => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
MatMenuModule,
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule,
MatSnackBarModule, MatIconModule,
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE })
],
imports: [ AppTestingModule ],
declarations: [
DataTableComponent,
TimeAgoPipe,
@ -96,36 +75,17 @@ describe('Libraries Routed Component', () => {
AppConfigPipe,
ExperimentalDirective
],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService,
CustomResourcesService,
ContentManagementService
],
schemas: [ NO_ERRORS_SCHEMA ]
})
.compileComponents().then(() => {
fixture = TestBed.createComponent(LibrariesComponent);
component = fixture.componentInstance;
nodesApi = TestBed.get(NodesApiService);
alfrescoApi = TestBed.get(AlfrescoApiService);
alfrescoApi.reset();
router = TestBed.get(Router);
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(LibrariesComponent);
component = fixture.componentInstance;
nodesApi = TestBed.get(NodesApiService);
alfrescoApi = TestBed.get(AlfrescoApiService);
alfrescoApi.reset();
router = TestBed.get(Router);
spyOn(alfrescoApi.sitesApi, 'getSites').and.returnValue((Promise.resolve(page)));
spyOn(alfrescoApi.peopleApi, 'getSiteMembership').and.returnValue((Promise.resolve({})));
});

View File

@ -24,19 +24,12 @@
*/
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import { TranslateModule } from '@ngx-translate/core';
import { Location } from '@angular/common';
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import {
AuthenticationService, UserPreferencesService, TranslationService,
TranslationMock, AppConfigService, StorageService, AlfrescoApiService,
CookieService, LogService, AppConfigPipe
} from '@alfresco/adf-core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { AuthenticationService, UserPreferencesService, AppConfigPipe } from '@alfresco/adf-core';
import { LoginComponent } from './login.component';
import { AppTestingModule } from '../../testing/app-testing.module';
describe('LoginComponent', () => {
let fixture: ComponentFixture<LoginComponent>;
@ -45,27 +38,15 @@ describe('LoginComponent', () => {
let auth: AuthenticationService;
let location: Location;
beforeEach(async(() => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule
],
imports: [ AppTestingModule ],
declarations: [
LoginComponent,
AppConfigPipe
],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
Location,
CookieService,
LogService,
StorageService,
AlfrescoApiService,
AppConfigService,
AuthenticationService,
UserPreferencesService
Location
],
schemas: [ NO_ERRORS_SCHEMA ]
});
@ -73,16 +54,16 @@ describe('LoginComponent', () => {
fixture = TestBed.createComponent(LoginComponent);
router = TestBed.get(Router);
location = TestBed.get(Location);
auth = TestBed.get(AuthenticationService);
userPreference = TestBed.get(UserPreferencesService);
}));
beforeEach(() => {
spyOn(userPreference, 'setStoragePrefix');
spyOn(router, 'navigateByUrl');
spyOn(auth, 'getRedirect').and.returnValue('/some-url');
location = TestBed.get(Location);
spyOn(location, 'forward');
auth = TestBed.get(AuthenticationService);
spyOn(auth, 'getRedirect').and.returnValue('/some-url');
userPreference = TestBed.get(UserPreferencesService);
spyOn(userPreference, 'setStoragePrefix');
});
describe('OnInit()', () => {

View File

@ -25,23 +25,13 @@
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,
TranslationService, TranslationMock,
CoreModule, UploadService
} from '@alfresco/adf-core';
import { AlfrescoApiService, UserPreferencesService, AppConfigPipe, NodeFavoriteDirective } from '@alfresco/adf-core';
import { PreviewComponent } from './preview.component';
import { Observable } from 'rxjs/Rx';
import { NodePermissionService } from '../../common/services/node-permission.service';
import { ContentManagementService } from '../../common/services/content-management.service';
import { StoreModule } from '@ngrx/store';
import { appReducer } from '../../store/reducers/app.reducer';
import { INITIAL_STATE } from '../../store/states/app.state';
import { EffectsModule } from '@ngrx/effects';
import { NodeEffects } from '../../store/effects/node.effects';
import { AppTestingModule } from '../../testing/app-testing.module';
describe('PreviewComponent', () => {
@ -55,20 +45,13 @@ describe('PreviewComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
CoreModule.forRoot(),
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE }),
AppTestingModule,
EffectsModule.forRoot([NodeEffects])
],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
NodePermissionService,
ContentManagementService,
UploadService
],
declarations: [
AppConfigPipe,
PreviewComponent,
// NodeFavoriteDirective
NodeFavoriteDirective
],
schemas: [ NO_ERRORS_SCHEMA ]
})

View File

@ -23,31 +23,19 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
import {
NotificationService, TranslationService, TranslationMock,
NodesApiService, AlfrescoApiService, ContentService, UploadService,
UserPreferencesService, LogService, AppConfigService,
StorageService, CookieService, ThumbnailService, AuthenticationService,
AlfrescoApiService,
TimeAgoPipe, NodeNameTooltipPipe, NodeFavoriteDirective, DataTableComponent, AppConfigPipe
} 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 { DocumentListComponent } from '@alfresco/adf-content-services';
import { ContentManagementService } from '../../common/services/content-management.service';
import { NodePermissionService } from '../../common/services/node-permission.service';
import { RecentFilesComponent } from './recent-files.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('RecentFiles Routed Component', () => {
describe('RecentFilesComponent', () => {
let fixture: ComponentFixture<RecentFilesComponent>;
let component: RecentFilesComponent;
let alfrescoApi: AlfrescoApiService;
@ -63,16 +51,10 @@ describe('RecentFiles Routed Component', () => {
};
});
beforeEach(async(() => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
MatMenuModule,
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule,
MatSnackBarModule, MatIconModule,
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE })
AppTestingModule
],
declarations: [
DataTableComponent,
@ -83,41 +65,21 @@ describe('RecentFiles Routed Component', () => {
RecentFilesComponent,
AppConfigPipe
],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentManagementService,
NodePermissionService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService,
CustomResourcesService,
UploadService
],
schemas: [ NO_ERRORS_SCHEMA ]
})
.compileComponents().then(() => {
fixture = TestBed.createComponent(RecentFilesComponent);
component = fixture.componentInstance;
contentService = TestBed.get(ContentManagementService);
alfrescoApi = TestBed.get(AlfrescoApiService);
alfrescoApi.reset();
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(RecentFilesComponent);
component = fixture.componentInstance;
contentService = TestBed.get(ContentManagementService);
alfrescoApi = TestBed.get(AlfrescoApiService);
alfrescoApi.reset();
spyOn(alfrescoApi.peopleApi, 'getPerson').and.returnValue(Promise.resolve({
entry: { id: 'personId' }
}));
entry: { id: 'personId' }
}));
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(Promise.resolve(page));
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(Promise.resolve(page));
});
describe('OnInit()', () => {

View File

@ -23,29 +23,16 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
import {
NotificationService, TranslationService, TranslationMock,
NodesApiService, AlfrescoApiService, ContentService,
UserPreferencesService, LogService, AppConfigService, UploadService,
StorageService, CookieService, ThumbnailService, AuthenticationService,
AlfrescoApiService,
TimeAgoPipe, NodeNameTooltipPipe, NodeFavoriteDirective, DataTableComponent, AppConfigPipe
} 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 { DocumentListComponent } from '@alfresco/adf-content-services';
import { ContentManagementService } from '../../common/services/content-management.service';
import { NodePermissionService } from '../../common/services/node-permission.service';
import { SharedFilesComponent } from './shared-files.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('SharedFilesComponent', () => {
let fixture: ComponentFixture<SharedFilesComponent>;
@ -63,18 +50,10 @@ describe('SharedFilesComponent', () => {
};
});
beforeEach(async(() => {
beforeEach(() => {
TestBed
.configureTestingModule({
imports: [
MatMenuModule,
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule,
MatSnackBarModule, MatIconModule,
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE })
],
imports: [ AppTestingModule ],
declarations: [
DataTableComponent,
TimeAgoPipe,
@ -84,39 +63,17 @@ describe('SharedFilesComponent', () => {
SharedFilesComponent,
AppConfigPipe
],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentManagementService,
NodePermissionService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService,
CustomResourcesService,
UploadService
],
schemas: [ NO_ERRORS_SCHEMA ]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(SharedFilesComponent);
component = fixture.componentInstance;
contentService = TestBed.get(ContentManagementService);
alfrescoApi = TestBed.get(AlfrescoApiService);
alfrescoApi.reset();
});
}));
fixture = TestBed.createComponent(SharedFilesComponent);
component = fixture.componentInstance;
beforeEach(() => {
spyOn(alfrescoApi.sharedLinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(page));
contentService = TestBed.get(ContentManagementService);
alfrescoApi = TestBed.get(AlfrescoApiService);
alfrescoApi.reset();
spyOn(alfrescoApi.sharedLinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(page));
});
describe('OnInit', () => {

View File

@ -25,16 +25,12 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { AppConfigService, CoreModule } from '@alfresco/adf-core';
import { AppConfigService } from '@alfresco/adf-core';
import { BrowsingFilesService } from '../../common/services/browsing-files.service';
import { NodePermissionService } from '../../common/services/node-permission.service';
import { SidenavComponent } from './sidenav.component';
import { EffectsModule } from '@ngrx/effects';
import { NodeEffects } from '../../store/effects/node.effects';
import { ContentManagementService } from '../../common/services/content-management.service';
import { AppTestingModule } from '../../testing/app-testing.module';
import { MaterialModule } from '../../material.module';
describe('SidenavComponent', () => {
let fixture: ComponentFixture<SidenavComponent>;
@ -54,18 +50,11 @@ describe('SidenavComponent', () => {
TestBed.configureTestingModule({
imports: [
AppTestingModule,
MaterialModule,
CoreModule.forRoot(),
EffectsModule.forRoot([NodeEffects])
],
declarations: [
SidenavComponent
],
providers: [
NodePermissionService,
BrowsingFilesService,
ContentManagementService
],
schemas: [ NO_ERRORS_SCHEMA ]
})
.compileComponents()

View File

@ -25,20 +25,14 @@
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import {
NotificationService,
NodesApiService, AlfrescoApiService, ContentService,
UserPreferencesService, LogService, AppConfigService,
StorageService, CookieService, ThumbnailService,
AuthenticationService, TimeAgoPipe, NodeNameTooltipPipe,
NodeFavoriteDirective, DataTableComponent, AppConfigPipe, PeopleContentService
AlfrescoApiService,
TimeAgoPipe, NodeNameTooltipPipe,
NodeFavoriteDirective, DataTableComponent, AppConfigPipe
} from '@alfresco/adf-core';
import { DocumentListComponent, CustomResourcesService } from '@alfresco/adf-content-services';
import { DocumentListService } from '@alfresco/adf-content-services';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { ContentManagementService } from '../../common/services/content-management.service';
import { TrashcanComponent } from './trashcan.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { MaterialModule } from '../../material.module';
describe('TrashcanComponent', () => {
let fixture: ComponentFixture<TrashcanComponent>;
@ -58,10 +52,7 @@ describe('TrashcanComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
AppTestingModule,
MaterialModule,
],
imports: [ AppTestingModule ],
declarations: [
DataTableComponent,
TimeAgoPipe,
@ -71,21 +62,6 @@ describe('TrashcanComponent', () => {
TrashcanComponent,
AppConfigPipe
],
providers: [
AuthenticationService,
UserPreferencesService,
PeopleContentService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentManagementService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService,
CustomResourcesService
],
schemas: [ NO_ERRORS_SCHEMA ]
});

View File

@ -24,10 +24,26 @@
*/
import { NgModule } from '@angular/core';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { TranslateService, TranslatePipe } 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 {
TranslationService,
TranslationMock,
AuthenticationService,
UserPreferencesService,
AppConfigService,
StorageService,
CookieService,
AlfrescoApiService,
LogService,
NotificationService,
NodesApiService,
ContentService,
ThumbnailService,
UploadService,
PeopleContentService
} from '@alfresco/adf-core';
import { HttpClientModule } from '@angular/common/http';
import { TranslateServiceMock } from './translation.service';
import { StoreModule } from '@ngrx/store';
@ -35,26 +51,64 @@ import { appReducer } from '../store/reducers/app.reducer';
import { INITIAL_STATE } from '../store/states/app.state';
import { RouterTestingModule } from '@angular/router/testing';
import { EffectsModule } from '@ngrx/effects';
import {
CustomResourcesService,
DocumentListService
} from '@alfresco/adf-content-services';
import { MaterialModule } from '../material.module';
import { ContentManagementService } from '../common/services/content-management.service';
import { NodeActionsService } from '../common/services/node-actions.service';
import { NodePermissionService } from '../common/services/node-permission.service';
import { BrowsingFilesService } from '../common/services/browsing-files.service';
@NgModule({
imports: [
NoopAnimationsModule,
HttpClientModule,
RouterTestingModule,
StoreModule.forRoot({ app: appReducer }, { initialState: INITIAL_STATE }),
MaterialModule,
StoreModule.forRoot(
{ app: appReducer },
{ initialState: INITIAL_STATE }
),
EffectsModule.forRoot([])
],
declarations: [
TranslatePipeMock
],
exports: [
TranslatePipeMock,
RouterTestingModule
],
declarations: [TranslatePipeMock],
exports: [TranslatePipeMock, RouterTestingModule, MaterialModule],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
{ provide: TranslateService, useClass: TranslateServiceMock },
{ provide: TranslatePipe, useClass: TranslatePipeMock }
{ provide: TranslatePipe, useClass: TranslatePipeMock },
{
provide: AuthenticationService,
useValue: {
isEcmLoggedIn(): boolean {
return true;
},
getRedirect(): string {
return null;
}
}
},
UserPreferencesService,
AppConfigService,
StorageService,
CookieService,
AlfrescoApiService,
LogService,
NotificationService,
NodesApiService,
ContentService,
ThumbnailService,
UploadService,
CustomResourcesService,
DocumentListService,
PeopleContentService,
ContentManagementService,
NodeActionsService,
NodePermissionService,
BrowsingFilesService
]
})
export class AppTestingModule {}

View File

@ -25,10 +25,19 @@
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class TranslateServiceMock extends TranslateService {
constructor() {
super(null, null, null, null, null);
}
get(key: string | Array<string>, interpolateParams?: Object): Observable<string | any> {
return Observable.of(key);
}
instant(key: string | Array<string>, interpolateParams?: Object): string | any {
return key;
}
}