-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add confirmation dialog when leaving logbook/:id
Should close: #131
- Loading branch information
Showing
9 changed files
with
87 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
scilog/src/app/logbook/core/navigation-guard-service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { NavigationGuardService } from './navigation-guard-service'; | ||
import { LogbookInfoService } from 'src/app/core/logbook-info.service'; | ||
|
||
describe('CanDeactivateGuard', () => { | ||
let service: NavigationGuardService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
NavigationGuardService, | ||
{ provide: LogbookInfoService, useValue: { logbookInfo: { id: 'id' } } } | ||
] | ||
}); | ||
service = TestBed.inject(NavigationGuardService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should return true on back', () => { | ||
spyOn(window, 'confirm').and.returnValue(true); | ||
expect(service.canDeactivate({canDeactivate: () => false})).toBeTrue(); | ||
}); | ||
|
||
it('should return false on back', () => { | ||
spyOn(window, 'confirm').and.returnValue(false); | ||
expect(service.canDeactivate({canDeactivate: () => false})).toBeFalse(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { CanDeactivate } from '@angular/router'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
|
||
export interface ComponentCanDeactivate { | ||
canDeactivate: () => boolean | Observable<boolean>; | ||
} | ||
|
||
@Injectable() | ||
export class NavigationGuardService implements CanDeactivate<ComponentCanDeactivate> { | ||
|
||
canDeactivate(component: ComponentCanDeactivate): boolean | Observable<boolean> { | ||
return component.canDeactivate() || confirm('You are about to leave the page. Do you want to continue?'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters