Redirecting to project page after creating added

This commit is contained in:
PiotrP 2018-11-15 01:00:48 -08:00
parent 39bc162414
commit b8ea53b32b
4 changed files with 27 additions and 7 deletions

View File

@ -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"> <form [formGroup]="projectNameForm" class="file-name-form">
<mat-form-field class="file-name-form-field"> <mat-form-field class="file-name-form-field">
<input matInput type="text" formControlName="projectName" [ngClass]="{ 'is-invalid': form.projectName?.errors }" placeholder="Please enter name" /> <input matInput type="text" formControlName="projectName" [ngClass]="{ 'is-invalid': form.projectName?.errors }" placeholder="Please enter name" />

View File

@ -8,6 +8,7 @@ import { ProjectService } from '../../../services/project.service';
import { ToasterService } from '../../../services/toaster.service'; import { ToasterService } from '../../../services/toaster.service';
import { of } from 'rxjs/internal/observable/of'; import { of } from 'rxjs/internal/observable/of';
import { Project } from '../../../models/project'; import { Project } from '../../../models/project';
import { Router } from '@angular/router';
export class MockedProjectService { export class MockedProjectService {
public projects: Project[] = [{ public projects: Project[] = [{
@ -41,6 +42,15 @@ describe('AddBlankProjectDialogComponent', () => {
let component: AddBlankProjectDialogComponent; let component: AddBlankProjectDialogComponent;
let fixture: ComponentFixture<AddBlankProjectDialogComponent>; let fixture: ComponentFixture<AddBlankProjectDialogComponent>;
let server: Server; let server: Server;
let router = {
navigate: jasmine.createSpy('navigate')
};
let toaster = {
success: jasmine.createSpy('success')
};
let dialogRef = {
close: jasmine.createSpy('close')
};
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@ -54,10 +64,11 @@ describe('AddBlankProjectDialogComponent', () => {
MatSnackBarModule MatSnackBarModule
], ],
providers: [ providers: [
{ provide: MatDialogRef }, { provide: MatDialogRef, useValue: dialogRef },
{ provide: MAT_DIALOG_DATA }, { provide: MAT_DIALOG_DATA },
{ provide: ProjectService, useClass: MockedProjectService }, { provide: ProjectService, useClass: MockedProjectService },
{ provide: ToasterService } { provide: ToasterService, useValue: toaster },
{ provide: Router, useValue: router }
], ],
declarations : [AddBlankProjectDialogComponent] declarations : [AddBlankProjectDialogComponent]
}) })
@ -108,4 +119,14 @@ describe('AddBlankProjectDialogComponent', () => {
expect(component.openConfirmationDialog).toHaveBeenCalled(); 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();
});
}); });

View File

@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { MatDialog, MatDialogRef } from '@angular/material'; import { MatDialog, MatDialogRef } from '@angular/material';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { Project } from '../../../models/project'; import { Project } from '../../../models/project';
@ -21,6 +22,7 @@ export class AddBlankProjectDialogComponent implements OnInit {
constructor( constructor(
public dialogRef: MatDialogRef<AddBlankProjectDialogComponent>, public dialogRef: MatDialogRef<AddBlankProjectDialogComponent>,
private router: Router,
private dialog: MatDialog, private dialog: MatDialog,
private projectService: ProjectService, private projectService: ProjectService,
private toasterService: ToasterService, private toasterService: ToasterService,
@ -64,6 +66,7 @@ export class AddBlankProjectDialogComponent implements OnInit {
.subscribe((project: Project) => { .subscribe((project: Project) => {
this.dialogRef.close(); this.dialogRef.close();
this.toasterService.success(`Project ${project.name} added`) this.toasterService.success(`Project ${project.name} added`)
this.router.navigate(['/server', this.server.id, 'project', project.project_id]);
}); });
} }

View File

@ -106,10 +106,6 @@ export class ProjectsComponent implements OnInit {
}) })
let instance = dialogRef.componentInstance; let instance = dialogRef.componentInstance;
instance.server = this.server; instance.server = this.server;
dialogRef.afterClosed().subscribe(() => {
this.refresh();
});
} }
importProject(){ importProject(){