Example #1
0
 it('should normalize strip a trailing slash', () => {
   const input = baseUrl + '/';
   expect(Location.stripTrailingSlash(input)).toBe(baseUrl);
 });
 isNotHome() {
   return this.location.path() !== '';
 }
 public getClass(primaryOption, defaultOption, prefixToCheck) {
     return this._location.path().startsWith(prefixToCheck) ? primaryOption : defaultOption;
 }
 public goBack(): void {
   this.location.back();
 }
Example #5
0
 (router: Router, location: Location, tcb: TestComponentBuilder) => {
   tcb.createFakeAsync(MyApp);
   router.navigate(['/']);
   tick();
   expect(location.path()).toBe('');
 })
Example #6
0
 getLinkStyle(path) {
     return this.location.path().indexOf(path) > -1;
 }
 .subscribe( resp => {
     this.location.back();
 } );
 constructor(public authenticationService: AuthenticationService, private _location: Location) {
    
     _location.go('/home');
 }
 ngOnInit() {
     this.location.go('/');
 }
describe('SignupComponent', () => {

  @Component({
    template: `<mpt-signup></mpt-signup><router-outlet></router-outlet>`,
    directives: [SignupComponent, ROUTER_DIRECTIVES],
  })
  class TestComponent {
  }

  @Component({
    template: ``,
  })
  class BlankComponent {
  }

  let fixture:ComponentFixture<any>;
  let cmpDebugElement:DebugElement;

  let loginService:LoginService;
  let backend:MockBackend;
  let router:Router;
  let location:Location;

  beforeEach(() => addProviders([
    provideFakeRouter(TestComponent, [
      {
        path: 'home',
        component: BlankComponent,
      },
    ]),
    APP_TEST_PROVIDERS,
  ]));
  beforeEach(inject([LoginService, MockBackend, Router, Location], (..._) => {
    [loginService, backend, router, location] = _;
  }));
  beforeEach(async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
    tcb
      .createAsync(TestComponent)
      .then((_fixture:ComponentFixture<any>) => {
        fixture = _fixture;
        cmpDebugElement = _fixture.debugElement.query(By.directive(SignupComponent));
        _fixture.detectChanges();
      });
  })));

  it('can be shown', () => {
    expect(cmpDebugElement).toBeTruthy();
  });

  it('can validate inputs', () => {
    const page:SignupComponent = cmpDebugElement.componentInstance;
    page.name.updateValue('a', {});
    page.email.updateValue('b', {});
    page.password.updateValue('c', {});
    page.passwordConfirmation.updateValue('d', {});
    expect(page.myForm.valid).toBeFalsy();
    page.name.updateValue('akira', {});
    page.email.updateValue('test@test.com', {});
    page.password.updateValue('secret123', {});
    page.passwordConfirmation.updateValue('secret123', {});
    expect(page.myForm.valid).toBeTruthy();
  });

  it('can signup', fakeAsync(() => {
    const page:SignupComponent = cmpDebugElement.componentInstance;
    spyOn(loginService, 'login').and.callThrough();
    backend.connections.subscribe(conn => {
      conn.mockRespond(new Response(new BaseResponseOptions()));
    });
    page.onSubmit({
      email: 'test@test.com',
      password: 'secret',
      name: 'akira',
    });
    expect(loginService.login).toHaveBeenCalledWith('test@test.com', 'secret');
    advance(fixture);
    expect(location.path()).toEqual('/home');
  }));

});
 isActive(path: string) {
   return (this.loc.path() || '/') === path;
 }
Example #12
0
 it('should not remove slashes after a pound sign', () => {
   const input = baseUrl + '#test/?=3';
   expect(Location.stripTrailingSlash(input)).toBe(input);
 });
Example #13
0
 it('should not remove slashes inside query params', () => {
   const input = baseUrl + '?test/?=3';
   expect(Location.stripTrailingSlash(input)).toBe(input);
 });
Example #14
0
 it('should ignore query params when stripping a slash', () => {
   const input = baseUrl + '/?param=1';
   expect(Location.stripTrailingSlash(input)).toBe(baseUrl + '?param=1');
 });
 fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
   TestBed.createComponent(MyApp);
   router.navigateByUrl('/about');
   tick();
   expect(location.path()).toEqual('/about');
 })
 //Checks if the route is "/courses".
 public addSessionHidden() {
   let list = ["/courses"],
       route = this.location.path();
   return (list.indexOf(route) > -1);
 }
	back()
	{
		this.location.back();		
	}
Example #18
0
 isActive(segment): boolean {
   return this.location.path().endsWith(segment);
 }
Example #19
0
 isActive(path:string):boolean {
   return this.location.path().split('?')[0] === path;
 }
describe('LoginComponent', () => {

  @Component({
    template: `<mpt-login></mpt-login><router-outlet></router-outlet>`,
    directives: [LoginComponent, ROUTER_DIRECTIVES],
  })
  class TestComponent {
  }

  @Component({
    template: ``,
  })
  class BlankComponent {
  }

  let cmpDebugElement:DebugElement;

  let fixture:ComponentFixture<any>;
  let loginService:LoginService;
  let backend:MockBackend;
  let router:Router;
  let location:Location;

  beforeEach(() => addProviders([
    provideFakeRouter(TestComponent, [
      {path: 'home', component: BlankComponent},
    ]),
    ...APP_TEST_PROVIDERS,
  ]));
  beforeEach(inject([LoginService, MockBackend, Router, Location], (..._) => {
    [loginService, backend, router, location] = _;
  }));
  beforeEach(async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
    tcb
      .createAsync(TestComponent)
      .then((_fixture:ComponentFixture<any>) => {
        fixture = _fixture;
        cmpDebugElement = _fixture.debugElement.query(By.directive(LoginComponent));
        _fixture.detectChanges();
      });
  })));

  it('can be shown', () => {
    expect(cmpDebugElement).toBeTruthy();
  });

  it('can login', fakeAsync(() => {
    const cmp:LoginComponent = cmpDebugElement.componentInstance;
    spyOn(loginService, 'login').and.callThrough();
    backend.connections.subscribe(conn => {
      conn.mockRespond(new Response(new BaseResponseOptions()));
    });
    cmp.login('test@test.com', 'secret');
    expect(loginService.login).toHaveBeenCalledWith('test@test.com', 'secret');
    advance(fixture);
    expect(location.path()).toEqual('/home');
  }));

  it('can navigate to signup page', () => {
    const el = cmpDebugElement.nativeElement;
    const signupLink = getDOM().querySelector(el, 'a');
    expect(signupLink.getAttribute('href')).toEqual('/signup');
  });

});
Example #21
0
 this.router.subscribe(() => {
     this.activeView = this.location.path();
 });
 goback(): void {
     this._location.back();
 }
 .subscribe(() => {
   ga('send', {hitType: 'pageview', page: this.location.path()});
 });
 goBack():void {
   this.location.back();   
  //this.projectsComponent.setSelected(this.project);    
 }
Example #25
0
 (router: Router, location: Location, tcb: TestComponentBuilder) => {
   tcb.createFakeAsync(MyApp);
   router.navigateByUrl('/about');
   tick();
   expect(location.path()).toEqual('/about');
 })
Example #26
0
 this.authService.subscribe((val) => {
     if (val.authenticated) {
         this.location.replaceState('/');
         this.router.navigateByUrl('protected');
     }
 });
Example #27
0
 function assertUrl(path: any /** TODO #9100 */) { expect(location.path()).toEqual(path); }
 fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
   TestBed.createComponent(MyApp);
   router.navigate(['/']);
   tick();
   expect(location.path()).toBe('/');
 })
 back(): void {
     this.location.back();
 }
Example #30
0
 it('should strip single character slash', () => {
   const input = '/';
   expect(Location.stripTrailingSlash(input)).toBe('');
 });