canActivateChild implementation (#2691)

This commit is contained in:
Cilibiu Bogdan
2017-11-22 12:07:27 +02:00
committed by Eugenio Romano
parent 4fbd9f5d62
commit 39737b3df6
2 changed files with 62 additions and 0 deletions

View File

@@ -214,4 +214,62 @@ describe('CanActivateLoggedIn', () => {
expect(this.auth.setRedirectUrl).toHaveBeenCalledWith('some-url'); expect(this.auth.setRedirectUrl).toHaveBeenCalledWith('some-url');
}); });
}); });
describe('canActivateChild', () => {
describe('user is not logged in', () => {
beforeEach(async(() => {
this.test = new TestConfig({
isLoggedIn: false
});
const { guard } = this.test;
guard.canActivateChild(null, { url: '' }).then((activate) => {
this.activate = activate;
});
}));
it('should not allow route to activate', () => {
expect(this.activate).toBe(false);
});
});
describe('user is logged in but ticket is invalid', () => {
beforeEach(async(() => {
this.test = new TestConfig({
isLoggedIn: true,
validateTicket: false
});
const { guard } = this.test;
guard.canActivateChild(null, { url: '' }).then((activate) => {
this.activate = activate;
});
}));
it('should not allow route to activate', () => {
expect(this.activate).toBe(false);
});
});
describe('user is logged in and ticket is valid', () => {
beforeEach(async(() => {
this.test = new TestConfig({
isLoggedIn: true,
validateTicket: true
});
const { guard } = this.test;
guard.canActivateChild(null, { url: '' }).then((activate) => {
this.activate = activate;
});
}));
it('should allow route to activate', () => {
expect(this.activate).toBe(true);
});
});
});
}); });

View File

@@ -43,6 +43,10 @@ export class AuthGuardEcm implements CanActivate {
.catch(() => false); .catch(() => false);
} }
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
return this.canActivate(route, state);
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
return this.isLoggedIn().then(isLoggedIn => { return this.isLoggedIn().then(isLoggedIn => {