mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
content api service (#455)
* introduce content-api service * upgrade files component * upgrade directives * upgrade directives * update directives * fix profile resolver call ordering issue * fix reducer * update services * extra apis * update about page * update preview component * code updates
This commit is contained in:
committed by
Cilibiu Bogdan
parent
ac6e96530f
commit
af547aac31
@@ -25,13 +25,14 @@
|
||||
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
|
||||
import { AlfrescoApiService, UserPreferencesService, AppConfigPipe, NodeFavoriteDirective } from '@alfresco/adf-core';
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { UserPreferencesService, AppConfigPipe, NodeFavoriteDirective } from '@alfresco/adf-core';
|
||||
import { PreviewComponent } from './preview.component';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
import { NodeEffects } from '../../store/effects/node.effects';
|
||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||
import { ContentApiService } from '../../services/content-api.service';
|
||||
|
||||
describe('PreviewComponent', () => {
|
||||
|
||||
@@ -39,10 +40,10 @@ describe('PreviewComponent', () => {
|
||||
let component: PreviewComponent;
|
||||
let router: Router;
|
||||
let route: ActivatedRoute;
|
||||
let alfrescoApi: AlfrescoApiService;
|
||||
let preferences: UserPreferencesService;
|
||||
let contentApi: ContentApiService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
AppTestingModule,
|
||||
@@ -54,18 +55,16 @@ describe('PreviewComponent', () => {
|
||||
NodeFavoriteDirective
|
||||
],
|
||||
schemas: [ NO_ERRORS_SCHEMA ]
|
||||
})
|
||||
.compileComponents().then(() => {
|
||||
fixture = TestBed.createComponent(PreviewComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
router = TestBed.get(Router);
|
||||
route = TestBed.get(ActivatedRoute);
|
||||
alfrescoApi = TestBed.get(AlfrescoApiService);
|
||||
alfrescoApi.reset();
|
||||
preferences = TestBed.get(UserPreferencesService);
|
||||
});
|
||||
}));
|
||||
|
||||
fixture = TestBed.createComponent(PreviewComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
router = TestBed.get(Router);
|
||||
route = TestBed.get(ActivatedRoute);
|
||||
preferences = TestBed.get(UserPreferencesService);
|
||||
contentApi = TestBed.get(ContentApiService);
|
||||
});
|
||||
|
||||
it('should extract the property path root', () => {
|
||||
expect(component.getRootField('some.property.path')).toBe('some');
|
||||
@@ -339,35 +338,33 @@ describe('PreviewComponent', () => {
|
||||
|
||||
it('should not display node when id is missing', async () => {
|
||||
spyOn(router, 'navigate').and.stub();
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeInfo').and.returnValue(
|
||||
Promise.resolve(null)
|
||||
spyOn(contentApi, 'getNodeInfo').and.returnValue(
|
||||
Observable.of(null)
|
||||
);
|
||||
|
||||
await component.displayNode(null);
|
||||
|
||||
expect(alfrescoApi.nodesApi.getNodeInfo).not.toHaveBeenCalled();
|
||||
expect(contentApi.getNodeInfo).not.toHaveBeenCalled();
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should navigate to original location if node not found', async () => {
|
||||
spyOn(router, 'navigate').and.stub();
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeInfo').and.returnValue(
|
||||
Promise.resolve(null)
|
||||
spyOn(contentApi, 'getNodeInfo').and.returnValue(
|
||||
Observable.of(null)
|
||||
);
|
||||
|
||||
component.previewLocation = 'personal-files';
|
||||
await component.displayNode('folder1');
|
||||
|
||||
expect(alfrescoApi.nodesApi.getNodeInfo).toHaveBeenCalledWith(
|
||||
'folder1', { include: [ 'allowableOperations' ] }
|
||||
);
|
||||
expect(contentApi.getNodeInfo).toHaveBeenCalledWith('folder1');
|
||||
expect(router.navigate).toHaveBeenCalledWith(['personal-files', 'folder1']);
|
||||
});
|
||||
|
||||
it('should navigate to original location if node is not a File', async () => {
|
||||
spyOn(router, 'navigate').and.stub();
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeInfo').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getNodeInfo').and.returnValue(
|
||||
Observable.of({
|
||||
isFile: false
|
||||
})
|
||||
);
|
||||
@@ -375,31 +372,27 @@ describe('PreviewComponent', () => {
|
||||
component.previewLocation = 'personal-files';
|
||||
await component.displayNode('folder1');
|
||||
|
||||
expect(alfrescoApi.nodesApi.getNodeInfo).toHaveBeenCalledWith(
|
||||
'folder1', { include: [ 'allowableOperations' ] }
|
||||
);
|
||||
expect(contentApi.getNodeInfo).toHaveBeenCalledWith('folder1');
|
||||
expect(router.navigate).toHaveBeenCalledWith(['personal-files', 'folder1']);
|
||||
});
|
||||
|
||||
it('should navigate to original location in case of Alfresco API errors', async () => {
|
||||
spyOn(router, 'navigate').and.stub();
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeInfo').and.returnValue(
|
||||
Promise.reject('error')
|
||||
spyOn(contentApi, 'getNodeInfo').and.returnValue(
|
||||
Observable.throw('error')
|
||||
);
|
||||
|
||||
component.previewLocation = 'personal-files';
|
||||
await component.displayNode('folder1');
|
||||
|
||||
expect(alfrescoApi.nodesApi.getNodeInfo).toHaveBeenCalledWith(
|
||||
'folder1', { include: [ 'allowableOperations' ] }
|
||||
);
|
||||
expect(contentApi.getNodeInfo).toHaveBeenCalledWith('folder1');
|
||||
expect(router.navigate).toHaveBeenCalledWith(['personal-files', 'folder1']);
|
||||
});
|
||||
|
||||
it('should navigate to original location in case of internal errors', async () => {
|
||||
spyOn(router, 'navigate').and.stub();
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeInfo').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getNodeInfo').and.returnValue(
|
||||
Observable.of({
|
||||
isFile: true
|
||||
})
|
||||
);
|
||||
@@ -410,17 +403,15 @@ describe('PreviewComponent', () => {
|
||||
component.previewLocation = 'personal-files';
|
||||
await component.displayNode('folder1');
|
||||
|
||||
expect(alfrescoApi.nodesApi.getNodeInfo).toHaveBeenCalledWith(
|
||||
'folder1', { include: [ 'allowableOperations' ] }
|
||||
);
|
||||
expect(contentApi.getNodeInfo).toHaveBeenCalledWith('folder1');
|
||||
expect(router.navigate).toHaveBeenCalledWith(['personal-files', 'folder1']);
|
||||
});
|
||||
|
||||
it('should setup node for displaying', async () => {
|
||||
spyOn(router, 'navigate').and.stub();
|
||||
spyOn(component, 'getNearestNodes').and.returnValue({ left: 'node1', right: 'node3' });
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeInfo').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getNodeInfo').and.returnValue(
|
||||
Observable.of({
|
||||
id: 'node2',
|
||||
parentId: 'parent1',
|
||||
isFile: true
|
||||
@@ -439,8 +430,8 @@ describe('PreviewComponent', () => {
|
||||
preferences.set('personal-files.sorting.key', 'name');
|
||||
preferences.set('personal-files.sorting.direction', 'desc');
|
||||
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeChildren').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getNodeChildren').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { id: 'node1', name: 'node 1' } },
|
||||
@@ -458,8 +449,8 @@ describe('PreviewComponent', () => {
|
||||
preferences.set('personal-files.sorting.key', 'missing');
|
||||
preferences.set('personal-files.sorting.direction', 'desc');
|
||||
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeChildren').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getNodeChildren').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { id: 'node1', name: 'node 1' } },
|
||||
@@ -481,8 +472,8 @@ describe('PreviewComponent', () => {
|
||||
it('should sort file ids for personal-files with [modifiedAt desc]', async () => {
|
||||
spyOn(preferences, 'get').and.returnValue(null);
|
||||
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeChildren').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getNodeChildren').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { id: 'node1', name: 'node 1', modifiedAt: 1 } },
|
||||
@@ -500,8 +491,8 @@ describe('PreviewComponent', () => {
|
||||
preferences.set('personal-files.sorting.key', 'name');
|
||||
preferences.set('personal-files.sorting.direction', 'desc');
|
||||
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeChildren').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getNodeChildren').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { id: 'node1', name: 'node 1' } },
|
||||
@@ -523,8 +514,8 @@ describe('PreviewComponent', () => {
|
||||
it('should sort file ids for libraries with [modifiedAt desc]', async () => {
|
||||
spyOn(preferences, 'get').and.returnValue(null);
|
||||
|
||||
spyOn(alfrescoApi.nodesApi, 'getNodeChildren').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getNodeChildren').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { id: 'node1', name: 'node 1', modifiedAt: new Date(1) } },
|
||||
@@ -542,8 +533,8 @@ describe('PreviewComponent', () => {
|
||||
preferences.set('favorites.sorting.key', 'name');
|
||||
preferences.set('favorites.sorting.direction', 'desc');
|
||||
|
||||
spyOn(alfrescoApi.favoritesApi, 'getFavorites').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getFavorites').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { target: { file: { id: 'file3', name: 'file 3' } } } },
|
||||
@@ -561,8 +552,8 @@ describe('PreviewComponent', () => {
|
||||
it('should sort file ids for favorites with [modifiedAt desc]', async () => {
|
||||
spyOn(preferences, 'get').and.returnValue(null);
|
||||
|
||||
spyOn(alfrescoApi.favoritesApi, 'getFavorites').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getFavorites').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { target: { file: { id: 'file3', modifiedAt: new Date(3) } } } },
|
||||
@@ -581,8 +572,8 @@ describe('PreviewComponent', () => {
|
||||
preferences.set('shared.sorting.key', 'name');
|
||||
preferences.set('shared.sorting.direction', 'asc');
|
||||
|
||||
spyOn(alfrescoApi.sharedLinksApi, 'findSharedLinks').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'findSharedLinks').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { nodeId: 'node2', name: 'node 2', modifiedAt: new Date(2) } },
|
||||
@@ -599,8 +590,8 @@ describe('PreviewComponent', () => {
|
||||
it('should sort file ids for favorites with [modifiedAt desc]', async () => {
|
||||
spyOn(preferences, 'get').and.returnValue(null);
|
||||
|
||||
spyOn(alfrescoApi.sharedLinksApi, 'findSharedLinks').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'findSharedLinks').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { nodeId: 'node2', name: 'node 2', modifiedAt: new Date(2) } },
|
||||
@@ -618,14 +609,14 @@ describe('PreviewComponent', () => {
|
||||
preferences.set('recent-files.sorting.key', 'name');
|
||||
preferences.set('recent-files.sorting.direction', 'asc');
|
||||
|
||||
spyOn(alfrescoApi.peopleApi, 'getPerson').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getPerson').and.returnValue(
|
||||
Observable.of({
|
||||
entry: { id: 'user' }
|
||||
})
|
||||
);
|
||||
|
||||
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'search').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { id: 'node2', name: 'node 2', modifiedAt: new Date(2) } },
|
||||
@@ -642,14 +633,14 @@ describe('PreviewComponent', () => {
|
||||
it('should sort file ids for favorites with [modifiedAt desc]', async () => {
|
||||
spyOn(preferences, 'get').and.returnValue(null);
|
||||
|
||||
spyOn(alfrescoApi.peopleApi, 'getPerson').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'getPerson').and.returnValue(
|
||||
Observable.of({
|
||||
entry: { id: 'user' }
|
||||
})
|
||||
);
|
||||
|
||||
spyOn(alfrescoApi.searchApi, 'search').and.returnValue(
|
||||
Promise.resolve({
|
||||
spyOn(contentApi, 'search').and.returnValue(
|
||||
Observable.of({
|
||||
list: {
|
||||
entries: [
|
||||
{ entry: { id: 'node2', name: 'node 2', modifiedAt: new Date(2) } },
|
||||
|
Reference in New Issue
Block a user