mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-24 23:26:39 +00:00
Redirecting to project page after creating added
This commit is contained in:
parent
39bc162414
commit
b8ea53b32b
@ -1,4 +1,4 @@
|
||||
<h1 mat-dialog-title>Add blank project</h1>
|
||||
<h1 mat-dialog-title>Create new project</h1>
|
||||
<form [formGroup]="projectNameForm" class="file-name-form">
|
||||
<mat-form-field class="file-name-form-field">
|
||||
<input matInput type="text" formControlName="projectName" [ngClass]="{ 'is-invalid': form.projectName?.errors }" placeholder="Please enter name" />
|
||||
|
@ -8,6 +8,7 @@ import { ProjectService } from '../../../services/project.service';
|
||||
import { ToasterService } from '../../../services/toaster.service';
|
||||
import { of } from 'rxjs/internal/observable/of';
|
||||
import { Project } from '../../../models/project';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
export class MockedProjectService {
|
||||
public projects: Project[] = [{
|
||||
@ -41,6 +42,15 @@ describe('AddBlankProjectDialogComponent', () => {
|
||||
let component: AddBlankProjectDialogComponent;
|
||||
let fixture: ComponentFixture<AddBlankProjectDialogComponent>;
|
||||
let server: Server;
|
||||
let router = {
|
||||
navigate: jasmine.createSpy('navigate')
|
||||
};
|
||||
let toaster = {
|
||||
success: jasmine.createSpy('success')
|
||||
};
|
||||
let dialogRef = {
|
||||
close: jasmine.createSpy('close')
|
||||
};
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@ -54,10 +64,11 @@ describe('AddBlankProjectDialogComponent', () => {
|
||||
MatSnackBarModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: MatDialogRef },
|
||||
{ provide: MatDialogRef, useValue: dialogRef },
|
||||
{ provide: MAT_DIALOG_DATA },
|
||||
{ provide: ProjectService, useClass: MockedProjectService },
|
||||
{ provide: ToasterService }
|
||||
{ provide: ToasterService, useValue: toaster },
|
||||
{ provide: Router, useValue: router }
|
||||
],
|
||||
declarations : [AddBlankProjectDialogComponent]
|
||||
})
|
||||
@ -108,4 +119,14 @@ describe('AddBlankProjectDialogComponent', () => {
|
||||
|
||||
expect(component.openConfirmationDialog).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should redirect to newly created project', () => {
|
||||
component.projectNameForm.controls['projectName'].setValue("validName");
|
||||
|
||||
component.addProject();
|
||||
|
||||
expect(dialogRef.close).toHaveBeenCalled();
|
||||
expect(toaster.success).toHaveBeenCalled();
|
||||
expect(router.navigate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { MatDialog, MatDialogRef } from '@angular/material';
|
||||
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
|
||||
import { Project } from '../../../models/project';
|
||||
@ -21,6 +22,7 @@ export class AddBlankProjectDialogComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<AddBlankProjectDialogComponent>,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private projectService: ProjectService,
|
||||
private toasterService: ToasterService,
|
||||
@ -64,6 +66,7 @@ export class AddBlankProjectDialogComponent implements OnInit {
|
||||
.subscribe((project: Project) => {
|
||||
this.dialogRef.close();
|
||||
this.toasterService.success(`Project ${project.name} added`)
|
||||
this.router.navigate(['/server', this.server.id, 'project', project.project_id]);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -106,10 +106,6 @@ export class ProjectsComponent implements OnInit {
|
||||
})
|
||||
let instance = dialogRef.componentInstance;
|
||||
instance.server = this.server;
|
||||
|
||||
dialogRef.afterClosed().subscribe(() => {
|
||||
this.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
importProject(){
|
||||
|
Loading…
Reference in New Issue
Block a user