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
export function MyDecorator(target: any) { | |
// save a reference to the original constructor | |
var original = target; | |
// a utility function to generate instances of a class | |
function construct(constructor, args) { | |
let c: any = () => { | |
return constructor.apply(this, args); | |
}; | |
c.prototype = constructor.prototype; |
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
import { Injectable } from '@angular/core'; | |
import { environment } from '@environments/environment'; | |
/** | |
* Class of static methods to allow for consistent console logging. | |
* @export | |
*/ | |
@Injectable({ | |
providedIn: 'root' |
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
import { Logger } from './logger'; | |
import { environment } from '@environments/environment'; | |
describe('Logger Spec', () => { | |
let debug; | |
let info; | |
let warn; | |
let err; | |
let log; |
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
import { TestBed } from '@angular/core/testing'; | |
import { CanDeactivateGuardService } from './can-deactivate-guard.service'; | |
import { CanDeactivate } from '@angular/router'; | |
import { Observable, Subject } from 'rxjs'; | |
import { CanDeactivateGuarded } from './can-deactivate-guarded'; | |
class MockComponent implements CanDeactivateGuarded { | |
// Set this to the value you want to mock being returned from GuardedComponent | |
returnValue: boolean | Observable<boolean>; |
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
import { CanDeactivate } from '@angular/router'; | |
import { Component } from '@angular/core'; | |
import { Observable } from 'rxjs'; | |
export interface CanDeactivateGuarded { | |
canDeactivate: () => boolean | Observable<boolean>; | |
} |
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
class MockComponent implements CanDeactivateGuarded { | |
// Set this to the value you want to mock being returned from GuardedComponent | |
returnValue: boolean | Observable<boolean>; | |
canDeactivate(): boolean | Observable<boolean> { | |
return this.returnValue; | |
} | |
} |
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
import { Injectable } from '@angular/core'; | |
import { CanDeactivate } from '@angular/router'; | |
import { GuardedComponent } from './guarded/guarded.component'; | |
import { CanDeactivateGuarded } from './can-deactivate-guarded'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class CanDeactivateGuardService implements CanDeactivate<CanDeactivateGuarded> { | |
canDeactivate(component: CanDeactivateGuarded) { |
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
describe('CanDeactivateGuardService', () => { | |
let mockComponent: MockComponent; | |
let service: CanDeactivateGuardService; | |
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
providers: [ | |
CanDeactivateGuardService, | |
MockComponent | |
] |
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
it('can route if unguarded', () => { | |
// Mock GuardedComponent.isGuarded = false, which returns true from canActivate() | |
mockComponent.returnValue = true; | |
expect(service.canDeactivate(mockComponent)).toBeTruthy(); | |
}); | |
it('will route if guarded and user accepted the dialog', () => { | |
// Mock the behavior of the GuardedComponent: | |
const subject$ = new Subject<boolean>(); | |
mockComponent.returnValue = subject$.asObservable(); |
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
app-root { | |
padding: 1em; | |
box-sizing: border-box; | |
height: 100vh; | |
width: 100vw; | |
display: grid; | |
grid-gap: 1em; | |
grid-template-columns: 1fr 1fr 1fr; | |
grid-template-rows: 1fr; | |
grid-template-areas: 'blue green purple'; |
OlderNewer