mirror of https://github.com/Squidex/squidex.git
10 changed files with 134 additions and 14 deletions
@ -0,0 +1,27 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Sebastian Stehle. All rights reserved |
|||
*/ |
|||
|
|||
import { CanDeactivateGuard } from './can-deactivate.guard'; |
|||
|
|||
describe('CanDeactivateGuard', () => { |
|||
it('should call component', () => { |
|||
let called = false; |
|||
|
|||
const component = { |
|||
canDeactivate: () => { |
|||
called = true; |
|||
|
|||
return true; |
|||
} |
|||
}; |
|||
|
|||
const result = new CanDeactivateGuard().canDeactivate(component); |
|||
|
|||
expect(result).toBeTruthy(); |
|||
expect(called).toBeTruthy(); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,21 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Sebastian Stehle. All rights reserved |
|||
*/ |
|||
|
|||
import { Injectable } from '@angular/core'; |
|||
import { CanDeactivate } from '@angular/router'; |
|||
import { Observable } from 'rxjs/Observable'; |
|||
|
|||
export interface CanComponentDeactivate { |
|||
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean; |
|||
} |
|||
|
|||
@Injectable() |
|||
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> { |
|||
public canDeactivate(component: CanComponentDeactivate) { |
|||
return component.canDeactivate ? component.canDeactivate() : true; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue