mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +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:
@@ -28,8 +28,12 @@ import { of } from 'rxjs';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
TimeAgoPipe, NodeNameTooltipPipe, NodeFavoriteDirective, DataTableComponent, AppConfigPipe
|
||||
AlfrescoApiService,
|
||||
TimeAgoPipe,
|
||||
NodeNameTooltipPipe,
|
||||
NodeFavoriteDirective,
|
||||
DataTableComponent,
|
||||
AppConfigPipe
|
||||
} from '@alfresco/adf-core';
|
||||
import { DocumentListComponent } from '@alfresco/adf-content-services';
|
||||
import { ShareDataTableAdapter } from '@alfresco/adf-content-services';
|
||||
@@ -39,149 +43,157 @@ import { ContentApiService } from '../../services/content-api.service';
|
||||
import { ExperimentalDirective } from '../../directives/experimental.directive';
|
||||
|
||||
describe('LibrariesComponent', () => {
|
||||
let fixture: ComponentFixture<LibrariesComponent>;
|
||||
let component: LibrariesComponent;
|
||||
let contentApi: ContentApiService;
|
||||
let alfrescoApi: AlfrescoApiService;
|
||||
let router: Router;
|
||||
let page;
|
||||
let node;
|
||||
let fixture: ComponentFixture<LibrariesComponent>;
|
||||
let component: LibrariesComponent;
|
||||
let contentApi: ContentApiService;
|
||||
let alfrescoApi: AlfrescoApiService;
|
||||
let router: Router;
|
||||
let page;
|
||||
let node;
|
||||
|
||||
beforeEach(() => {
|
||||
page = {
|
||||
list: {
|
||||
entries: [{ entry: { id: 1 } }, { entry: { id: 2 } }],
|
||||
pagination: { data: 'data' }
|
||||
}
|
||||
};
|
||||
|
||||
node = <any>{
|
||||
id: 'nodeId',
|
||||
path: {
|
||||
elements: []
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppTestingModule],
|
||||
declarations: [
|
||||
DataTableComponent,
|
||||
TimeAgoPipe,
|
||||
NodeNameTooltipPipe,
|
||||
NodeFavoriteDirective,
|
||||
DocumentListComponent,
|
||||
LibrariesComponent,
|
||||
AppConfigPipe,
|
||||
ExperimentalDirective
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
||||
fixture = TestBed.createComponent(LibrariesComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
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({})
|
||||
);
|
||||
|
||||
contentApi = TestBed.get(ContentApiService);
|
||||
});
|
||||
|
||||
describe('makeLibraryTooltip()', () => {
|
||||
it('maps tooltip to description', () => {
|
||||
node.description = 'description';
|
||||
const tooltip = component.makeLibraryTooltip(node);
|
||||
|
||||
expect(tooltip).toBe(node.description);
|
||||
});
|
||||
|
||||
it('maps tooltip to description', () => {
|
||||
node.title = 'title';
|
||||
const tooltip = component.makeLibraryTooltip(node);
|
||||
|
||||
expect(tooltip).toBe(node.title);
|
||||
});
|
||||
|
||||
it('sets tooltip to empty string', () => {
|
||||
const tooltip = component.makeLibraryTooltip(node);
|
||||
|
||||
expect(tooltip).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeLibraryTitle()', () => {
|
||||
it('sets title with id when duplicate nodes title exists in list', () => {
|
||||
node.title = 'title';
|
||||
|
||||
const data = new ShareDataTableAdapter(null, null);
|
||||
data.setRows([
|
||||
<any>{ node: { entry: { id: 'some-id', title: 'title' } } }
|
||||
]);
|
||||
|
||||
component.documentList.data = data;
|
||||
|
||||
const title = component.makeLibraryTitle(node);
|
||||
expect(title).toContain('nodeId');
|
||||
});
|
||||
|
||||
it('sets title when no duplicate nodes title exists in list', () => {
|
||||
node.title = 'title';
|
||||
|
||||
const data = new ShareDataTableAdapter(null, null);
|
||||
data.setRows([
|
||||
<any>{ node: { entry: { id: 'some-id', title: 'title-some-id' } } }
|
||||
]);
|
||||
|
||||
component.documentList.data = data;
|
||||
const title = component.makeLibraryTitle(node);
|
||||
|
||||
expect(title).toBe('title');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Node navigation', () => {
|
||||
let routerSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
page = {
|
||||
list: {
|
||||
entries: [ { entry: { id: 1 } }, { entry: { id: 2 } } ],
|
||||
pagination: { data: 'data'}
|
||||
}
|
||||
};
|
||||
|
||||
node = <any> {
|
||||
id: 'nodeId',
|
||||
path: {
|
||||
elements: []
|
||||
}
|
||||
};
|
||||
routerSpy = spyOn(router, 'navigate');
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ AppTestingModule ],
|
||||
declarations: [
|
||||
DataTableComponent,
|
||||
TimeAgoPipe,
|
||||
NodeNameTooltipPipe,
|
||||
NodeFavoriteDirective,
|
||||
DocumentListComponent,
|
||||
LibrariesComponent,
|
||||
AppConfigPipe,
|
||||
ExperimentalDirective
|
||||
],
|
||||
schemas: [ NO_ERRORS_SCHEMA ]
|
||||
});
|
||||
it('does not navigate when id is not passed', () => {
|
||||
component.navigate(null);
|
||||
|
||||
fixture = TestBed.createComponent(LibrariesComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
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({})));
|
||||
|
||||
contentApi = TestBed.get(ContentApiService);
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('makeLibraryTooltip()', () => {
|
||||
it('maps tooltip to description', () => {
|
||||
node.description = 'description';
|
||||
const tooltip = component.makeLibraryTooltip(node);
|
||||
it('navigates to node id', () => {
|
||||
const document = { id: 'documentId' };
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: document }));
|
||||
|
||||
expect(tooltip).toBe(node.description);
|
||||
});
|
||||
component.navigate(node.id);
|
||||
|
||||
it('maps tooltip to description', () => {
|
||||
node.title = 'title';
|
||||
const tooltip = component.makeLibraryTooltip(node);
|
||||
expect(routerSpy.calls.argsFor(0)[0]).toEqual(['./', document.id]);
|
||||
});
|
||||
});
|
||||
|
||||
expect(tooltip).toBe(node.title);
|
||||
});
|
||||
describe('navigateTo', () => {
|
||||
it('navigates into library folder', () => {
|
||||
spyOn(component, 'navigate');
|
||||
|
||||
it('sets tooltip to empty string', () => {
|
||||
const tooltip = component.makeLibraryTooltip(node);
|
||||
const site: any = {
|
||||
entry: { guid: 'node-guid' }
|
||||
};
|
||||
|
||||
expect(tooltip).toBe('');
|
||||
});
|
||||
component.navigateTo(site);
|
||||
|
||||
expect(component.navigate).toHaveBeenCalledWith('node-guid');
|
||||
});
|
||||
|
||||
describe('makeLibraryTitle()', () => {
|
||||
it('sets title with id when duplicate nodes title exists in list', () => {
|
||||
node.title = 'title';
|
||||
it(' does not navigate when library is not provided', () => {
|
||||
spyOn(component, 'navigate');
|
||||
|
||||
const data = new ShareDataTableAdapter(null, null);
|
||||
data.setRows([<any>{ node: { entry: { id: 'some-id', title: 'title' } } }]);
|
||||
component.navigateTo(null);
|
||||
|
||||
component.documentList.data = data;
|
||||
|
||||
const title = component.makeLibraryTitle(node);
|
||||
expect(title).toContain('nodeId');
|
||||
});
|
||||
|
||||
it('sets title when no duplicate nodes title exists in list', () => {
|
||||
node.title = 'title';
|
||||
|
||||
const data = new ShareDataTableAdapter(null, null);
|
||||
data.setRows([<any>{ node: { entry: { id: 'some-id', title: 'title-some-id' } } }]);
|
||||
|
||||
component.documentList.data = data;
|
||||
const title = component.makeLibraryTitle(node);
|
||||
|
||||
expect(title).toBe('title');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Node navigation', () => {
|
||||
let routerSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
routerSpy = spyOn(router, 'navigate');
|
||||
});
|
||||
|
||||
it('does not navigate when id is not passed', () => {
|
||||
component.navigate(null);
|
||||
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('navigates to node id', () => {
|
||||
const document = { id: 'documentId' };
|
||||
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: document }));
|
||||
|
||||
component.navigate(node.id);
|
||||
|
||||
expect(routerSpy.calls.argsFor(0)[0]).toEqual(['./', document.id]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigateTo', () => {
|
||||
it('navigates into library folder', () => {
|
||||
spyOn(component, 'navigate');
|
||||
|
||||
const site: any = {
|
||||
entry: { guid: 'node-guid' }
|
||||
};
|
||||
|
||||
component.navigateTo(site);
|
||||
|
||||
expect(component.navigate).toHaveBeenCalledWith('node-guid');
|
||||
});
|
||||
|
||||
it(' does not navigate when library is not provided', () => {
|
||||
spyOn(component, 'navigate');
|
||||
|
||||
component.navigateTo(null);
|
||||
|
||||
expect(component.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
expect(component.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user