Use DOCUMENT from angular/common, Ref: #347

This commit is contained in:
ziajka 2019-03-22 13:43:53 +01:00
parent 038f3682eb
commit ddf2db7df6
2 changed files with 14 additions and 5 deletions

View File

@ -6,7 +6,8 @@ import { ServerService } from '../../services/server.service';
import { MockedServerService } from '../../services/server.service.spec'; import { MockedServerService } from '../../services/server.service.spec';
import { Server } from '../../models/server'; import { Server } from '../../models/server';
describe('LocalServerComponent', () => {
fdescribe('LocalServerComponent', () => {
let component: LocalServerComponent; let component: LocalServerComponent;
let fixture: ComponentFixture<LocalServerComponent>; let fixture: ComponentFixture<LocalServerComponent>;
let router: any; let router: any;
@ -24,7 +25,8 @@ describe('LocalServerComponent', () => {
spyOn(serverService, 'getLocalServer').and.returnValue(Promise.resolve(server)); spyOn(serverService, 'getLocalServer').and.returnValue(Promise.resolve(server));
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [{ provide: Router, useValue: router }, { provide: ServerService, useValue: serverService }], providers: [{ provide: Router, useValue: router },
{ provide: ServerService, useValue: serverService }],
declarations: [LocalServerComponent] declarations: [LocalServerComponent]
}).compileComponents(); }).compileComponents();

View File

@ -1,8 +1,9 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, Inject } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ServerService } from '../../services/server.service'; import { ServerService } from '../../services/server.service';
import { Server } from '../../models/server'; import { Server } from '../../models/server';
import { DOCUMENT } from '@angular/common';
@Component({ @Component({
selector: 'app-local-server', selector: 'app-local-server',
@ -10,10 +11,16 @@ import { Server } from '../../models/server';
styleUrls: ['./local-server.component.scss'] styleUrls: ['./local-server.component.scss']
}) })
export class LocalServerComponent implements OnInit { export class LocalServerComponent implements OnInit {
constructor(private router: Router, private serverService: ServerService) {} constructor(
private router: Router,
private serverService: ServerService,
@Inject(DOCUMENT) private document) {}
ngOnInit() { ngOnInit() {
this.serverService.getLocalServer(location.hostname, parseInt(location.port, 10)).then((server: Server) => { this.serverService.getLocalServer(
this.document.location.hostname,
parseInt(this.document.location.port, 10))
.then((server: Server) => {
this.router.navigate(['/server', server.id, 'projects']); this.router.navigate(['/server', server.id, 'projects']);
}); });
} }