Browse Source

Added a test for guard.

pull/304/head
Sebastian 8 years ago
parent
commit
37363fcbe7
  1. 19
      src/Squidex/app/shared/guards/schema-must-exist-published.guard.spec.ts

19
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<SchemasState>;
let state: RouterStateSnapshot = <any>{};
let state: RouterStateSnapshot = <any>{ url: 'current-url' };
let router: IMock<Router>;
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(<SchemaDetailsDto>{ 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());
});
});
Loading…
Cancel
Save