mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
pass actual redirect when no state (#3285)
This commit is contained in:
committed by
Denys Vuika
parent
4fbacf4860
commit
f63614e964
@@ -91,6 +91,19 @@ describe('AuthGuardService BPM', () => {
|
|||||||
expect(authService.getRedirect('BPM')).toEqual(['some-url', { q: '123' }]);
|
expect(authService.getRedirect('BPM')).toEqual(['some-url', { q: '123' }]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should set redirect navigation commands with query params', async(() => {
|
||||||
|
spyOn(authService, 'setRedirect').and.callThrough();
|
||||||
|
spyOn(routerService, 'navigate').and.stub();
|
||||||
|
const router: RouterStateSnapshot = <RouterStateSnapshot> { url: '/' };
|
||||||
|
|
||||||
|
authGuard.canActivate(null, router);
|
||||||
|
|
||||||
|
expect(authService.setRedirect).toHaveBeenCalledWith({
|
||||||
|
provider: 'BPM', navigation: ['/']
|
||||||
|
});
|
||||||
|
expect(authService.getRedirect('BPM')).toEqual(['/']);
|
||||||
|
}));
|
||||||
|
|
||||||
it('should get redirect url from config if there is one configured', async(() => {
|
it('should get redirect url from config if there is one configured', async(() => {
|
||||||
appConfigService.config.loginRoute = 'fakeLoginRoute';
|
appConfigService.config.loginRoute = 'fakeLoginRoute';
|
||||||
spyOn(authService, 'setRedirect').and.callThrough();
|
spyOn(authService, 'setRedirect').and.callThrough();
|
||||||
|
@@ -60,6 +60,11 @@ export class AuthGuardBpm implements CanActivate, CanActivateChild {
|
|||||||
private getNavigationCommands(redirectUrl: string): any[] {
|
private getNavigationCommands(redirectUrl: string): any[] {
|
||||||
const urlTree: UrlTree = this.router.parseUrl(redirectUrl);
|
const urlTree: UrlTree = this.router.parseUrl(redirectUrl);
|
||||||
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
||||||
|
|
||||||
|
if (!urlSegmentGroup) {
|
||||||
|
return [redirectUrl];
|
||||||
|
}
|
||||||
|
|
||||||
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
|
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
|
||||||
|
|
||||||
return urlSegments.reduce(function(acc, item) {
|
return urlSegments.reduce(function(acc, item) {
|
||||||
|
@@ -235,6 +235,28 @@ describe('AuthGuardService ECM', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with no route state', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
this.test = new TestConfig({
|
||||||
|
isLoggedIn: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const { guard, auth, router } = this.test;
|
||||||
|
|
||||||
|
guard.canActivate(null, { url: '/' }).then((activate) => {
|
||||||
|
this.auth = auth;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.navigateSpy = spyOn(router, 'navigate');
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should set redirect navigation commands with query params', () => {
|
||||||
|
expect(this.auth.setRedirect).toHaveBeenCalledWith({
|
||||||
|
provider: 'ECM', navigation: ['/']
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('canActivateChild', () => {
|
describe('canActivateChild', () => {
|
||||||
|
@@ -75,6 +75,11 @@ export class AuthGuardEcm implements CanActivate {
|
|||||||
private getNavigationCommands(redirectUrl: string): any[] {
|
private getNavigationCommands(redirectUrl: string): any[] {
|
||||||
const urlTree: UrlTree = this.router.parseUrl(redirectUrl);
|
const urlTree: UrlTree = this.router.parseUrl(redirectUrl);
|
||||||
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
||||||
|
|
||||||
|
if (!urlSegmentGroup) {
|
||||||
|
return [redirectUrl];
|
||||||
|
}
|
||||||
|
|
||||||
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
|
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
|
||||||
|
|
||||||
return urlSegments.reduce(function(acc, item) {
|
return urlSegments.reduce(function(acc, item) {
|
||||||
|
@@ -101,4 +101,17 @@ describe('AuthGuardService', () => {
|
|||||||
});
|
});
|
||||||
expect(router.navigate).toHaveBeenCalledWith(['/fakeLoginRoute']);
|
expect(router.navigate).toHaveBeenCalledWith(['/fakeLoginRoute']);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should pass actual redirect when no state segments exists', async(() => {
|
||||||
|
state.url = '/';
|
||||||
|
|
||||||
|
spyOn(router, 'navigate');
|
||||||
|
spyOn(authService, 'setRedirect');
|
||||||
|
|
||||||
|
service.canActivate(null, state);
|
||||||
|
|
||||||
|
expect(authService.setRedirect).toHaveBeenCalledWith({
|
||||||
|
provider: 'ALL', navigation: ['/']
|
||||||
|
});
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
@@ -63,6 +63,11 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
|||||||
private getNavigationCommands(redirectUrl: string): any[] {
|
private getNavigationCommands(redirectUrl: string): any[] {
|
||||||
const urlTree: UrlTree = this.router.parseUrl(redirectUrl);
|
const urlTree: UrlTree = this.router.parseUrl(redirectUrl);
|
||||||
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
const urlSegmentGroup: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
||||||
|
|
||||||
|
if (!urlSegmentGroup) {
|
||||||
|
return [redirectUrl];
|
||||||
|
}
|
||||||
|
|
||||||
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
|
const urlSegments: UrlSegment[] = urlSegmentGroup.segments;
|
||||||
|
|
||||||
return urlSegments.reduce(function(acc, item) {
|
return urlSegments.reduce(function(acc, item) {
|
||||||
|
Reference in New Issue
Block a user