mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-10-01 14:41:14 +00:00
[ACA-1443] prettier formatting and checks (#629)
* intergrate prettier * update settings * integrate with travis * unified formatting across all files
This commit is contained in:
@@ -23,14 +23,22 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { TestBed, fakeAsync, tick, ComponentFixture } 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 {
|
||||
TimeAgoPipe, NodeNameTooltipPipe, FileSizePipe, NodeFavoriteDirective,
|
||||
DataTableComponent,
|
||||
UploadService,
|
||||
AppConfigPipe
|
||||
TimeAgoPipe,
|
||||
NodeNameTooltipPipe,
|
||||
FileSizePipe,
|
||||
NodeFavoriteDirective,
|
||||
DataTableComponent,
|
||||
UploadService,
|
||||
AppConfigPipe
|
||||
} from '@alfresco/adf-core';
|
||||
import { DocumentListComponent } from '@alfresco/adf-content-services';
|
||||
import { ContentManagementService } from '../../services/content-management.service';
|
||||
@@ -42,270 +50,278 @@ import { ExperimentalDirective } from '../../directives/experimental.directive';
|
||||
import { of, throwError } from 'rxjs';
|
||||
|
||||
describe('FilesComponent', () => {
|
||||
let node;
|
||||
let fixture: ComponentFixture<FilesComponent>;
|
||||
let component: FilesComponent;
|
||||
let contentManagementService: ContentManagementService;
|
||||
let uploadService: UploadService;
|
||||
let router: Router;
|
||||
let nodeActionsService: NodeActionsService;
|
||||
let contentApi: ContentApiService;
|
||||
let node;
|
||||
let fixture: ComponentFixture<FilesComponent>;
|
||||
let component: FilesComponent;
|
||||
let contentManagementService: ContentManagementService;
|
||||
let uploadService: UploadService;
|
||||
let router: Router;
|
||||
let nodeActionsService: NodeActionsService;
|
||||
let contentApi: ContentApiService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppTestingModule],
|
||||
declarations: [
|
||||
FilesComponent,
|
||||
DataTableComponent,
|
||||
TimeAgoPipe,
|
||||
NodeNameTooltipPipe,
|
||||
NodeFavoriteDirective,
|
||||
DocumentListComponent,
|
||||
FileSizePipe,
|
||||
AppConfigPipe,
|
||||
ExperimentalDirective
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
snapshot: { data: { preferencePrefix: 'prefix' } },
|
||||
params: of({ folderId: 'someId' })
|
||||
}
|
||||
}
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(FilesComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
contentManagementService = TestBed.get(ContentManagementService);
|
||||
uploadService = TestBed.get(UploadService);
|
||||
router = TestBed.get(Router);
|
||||
nodeActionsService = TestBed.get(NodeActionsService);
|
||||
contentApi = TestBed.get(ContentApiService);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
node = { id: 'node-id', isFolder: true };
|
||||
spyOn(component.documentList, 'loadFolder').and.callFake(() => {});
|
||||
});
|
||||
|
||||
describe('Current page is valid', () => {
|
||||
it('should be a valid current page', fakeAsync(() => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(throwError(null));
|
||||
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
tick();
|
||||
|
||||
expect(component.isValidPath).toBe(false);
|
||||
}));
|
||||
|
||||
it('should set current page as invalid path', fakeAsync(() => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
|
||||
component.ngOnInit();
|
||||
tick();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.isValidPath).toBe(true);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('should set current node', () => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
fixture.detectChanges();
|
||||
expect(component.node).toBe(node);
|
||||
});
|
||||
|
||||
it('if should navigate to parent if node is not a folder', () => {
|
||||
node.isFolder = false;
|
||||
node.parentId = 'parent-id';
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
spyOn(router, 'navigate');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(router.navigate['calls'].argsFor(0)[0]).toEqual([
|
||||
'/personal-files',
|
||||
'parent-id'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('refresh on events', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ AppTestingModule ],
|
||||
declarations: [
|
||||
FilesComponent,
|
||||
DataTableComponent,
|
||||
TimeAgoPipe,
|
||||
NodeNameTooltipPipe,
|
||||
NodeFavoriteDirective,
|
||||
DocumentListComponent,
|
||||
FileSizePipe,
|
||||
AppConfigPipe,
|
||||
ExperimentalDirective
|
||||
],
|
||||
providers: [
|
||||
{ provide: ActivatedRoute, useValue: {
|
||||
snapshot: { data: { preferencePrefix: 'prefix' } },
|
||||
params: of({ folderId: 'someId' })
|
||||
} }
|
||||
],
|
||||
schemas: [ NO_ERRORS_SCHEMA ]
|
||||
});
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
spyOn(component.documentList, 'reload');
|
||||
|
||||
fixture = TestBed.createComponent(FilesComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
contentManagementService = TestBed.get(ContentManagementService);
|
||||
uploadService = TestBed.get(UploadService);
|
||||
router = TestBed.get(Router);
|
||||
nodeActionsService = TestBed.get(NodeActionsService);
|
||||
contentApi = TestBed.get(ContentApiService);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should call refresh onContentCopied event if parent is the same', () => {
|
||||
const nodes = [
|
||||
{ entry: { parentId: '1' } },
|
||||
{ entry: { parentId: '2' } }
|
||||
];
|
||||
|
||||
component.node = { id: '1' };
|
||||
|
||||
nodeActionsService.contentCopied.next(nodes);
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call refresh onContentCopied event when parent mismatch', () => {
|
||||
const nodes = [
|
||||
{ entry: { parentId: '1' } },
|
||||
{ entry: { parentId: '2' } }
|
||||
];
|
||||
|
||||
component.node = { id: '3' };
|
||||
|
||||
nodeActionsService.contentCopied.next(nodes);
|
||||
|
||||
expect(component.documentList.reload).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh onCreateFolder event', () => {
|
||||
contentManagementService.folderCreated.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh editFolder event', () => {
|
||||
contentManagementService.folderEdited.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh deleteNode event', () => {
|
||||
contentManagementService.nodesDeleted.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh moveNode event', () => {
|
||||
contentManagementService.nodesMoved.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh restoreNode event', () => {
|
||||
contentManagementService.nodesRestored.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh on fileUploadComplete event if parent node match', fakeAsync(() => {
|
||||
const file = { file: { options: { parentId: 'parentId' } } };
|
||||
component.node = { id: 'parentId' };
|
||||
|
||||
uploadService.fileUploadComplete.next(<any>file);
|
||||
|
||||
tick(500);
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should not call refresh on fileUploadComplete event if parent mismatch', fakeAsync(() => {
|
||||
const file = { file: { options: { parentId: 'otherId' } } };
|
||||
component.node = { id: 'parentId' };
|
||||
|
||||
uploadService.fileUploadComplete.next(<any>file);
|
||||
|
||||
tick(500);
|
||||
|
||||
expect(component.documentList.reload).not.toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should call refresh on fileUploadDeleted event if parent node match', fakeAsync(() => {
|
||||
const file = { file: { options: { parentId: 'parentId' } } };
|
||||
component.node = { id: 'parentId' };
|
||||
|
||||
uploadService.fileUploadDeleted.next(<any>file);
|
||||
|
||||
tick(500);
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should not call refresh on fileUploadDeleted event if parent mismatch', fakeAsync(() => {
|
||||
const file: any = { file: { options: { parentId: 'otherId' } } };
|
||||
component.node = { id: 'parentId' };
|
||||
|
||||
uploadService.fileUploadDeleted.next(file);
|
||||
|
||||
tick(500);
|
||||
|
||||
expect(component.documentList.reload).not.toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('onBreadcrumbNavigate()', () => {
|
||||
beforeEach(() => {
|
||||
node = { id: 'node-id', isFolder: true };
|
||||
spyOn(component.documentList, 'loadFolder').and.callFake(() => {});
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
describe('Current page is valid', () => {
|
||||
it('should be a valid current page', fakeAsync(() => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(throwError(null));
|
||||
it('should navigates to node id', () => {
|
||||
const routeData: any = { id: 'some-where-over-the-rainbow' };
|
||||
spyOn(component, 'navigate');
|
||||
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
tick();
|
||||
component.onBreadcrumbNavigate(routeData);
|
||||
|
||||
expect(component.isValidPath).toBe(false);
|
||||
}));
|
||||
expect(component.navigate).toHaveBeenCalledWith(routeData.id);
|
||||
});
|
||||
});
|
||||
|
||||
it('should set current page as invalid path', fakeAsync(() => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
describe('Node navigation', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
spyOn(router, 'navigate');
|
||||
|
||||
component.ngOnInit();
|
||||
tick();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.isValidPath).toBe(true);
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('should set current node', () => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
fixture.detectChanges();
|
||||
expect(component.node).toBe(node);
|
||||
});
|
||||
it('should navigates to node when id provided', () => {
|
||||
component.navigate(node.id);
|
||||
|
||||
it('if should navigate to parent if node is not a folder', () => {
|
||||
node.isFolder = false;
|
||||
node.parentId = 'parent-id';
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
spyOn(router, 'navigate');
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(router.navigate['calls'].argsFor(0)[0]).toEqual(['/personal-files', 'parent-id']);
|
||||
});
|
||||
expect(router.navigate).toHaveBeenCalledWith(
|
||||
['./', node.id],
|
||||
jasmine.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
describe('refresh on events', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
spyOn(component.documentList, 'reload');
|
||||
it('should navigates to home when id not provided', () => {
|
||||
component.navigate();
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should call refresh onContentCopied event if parent is the same', () => {
|
||||
const nodes = [
|
||||
{ entry: { parentId: '1' } },
|
||||
{ entry: { parentId: '2' } }
|
||||
];
|
||||
|
||||
component.node = { id: '1' };
|
||||
|
||||
nodeActionsService.contentCopied.next(nodes);
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call refresh onContentCopied event when parent mismatch', () => {
|
||||
const nodes = [
|
||||
{ entry: { parentId: '1' } },
|
||||
{ entry: { parentId: '2' } }
|
||||
];
|
||||
|
||||
component.node = { id: '3' };
|
||||
|
||||
nodeActionsService.contentCopied.next(nodes);
|
||||
|
||||
expect(component.documentList.reload).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh onCreateFolder event', () => {
|
||||
contentManagementService.folderCreated.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh editFolder event', () => {
|
||||
contentManagementService.folderEdited.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh deleteNode event', () => {
|
||||
contentManagementService.nodesDeleted.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh moveNode event', () => {
|
||||
contentManagementService.nodesMoved.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh restoreNode event', () => {
|
||||
contentManagementService.nodesRestored.next();
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call refresh on fileUploadComplete event if parent node match', fakeAsync(() => {
|
||||
const file = { file: { options: { parentId: 'parentId' } } };
|
||||
component.node = { id: 'parentId' };
|
||||
|
||||
uploadService.fileUploadComplete.next(<any>file);
|
||||
|
||||
tick(500);
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should not call refresh on fileUploadComplete event if parent mismatch', fakeAsync(() => {
|
||||
const file = { file: { options: { parentId: 'otherId' } } };
|
||||
component.node = { id: 'parentId' };
|
||||
|
||||
uploadService.fileUploadComplete.next(<any>file);
|
||||
|
||||
tick(500);
|
||||
|
||||
expect(component.documentList.reload).not.toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should call refresh on fileUploadDeleted event if parent node match', fakeAsync(() => {
|
||||
const file = { file: { options: { parentId: 'parentId' } } };
|
||||
component.node = { id: 'parentId' };
|
||||
|
||||
uploadService.fileUploadDeleted.next(<any>file);
|
||||
|
||||
tick(500);
|
||||
|
||||
expect(component.documentList.reload).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should not call refresh on fileUploadDeleted event if parent mismatch', fakeAsync(() => {
|
||||
const file: any = { file: { options: { parentId: 'otherId' } } };
|
||||
component.node = { id: 'parentId' };
|
||||
|
||||
uploadService.fileUploadDeleted.next(file);
|
||||
|
||||
tick(500);
|
||||
|
||||
expect(component.documentList.reload).not.toHaveBeenCalled();
|
||||
}));
|
||||
expect(router.navigate).toHaveBeenCalledWith(['./'], jasmine.any(Object));
|
||||
});
|
||||
|
||||
it('should navigate home if node is root', () => {
|
||||
component.node = {
|
||||
path: {
|
||||
elements: [{ id: 'node-id' }]
|
||||
}
|
||||
};
|
||||
|
||||
describe('onBreadcrumbNavigate()', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
fixture.detectChanges();
|
||||
});
|
||||
component.navigate(node.id);
|
||||
|
||||
it('should navigates to node id', () => {
|
||||
const routeData: any = { id: 'some-where-over-the-rainbow' };
|
||||
spyOn(component, 'navigate');
|
||||
expect(router.navigate).toHaveBeenCalledWith(['./'], jasmine.any(Object));
|
||||
});
|
||||
});
|
||||
|
||||
component.onBreadcrumbNavigate(routeData);
|
||||
describe('isSiteContainer', () => {
|
||||
it('should return false if node has no aspectNames', () => {
|
||||
const mock = { aspectNames: [] };
|
||||
|
||||
expect(component.navigate).toHaveBeenCalledWith(routeData.id);
|
||||
});
|
||||
expect(component.isSiteContainer(mock)).toBe(false);
|
||||
});
|
||||
|
||||
describe('Node navigation', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
|
||||
spyOn(router, 'navigate');
|
||||
it('should return false if node is not site container', () => {
|
||||
const mock = { aspectNames: ['something-else'] };
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should navigates to node when id provided', () => {
|
||||
component.navigate(node.id);
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith(['./', node.id], jasmine.any(Object));
|
||||
});
|
||||
|
||||
it('should navigates to home when id not provided', () => {
|
||||
component.navigate();
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith(['./'], jasmine.any(Object));
|
||||
});
|
||||
|
||||
it('should navigate home if node is root', () => {
|
||||
component.node = {
|
||||
path: {
|
||||
elements: [ {id: 'node-id'} ]
|
||||
}
|
||||
};
|
||||
|
||||
component.navigate(node.id);
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith(['./'], jasmine.any(Object));
|
||||
});
|
||||
expect(component.isSiteContainer(mock)).toBe(false);
|
||||
});
|
||||
|
||||
describe('isSiteContainer', () => {
|
||||
it('should return false if node has no aspectNames', () => {
|
||||
const mock = { aspectNames: [] };
|
||||
it('should return true if node is a site container', () => {
|
||||
const mock = { aspectNames: ['st:siteContainer'] };
|
||||
|
||||
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);
|
||||
});
|
||||
expect(component.isSiteContainer(mock)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user