[ACA-3830] Fix favorites navigation (#1599)

* fix favorites navigation

* improve report and unit test

* fix ACA test
mock version directive

* lint fix

* try different startegy

* remove first split

* fix root case
This commit is contained in:
Eugenio Romano
2020-08-14 09:13:23 +01:00
committed by GitHub
parent 3edf48f050
commit b0b22170c7
9 changed files with 131 additions and 33 deletions

View File

@@ -231,18 +231,25 @@ describe('FilesComponent', () => {
fixture.detectChanges();
});
it('should navigates to node when is more that one sub node', () => {
router.url = '/personal-files/favourites';
component.navigate(node.id);
expect(router.navigate).toHaveBeenCalledWith(['personal-files', 'favourites', node.id]);
});
it('should navigates to node when id provided', () => {
router.url = '/personal-files';
component.navigate(node.id);
expect(router.navigate).toHaveBeenCalledWith(['/personal-files', node.id]);
expect(router.navigate).toHaveBeenCalledWith(['personal-files', node.id]);
});
it('should navigates to home when id not provided', () => {
router.url = '/personal-files';
component.navigate();
expect(router.navigate).toHaveBeenCalledWith(['/personal-files']);
expect(router.navigate).toHaveBeenCalledWith(['personal-files']);
});
it('should navigate home if node is root', () => {
@@ -255,7 +262,7 @@ describe('FilesComponent', () => {
router.url = '/personal-files';
component.navigate(node.id);
expect(router.navigate).toHaveBeenCalledWith(['/personal-files']);
expect(router.navigate).toHaveBeenCalledWith(['personal-files']);
});
});

View File

@@ -123,15 +123,21 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
}
navigate(nodeId: string = null) {
const location = this.router.url.match(/.*?(?=\/|$)/g)[1];
const uuidRegEx = /[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-4[0-9A-Za-z]{3}-[89ABab][0-9A-Za-z]{3}-[0-9A-Za-z]{12}/gi;
let urlToNavigate;
const commands = [`/${location}`];
if (nodeId && !this.isRootNode(nodeId)) {
commands.push(nodeId);
if (this.router.url.match(uuidRegEx)) {
urlToNavigate = this.router.url.replace(uuidRegEx, nodeId).split('/');
urlToNavigate.shift();
} else {
urlToNavigate = this.router.url.split('/');
if (nodeId && !this.isRootNode(nodeId)) {
urlToNavigate.push(nodeId);
}
urlToNavigate.shift();
}
this.router.navigate(commands);
this.router.navigate(urlToNavigate);
}
onUploadNewVersion(ev: CustomEvent) {

View File

@@ -33,11 +33,12 @@ import {
AppConfigPipe,
UploadService
} from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { CustomResourcesService, DocumentListComponent } from '@alfresco/adf-content-services';
import { SharedFilesComponent } from './shared-files.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { Router } from '@angular/router';
import { ContentManagementService } from '../../services/content-management.service';
import { of } from 'rxjs';
describe('SharedFilesComponent', () => {
let fixture: ComponentFixture<SharedFilesComponent>;
@@ -45,6 +46,7 @@ describe('SharedFilesComponent', () => {
let alfrescoApi: AlfrescoApiService;
let page;
let uploadService: UploadService;
let customResourcesService: CustomResourcesService;
let contentManagementService: ContentManagementService;
const mockRouter = {
url: 'shared-files'
@@ -76,12 +78,14 @@ describe('SharedFilesComponent', () => {
fixture = TestBed.createComponent(SharedFilesComponent);
uploadService = TestBed.inject(UploadService);
contentManagementService = TestBed.inject(ContentManagementService);
customResourcesService = TestBed.inject(CustomResourcesService);
component = fixture.componentInstance;
alfrescoApi = TestBed.inject(AlfrescoApiService);
alfrescoApi.reset();
spyOn(alfrescoApi.sharedLinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(page));
spyOn(customResourcesService, 'loadSharedLinks').and.returnValue(of(page));
});
it('should call document list reload on linksUnshared event', fakeAsync(() => {

View File

@@ -31,6 +31,8 @@ import {
TranslationMock,
AuthenticationService,
UserPreferencesService,
DiscoveryApiService,
EcmProductVersionModel,
AppConfigService,
StorageService,
AlfrescoApiService,
@@ -53,6 +55,7 @@ import { MaterialModule } from '../material.module';
import { INITIAL_STATE } from '../store/initial-state';
import { TranslatePipeMock } from './translate-pipe.directive';
import { TranslateServiceMock } from './translation.service';
import { Observable, of } from 'rxjs';
@NgModule({
imports: [
@@ -80,6 +83,14 @@ import { TranslateServiceMock } from './translation.service';
{ provide: TranslationService, useClass: TranslationMock },
{ provide: TranslateService, useClass: TranslateServiceMock },
{ provide: TranslatePipe, useClass: TranslatePipeMock },
{
provide: DiscoveryApiService,
useValue: {
getEcmProductInfo(): Observable<EcmProductVersionModel> {
return of(new EcmProductVersionModel({ version: '10.0.0' }));
}
}
},
{
provide: AuthenticationService,
useValue: {