From 37363fcbe77419c679cad701a866f0e926b11987 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 27 Jun 2018 19:42:08 +0200 Subject: [PATCH] Added a test for guard. --- .../schema-must-exist-published.guard.spec.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Squidex/app/shared/guards/schema-must-exist-published.guard.spec.ts b/src/Squidex/app/shared/guards/schema-must-exist-published.guard.spec.ts index 41f2c1b6a..b5c10375a 100644 --- a/src/Squidex/app/shared/guards/schema-must-exist-published.guard.spec.ts +++ b/src/Squidex/app/shared/guards/schema-must-exist-published.guard.spec.ts @@ -9,6 +9,8 @@ import { Router, RouterStateSnapshot } from '@angular/router'; import { of } from 'rxjs'; import { IMock, Mock, Times } from 'typemoq'; +import { MathHelper } from '@app/framework'; + import { SchemaDetailsDto } from './../services/schemas.service'; import { SchemasState } from './../state/schemas.state'; import { SchemaMustExistPublishedGuard } from './schema-must-exist-published.guard'; @@ -21,7 +23,7 @@ describe('SchemaMustExistPublishedGuard', () => { }; let schemasState: IMock; - let state: RouterStateSnapshot = {}; + let state: RouterStateSnapshot = { url: 'current-url' }; let router: IMock; let schemaGuard: SchemaMustExistPublishedGuard; @@ -75,4 +77,19 @@ describe('SchemaMustExistPublishedGuard', () => { router.verify(x => x.navigate(['/404']), Times.once()); }); + + it('should redirect to content when singleton', () => { + schemasState.setup(x => x.select('123')) + .returns(() => of({ isSingleton: true })); + + let result: boolean; + + schemaGuard.canActivate(route, state).subscribe(x => { + result = x; + }).unsubscribe(); + + expect(result!).toBeFalsy(); + + router.verify(x => x.navigate([state.url, MathHelper.EMPTY_GUID]), Times.once()); + }); }); \ No newline at end of file