mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-10-01 14:41:14 +00:00
Browsing Files - unit tests granular dependencies (#199)
This commit is contained in:
committed by
Denys Vuika
parent
114455e5c9
commit
4d7b6d3271
@@ -24,16 +24,28 @@
|
||||
*/
|
||||
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { Router } from '@angular/router';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { TestBed, async } from '@angular/core/testing';
|
||||
import { UploadService, NodesApiService, ContentService } from '@alfresco/adf-core';
|
||||
|
||||
import { CommonModule } from '../../common/common.module';
|
||||
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,
|
||||
TimeAgoPipe, NodeNameTooltipPipe, FileSizePipe, NodeFavoriteDirective,
|
||||
DataTableComponent, UploadService
|
||||
} from '@alfresco/adf-core';
|
||||
import { DocumentListComponent } from '@alfresco/adf-content-services';
|
||||
import { MatMenuModule, MatSnackBarModule, MatIconModule, MatDialogModule } from '@angular/material';
|
||||
import { DocumentListService } 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 { GenericErrorComponent } from '../generic-error/generic-error.component';
|
||||
|
||||
import { FilesComponent } from './files.component';
|
||||
|
||||
describe('FilesComponent', () => {
|
||||
@@ -48,17 +60,50 @@ describe('FilesComponent', () => {
|
||||
let router: Router;
|
||||
let browsingFilesService: BrowsingFilesService;
|
||||
let nodeActionsService: NodeActionsService;
|
||||
let preferenceService: UserPreferencesService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
MatMenuModule,
|
||||
NoopAnimationsModule,
|
||||
HttpClientModule,
|
||||
TranslateModule.forRoot(),
|
||||
RouterTestingModule,
|
||||
CommonModule
|
||||
MatSnackBarModule, MatIconModule,
|
||||
MatDialogModule
|
||||
],
|
||||
declarations: [
|
||||
FilesComponent,
|
||||
GenericErrorComponent
|
||||
]
|
||||
DataTableComponent,
|
||||
TimeAgoPipe,
|
||||
NodeNameTooltipPipe,
|
||||
NodeFavoriteDirective,
|
||||
DocumentListComponent,
|
||||
FileSizePipe
|
||||
],
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: {
|
||||
params: Observable.of({ folderId: 'someId' }),
|
||||
snapshot: { data: { preferencePrefix: 'prefix' } }
|
||||
} } ,
|
||||
{ provide: TranslationService, useClass: TranslationMock },
|
||||
AuthenticationService,
|
||||
UserPreferencesService,
|
||||
AppConfigService, StorageService, CookieService,
|
||||
AlfrescoApiService,
|
||||
LogService,
|
||||
NotificationService,
|
||||
ContentManagementService,
|
||||
ContentService,
|
||||
NodesApiService,
|
||||
DocumentListService,
|
||||
ThumbnailService,
|
||||
NodeActionsService,
|
||||
UploadService,
|
||||
BrowsingFilesService
|
||||
],
|
||||
schemas: [ NO_ERRORS_SCHEMA ]
|
||||
}).compileComponents()
|
||||
.then(() => {
|
||||
|
||||
@@ -72,6 +117,7 @@ describe('FilesComponent', () => {
|
||||
alfrescoContentService = TestBed.get(ContentService);
|
||||
browsingFilesService = TestBed.get(BrowsingFilesService);
|
||||
nodeActionsService = TestBed.get(NodeActionsService);
|
||||
preferenceService = TestBed.get(UserPreferencesService);
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -454,4 +500,55 @@ describe('FilesComponent', () => {
|
||||
expect(router.navigate).toHaveBeenCalledWith(['./'], jasmine.any(Object));
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSiteContainer', () => {
|
||||
it('should return false if node has no aspectNames', () => {
|
||||
const mock = { aspectNames: [] };
|
||||
|
||||
expect(component.isSiteContainer(mock)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false if node is not site container', () => {
|
||||
const mock = { aspectNames: ['something-else'] };
|
||||
|
||||
expect(component.isSiteContainer(mock)).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true if node is a site container', () => {
|
||||
const mock = { aspectNames: [ 'st:siteContainer' ] };
|
||||
|
||||
expect(component.isSiteContainer(mock)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onSortingChanged', () => {
|
||||
it('should save sorting input', () => {
|
||||
spyOn(preferenceService, 'set');
|
||||
|
||||
const event = <any>{
|
||||
detail: {
|
||||
key: 'some-name',
|
||||
direction: 'some-direction'
|
||||
}
|
||||
};
|
||||
|
||||
component.onSortingChanged(event);
|
||||
|
||||
expect(preferenceService.set).toHaveBeenCalledWith('prefix.sorting.key', 'some-name');
|
||||
expect(preferenceService.set).toHaveBeenCalledWith('prefix.sorting.direction', 'some-direction');
|
||||
});
|
||||
|
||||
it('should save default sorting when no input', () => {
|
||||
spyOn(preferenceService, 'set');
|
||||
|
||||
const event = <any>{
|
||||
detail: {}
|
||||
};
|
||||
|
||||
component.onSortingChanged(event);
|
||||
|
||||
expect(preferenceService.set).toHaveBeenCalledWith('prefix.sorting.key', 'modifiedAt');
|
||||
expect(preferenceService.set).toHaveBeenCalledWith('prefix.sorting.direction', 'desc');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user