diff --git a/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts
index c1d324620d..9dff7425a0 100644
--- a/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts
+++ b/npm/ng-packs/packages/core/src/lib/tests/permission.directive.spec.ts
@@ -43,4 +43,26 @@ describe('PermissionDirective', () => {
expect(spy.mock.calls).toHaveLength(0);
});
});
+
+ describe('structural', () => {
+ beforeEach(() => {
+ spectator = createDirective(`
Testing Permission Directive
`);
+ directive = spectator.directive;
+ });
+
+ it('should be created', () => {
+ expect(directive).toBeTruthy();
+ });
+
+ it('should remove the element from DOM', () => {
+ expect(spectator.query('#test-element')).toBeFalsy();
+ grantedPolicy$.next(true);
+ expect(spectator.query('#test-element')).toBeTruthy();
+ grantedPolicy$.next(false);
+ expect(spectator.query('#test-element')).toBeFalsy();
+ grantedPolicy$.next(true);
+ grantedPolicy$.next(true);
+ expect(spectator.queryAll('#test-element')).toHaveLength(1);
+ });
+ });
});
diff --git a/npm/ng-packs/packages/core/src/lib/tests/permission.guard.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/permission.guard.spec.ts
index b358005837..a995a4c822 100644
--- a/npm/ng-packs/packages/core/src/lib/tests/permission.guard.spec.ts
+++ b/npm/ng-packs/packages/core/src/lib/tests/permission.guard.spec.ts
@@ -23,7 +23,7 @@ describe('PermissionGuard', () => {
it('should return true when the grantedPolicy is true', done => {
store.select.andReturn(of(true));
const spy = jest.spyOn(store, 'dispatch');
- guard.canActivate({ data: { requiredPolicy: '' } } as any).subscribe(res => {
+ guard.canActivate({ data: { requiredPolicy: 'test' } } as any, null).subscribe(res => {
expect(res).toBe(true);
expect(spy.mock.calls).toHaveLength(0);
done();
@@ -33,11 +33,25 @@ describe('PermissionGuard', () => {
it('should return false and dispatch RestOccurError when the grantedPolicy is false', done => {
store.select.andReturn(of(false));
const spy = jest.spyOn(store, 'dispatch');
- guard.canActivate({ data: { requiredPolicy: '' } } as any).subscribe(res => {
+ guard.canActivate({ data: { requiredPolicy: 'test' } } as any, null).subscribe(res => {
expect(res).toBe(false);
expect(spy.mock.calls[0][0] instanceof RestOccurError).toBeTruthy();
expect((spy.mock.calls[0][0] as RestOccurError).payload).toEqual({ status: 403 });
done();
});
});
+
+ it('should find the requiredPolicy from child route', done => {
+ store.select.andReturn(of(false));
+ const spy = jest.spyOn(store, 'select');
+ guard
+ .canActivate(
+ { data: {}, routeConfig: { children: [{ path: 'test', data: { requiredPolicy: 'TestPolicy' } }] } } as any,
+ { url: 'test' } as any,
+ )
+ .subscribe(() => {
+ expect(spy.mock.calls[0][0]({ auth: { grantedPolicies: { TestPolicy: true } } })).toBe(true);
+ done();
+ });
+ });
});