Merge pull request #406 from GNS3/Refresh-page-button-redirects-to-empty-page

Refresh page button redirects to empty page while in ElectronJS  #371
This commit is contained in:
ziajka 2019-05-29 07:58:13 +02:00 committed by GitHub
commit 64ad61c15b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import { MatIconModule, MatProgressSpinnerModule } from '@angular/material';
import { ProgressService } from './progress.service'; import { ProgressService } from './progress.service';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject, Observable } from 'rxjs';
class MockedRouter { class MockedRouter {
events: BehaviorSubject<boolean>; events: BehaviorSubject<boolean>;
@ -13,18 +13,20 @@ class MockedRouter {
constructor() { constructor() {
this.events = new BehaviorSubject(true); this.events = new BehaviorSubject(true);
} }
navigateByUrl() {}
} }
describe('ProgressComponent', () => { describe('ProgressComponent', () => {
let component: ProgressComponent; let component: ProgressComponent;
let fixture: ComponentFixture<ProgressComponent>; let fixture: ComponentFixture<ProgressComponent>;
let progressService: ProgressService; let progressService: ProgressService;
let router: MockedRouter; let router: MockedRouter = new MockedRouter();
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [RouterTestingModule, MatProgressSpinnerModule, MatIconModule], imports: [RouterTestingModule, MatProgressSpinnerModule, MatIconModule],
providers: [ProgressService, { provide: Router, useClass: MockedRouter }], providers: [ProgressService, { provide: Router, useValue: router }],
declarations: [ProgressComponent] declarations: [ProgressComponent]
}).compileComponents(); }).compileComponents();
@ -71,4 +73,12 @@ describe('ProgressComponent', () => {
expect(progressService.clear).toHaveBeenCalled(); expect(progressService.clear).toHaveBeenCalled();
}); });
it("should reload page after clicking refresh", () => {
spyOn(router, 'navigateByUrl');
component.refresh();
expect(router.navigateByUrl).toHaveBeenCalled();
});
}); });

View File

@ -36,8 +36,7 @@ export class ProgressComponent implements OnInit, OnDestroy {
} }
refresh() { refresh() {
// unfortunately we need to use global var this.router.navigateByUrl(this.router.url);
location.reload();
} }
ngOnDestroy() { ngOnDestroy() {