Browsing Files - unit tests granular dependencies (#199)

This commit is contained in:
Cilibiu Bogdan
2018-02-23 18:25:59 +02:00
committed by Denys Vuika
parent 114455e5c9
commit 4d7b6d3271
6 changed files with 514 additions and 61 deletions

View File

@@ -23,14 +23,26 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, async } from '@angular/core/testing';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { CoreModule, NodesApiService, AlfrescoApiService, ContentService } from '@alfresco/adf-core'; 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 { TestBed, async } from '@angular/core/testing';
import {
NotificationService, TranslationService, TranslationMock,
NodesApiService, AlfrescoApiService, ContentService,
UserPreferencesService, LogService, AppConfigService,
StorageService, CookieService, ThumbnailService,
AuthenticationService, TimeAgoPipe, NodeNameTooltipPipe,
NodeFavoriteDirective, DataTableComponent
} from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { CommonModule } from '../../common/common.module'; import { TranslateModule } from '@ngx-translate/core';
import { LocationLinkComponent } from '../location-link/location-link.component'; 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 { ContentManagementService } from '../../common/services/content-management.service';
import { FavoritesComponent } from './favorites.component'; import { FavoritesComponent } from './favorites.component';
@@ -42,6 +54,7 @@ describe('Favorites Routed Component', () => {
let alfrescoApi: AlfrescoApiService; let alfrescoApi: AlfrescoApiService;
let alfrescoContentService: ContentService; let alfrescoContentService: ContentService;
let contentService: ContentManagementService; let contentService: ContentManagementService;
let preferenceService: UserPreferencesService;
let router: Router; let router: Router;
let page; let page;
let node; let node;
@@ -75,14 +88,39 @@ describe('Favorites Routed Component', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
CoreModule, MatMenuModule,
CommonModule, NoopAnimationsModule,
RouterTestingModule HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule,
MatSnackBarModule, MatIconModule
], ],
declarations: [ declarations: [
LocationLinkComponent, DataTableComponent,
TimeAgoPipe,
NodeNameTooltipPipe,
NodeFavoriteDirective,
DocumentListComponent,
FavoritesComponent FavoritesComponent
] ],
providers: [
{ provide: ActivatedRoute, useValue: {
snapshot: { data: { preferencePrefix: 'prefix' } }
} } ,
{ provide: TranslationService, useClass: TranslationMock },
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentManagementService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService
],
schemas: [ NO_ERRORS_SCHEMA ]
}) })
.compileComponents().then(() => { .compileComponents().then(() => {
fixture = TestBed.createComponent(FavoritesComponent); fixture = TestBed.createComponent(FavoritesComponent);
@@ -92,6 +130,7 @@ describe('Favorites Routed Component', () => {
alfrescoApi = TestBed.get(AlfrescoApiService); alfrescoApi = TestBed.get(AlfrescoApiService);
alfrescoContentService = TestBed.get(ContentService); alfrescoContentService = TestBed.get(ContentService);
contentService = TestBed.get(ContentManagementService); contentService = TestBed.get(ContentManagementService);
preferenceService = TestBed.get(UserPreferencesService);
router = TestBed.get(Router); router = TestBed.get(Router);
}); });
})); }));
@@ -101,23 +140,34 @@ describe('Favorites Routed Component', () => {
}); });
describe('Events', () => { describe('Events', () => {
it('should refresh on editing folder event', () => { beforeEach(() => {
spyOn(component, 'refresh'); spyOn(component, 'refresh');
fixture.detectChanges(); fixture.detectChanges();
});
it('should refresh on editing folder event', () => {
alfrescoContentService.folderEdit.next(null); alfrescoContentService.folderEdit.next(null);
expect(component.refresh).toHaveBeenCalled(); expect(component.refresh).toHaveBeenCalled();
}); });
it('should refresh on move node event', () => { it('should refresh on move node event', () => {
spyOn(component, 'refresh');
fixture.detectChanges();
contentService.nodeMoved.next(null); contentService.nodeMoved.next(null);
expect(component.refresh).toHaveBeenCalled(); expect(component.refresh).toHaveBeenCalled();
}); });
it('should refresh on node deleted event', () => {
contentService.nodeDeleted.next(null);
expect(component.refresh).toHaveBeenCalled();
});
it('should refresh on node restore event', () => {
contentService.nodeRestored.next(null);
expect(component.refresh).toHaveBeenCalled();
});
}); });
describe('Node navigation', () => { describe('Node navigation', () => {
@@ -238,4 +288,35 @@ describe('Favorites Routed Component', () => {
expect(component.documentList.reload).toHaveBeenCalled(); expect(component.documentList.reload).toHaveBeenCalled();
}); });
}); });
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');
});
});
}); });

View File

@@ -24,16 +24,28 @@
*/ */
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, async } from '@angular/core/testing'; import { TestBed, async } from '@angular/core/testing';
import { UploadService, NodesApiService, ContentService } from '@alfresco/adf-core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { CommonModule } from '../../common/common.module'; 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 { ContentManagementService } from '../../common/services/content-management.service';
import { BrowsingFilesService } from '../../common/services/browsing-files.service'; import { BrowsingFilesService } from '../../common/services/browsing-files.service';
import { NodeActionsService } from '../../common/services/node-actions.service'; import { NodeActionsService } from '../../common/services/node-actions.service';
import { GenericErrorComponent } from '../generic-error/generic-error.component';
import { FilesComponent } from './files.component'; import { FilesComponent } from './files.component';
describe('FilesComponent', () => { describe('FilesComponent', () => {
@@ -48,17 +60,50 @@ describe('FilesComponent', () => {
let router: Router; let router: Router;
let browsingFilesService: BrowsingFilesService; let browsingFilesService: BrowsingFilesService;
let nodeActionsService: NodeActionsService; let nodeActionsService: NodeActionsService;
let preferenceService: UserPreferencesService;
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
MatMenuModule,
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule, RouterTestingModule,
CommonModule MatSnackBarModule, MatIconModule,
MatDialogModule
], ],
declarations: [ declarations: [
FilesComponent, 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() }).compileComponents()
.then(() => { .then(() => {
@@ -72,6 +117,7 @@ describe('FilesComponent', () => {
alfrescoContentService = TestBed.get(ContentService); alfrescoContentService = TestBed.get(ContentService);
browsingFilesService = TestBed.get(BrowsingFilesService); browsingFilesService = TestBed.get(BrowsingFilesService);
nodeActionsService = TestBed.get(NodeActionsService); nodeActionsService = TestBed.get(NodeActionsService);
preferenceService = TestBed.get(UserPreferencesService);
}); });
})); }));
@@ -454,4 +500,55 @@ describe('FilesComponent', () => {
expect(router.navigate).toHaveBeenCalledWith(['./'], jasmine.any(Object)); 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');
});
});
}); });

View File

@@ -23,15 +23,26 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, async } from '@angular/core/testing'; import { TestBed, async } from '@angular/core/testing';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/Rx';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { CoreModule , NodesApiService, AlfrescoApiService} from '@alfresco/adf-core'; import { Router, ActivatedRoute } 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,
TimeAgoPipe, NodeNameTooltipPipe, NodeFavoriteDirective, DataTableComponent
} from '@alfresco/adf-core';
import { DocumentListComponent } 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 { ShareDataTableAdapter } from '@alfresco/adf-content-services'; import { ShareDataTableAdapter } from '@alfresco/adf-content-services';
import { CommonModule } from '../../common/common.module';
import { LibrariesComponent } from './libraries.component'; import { LibrariesComponent } from './libraries.component';
describe('Libraries Routed Component', () => { describe('Libraries Routed Component', () => {
@@ -40,6 +51,7 @@ describe('Libraries Routed Component', () => {
let nodesApi: NodesApiService; let nodesApi: NodesApiService;
let alfrescoApi: AlfrescoApiService; let alfrescoApi: AlfrescoApiService;
let router: Router; let router: Router;
let preferenceService: UserPreferencesService;
let page; let page;
let node; let node;
@@ -62,13 +74,38 @@ describe('Libraries Routed Component', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
CoreModule, MatMenuModule,
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule, RouterTestingModule,
CommonModule MatSnackBarModule, MatIconModule
], ],
declarations: [ declarations: [
DataTableComponent,
TimeAgoPipe,
NodeNameTooltipPipe,
NodeFavoriteDirective,
DocumentListComponent,
LibrariesComponent LibrariesComponent
] ],
providers: [
{ provide: ActivatedRoute, useValue: {
snapshot: { data: { preferencePrefix: 'prefix' } }
} } ,
{ provide: TranslationService, useClass: TranslationMock },
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService
],
schemas: [ NO_ERRORS_SCHEMA ]
}) })
.compileComponents().then(() => { .compileComponents().then(() => {
fixture = TestBed.createComponent(LibrariesComponent); fixture = TestBed.createComponent(LibrariesComponent);
@@ -77,6 +114,7 @@ describe('Libraries Routed Component', () => {
nodesApi = TestBed.get(NodesApiService); nodesApi = TestBed.get(NodesApiService);
alfrescoApi = TestBed.get(AlfrescoApiService); alfrescoApi = TestBed.get(AlfrescoApiService);
router = TestBed.get(Router); router = TestBed.get(Router);
preferenceService = TestBed.get(UserPreferencesService);
}); });
})); }));
@@ -191,4 +229,35 @@ describe('Libraries Routed Component', () => {
expect(component.navigate).not.toHaveBeenCalled(); expect(component.navigate).not.toHaveBeenCalled();
}); });
}); });
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');
});
});
}); });

View File

@@ -23,15 +23,25 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, async } from '@angular/core/testing'; import { TestBed, async } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { CoreModule, AlfrescoApiService } from '@alfresco/adf-core'; import { Router, ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { CommonModule } from '../../common/common.module'; import { HttpClientModule } from '@angular/common/http';
import {
NotificationService, TranslationService, TranslationMock,
NodesApiService, AlfrescoApiService, ContentService,
UserPreferencesService, LogService, AppConfigService,
StorageService, CookieService, ThumbnailService, AuthenticationService,
TimeAgoPipe, NodeNameTooltipPipe, NodeFavoriteDirective, DataTableComponent
} from '@alfresco/adf-core';
import { DocumentListComponent } 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 { ContentManagementService } from '../../common/services/content-management.service';
import { LocationLinkComponent } from '../location-link/location-link.component';
import { RecentFilesComponent } from './recent-files.component'; import { RecentFilesComponent } from './recent-files.component';
describe('RecentFiles Routed Component', () => { describe('RecentFiles Routed Component', () => {
@@ -40,6 +50,7 @@ describe('RecentFiles Routed Component', () => {
let router: Router; let router: Router;
let alfrescoApi: AlfrescoApiService; let alfrescoApi: AlfrescoApiService;
let contentService: ContentManagementService; let contentService: ContentManagementService;
let preferenceService: UserPreferencesService;
let page; let page;
let person; let person;
@@ -57,14 +68,39 @@ describe('RecentFiles Routed Component', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
CoreModule, MatMenuModule,
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule, RouterTestingModule,
CommonModule MatSnackBarModule, MatIconModule
], ],
declarations: [ declarations: [
LocationLinkComponent, DataTableComponent,
TimeAgoPipe,
NodeNameTooltipPipe,
NodeFavoriteDirective,
DocumentListComponent,
RecentFilesComponent RecentFilesComponent
] ],
providers: [
{ provide: ActivatedRoute, useValue: {
snapshot: { data: { preferencePrefix: 'prefix' } }
} } ,
{ provide: TranslationService, useClass: TranslationMock },
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentManagementService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService
],
schemas: [ NO_ERRORS_SCHEMA ]
}) })
.compileComponents().then(() => { .compileComponents().then(() => {
fixture = TestBed.createComponent(RecentFilesComponent); fixture = TestBed.createComponent(RecentFilesComponent);
@@ -72,6 +108,7 @@ describe('RecentFiles Routed Component', () => {
router = TestBed.get(Router); router = TestBed.get(Router);
contentService = TestBed.get(ContentManagementService); contentService = TestBed.get(ContentManagementService);
preferenceService = TestBed.get(UserPreferencesService);
alfrescoApi = TestBed.get(AlfrescoApiService); alfrescoApi = TestBed.get(AlfrescoApiService);
}); });
})); }));
@@ -150,4 +187,35 @@ describe('RecentFiles Routed Component', () => {
expect(component.documentList.reload).toHaveBeenCalled(); expect(component.documentList.reload).toHaveBeenCalled();
}); });
}); });
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');
});
});
}); });

View File

@@ -23,15 +23,25 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { Router } from '@angular/router';
import { TestBed, async, fakeAsync, tick } from '@angular/core/testing'; import { TestBed, async, fakeAsync, tick } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
import { AlfrescoApiService } from '@alfresco/adf-core'; import {
NotificationService, TranslationService, TranslationMock,
import { CommonModule } from '../../common/common.module'; NodesApiService, AlfrescoApiService, ContentService,
UserPreferencesService, LogService, AppConfigService,
StorageService, CookieService, ThumbnailService, AuthenticationService,
TimeAgoPipe, NodeNameTooltipPipe, NodeFavoriteDirective,DataTableComponent
} from '@alfresco/adf-core';
import { DocumentListComponent } 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 { ContentManagementService } from '../../common/services/content-management.service';
import { LocationLinkComponent } from '../location-link/location-link.component';
import { SharedFilesComponent } from './shared-files.component'; import { SharedFilesComponent } from './shared-files.component';
describe('SharedFilesComponent', () => { describe('SharedFilesComponent', () => {
@@ -40,6 +50,7 @@ describe('SharedFilesComponent', () => {
let contentService: ContentManagementService; let contentService: ContentManagementService;
let nodeService; let nodeService;
let alfrescoApi: AlfrescoApiService; let alfrescoApi: AlfrescoApiService;
let preferenceService: UserPreferencesService;
let router: Router; let router: Router;
let page; let page;
@@ -56,13 +67,39 @@ describe('SharedFilesComponent', () => {
TestBed TestBed
.configureTestingModule({ .configureTestingModule({
imports: [ imports: [
MatMenuModule,
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule, RouterTestingModule,
CommonModule MatSnackBarModule, MatIconModule
], ],
declarations: [ declarations: [
LocationLinkComponent, DataTableComponent,
TimeAgoPipe,
NodeNameTooltipPipe,
NodeFavoriteDirective,
DocumentListComponent,
SharedFilesComponent SharedFilesComponent
] ],
providers: [
{ provide: ActivatedRoute, useValue: {
snapshot: { data: { preferencePrefix: 'prefix' } }
} } ,
{ provide: TranslationService, useClass: TranslationMock },
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentManagementService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService
],
schemas: [ NO_ERRORS_SCHEMA ]
}) })
.compileComponents() .compileComponents()
.then(() => { .then(() => {
@@ -72,6 +109,7 @@ describe('SharedFilesComponent', () => {
contentService = TestBed.get(ContentManagementService); contentService = TestBed.get(ContentManagementService);
alfrescoApi = TestBed.get(AlfrescoApiService); alfrescoApi = TestBed.get(AlfrescoApiService);
nodeService = alfrescoApi.getInstance().nodes; nodeService = alfrescoApi.getInstance().nodes;
preferenceService = TestBed.get(UserPreferencesService);
router = TestBed.get(Router); router = TestBed.get(Router);
}); });
@@ -160,4 +198,35 @@ describe('SharedFilesComponent', () => {
expect(component.documentList.reload).toHaveBeenCalled(); expect(component.documentList.reload).toHaveBeenCalled();
}); });
}); });
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');
});
});
}); });

View File

@@ -22,19 +22,34 @@
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
import { TestBed, async } from '@angular/core/testing'; import { TestBed, async } from '@angular/core/testing';
import { CoreModule, AlfrescoApiService } from '@alfresco/adf-core'; import {
import { TrashcanComponent } from './trashcan.component'; NotificationService, TranslationService, TranslationMock,
import { CommonModule } from '../../common/common.module'; NodesApiService, AlfrescoApiService, ContentService,
import { LocationLinkComponent } from '../location-link/location-link.component'; UserPreferencesService, LogService, AppConfigService,
StorageService, CookieService, ThumbnailService,
AuthenticationService, TimeAgoPipe, NodeNameTooltipPipe,
NodeFavoriteDirective, DataTableComponent
} from '@alfresco/adf-core';
import { DocumentListComponent } 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 { ContentManagementService } from '../../common/services/content-management.service';
import { TrashcanComponent } from './trashcan.component';
describe('TrashcanComponent', () => { describe('TrashcanComponent', () => {
let fixture; let fixture;
let component; let component;
let alfrescoApi: AlfrescoApiService; let alfrescoApi: AlfrescoApiService;
let contentService: ContentManagementService; let contentService: ContentManagementService;
let preferenceService: UserPreferencesService;
let page; let page;
beforeEach(() => { beforeEach(() => {
@@ -49,17 +64,39 @@ describe('TrashcanComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [
MatMenuModule,
NoopAnimationsModule,
HttpClientModule,
TranslateModule.forRoot(),
RouterTestingModule, RouterTestingModule,
CoreModule, MatSnackBarModule, MatIconModule
CommonModule
], ],
declarations: [ declarations: [
LocationLinkComponent, DataTableComponent,
TimeAgoPipe,
NodeNameTooltipPipe,
NodeFavoriteDirective,
DocumentListComponent,
TrashcanComponent TrashcanComponent
], ],
providers: [ providers: [
ContentManagementService { provide: ActivatedRoute, useValue: {
] snapshot: { data: { preferencePrefix: 'prefix' } }
} } ,
{ provide: TranslationService, useClass: TranslationMock },
AuthenticationService,
UserPreferencesService,
AppConfigService, StorageService, CookieService,
AlfrescoApiService,
LogService,
NotificationService,
ContentManagementService,
ContentService,
NodesApiService,
DocumentListService,
ThumbnailService
],
schemas: [ NO_ERRORS_SCHEMA ]
}) })
.compileComponents() .compileComponents()
.then(() => { .then(() => {
@@ -68,6 +105,7 @@ describe('TrashcanComponent', () => {
alfrescoApi = TestBed.get(AlfrescoApiService); alfrescoApi = TestBed.get(AlfrescoApiService);
contentService = TestBed.get(ContentManagementService); contentService = TestBed.get(ContentManagementService);
preferenceService = TestBed.get(UserPreferencesService);
component.documentList = { component.documentList = {
loadTrashcan: jasmine.createSpy('loadTrashcan'), loadTrashcan: jasmine.createSpy('loadTrashcan'),
@@ -102,4 +140,35 @@ describe('TrashcanComponent', () => {
expect(component.documentList.resetSelection).toHaveBeenCalled(); expect(component.documentList.resetSelection).toHaveBeenCalled();
}); });
}); });
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', 'archivedAt');
expect(preferenceService.set).toHaveBeenCalledWith('prefix.sorting.direction', 'desc');
});
});
}); });