-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Edit Project dialog (#1003)
* implement edit project functionality * add unit test * add e2e test
- Loading branch information
1 parent
7e67fce
commit 5022de6
Showing
13 changed files
with
239 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div id="km-edit-project-dialog" class="km-dialog-box"> | ||
<mat-toolbar> | ||
Edit Project | ||
<button mat-icon-button mat-dialog-close> | ||
<i class="fa fa-times" aria-hidden="true"></i> | ||
</button> | ||
</mat-toolbar> | ||
<mat-dialog-content> | ||
<div class="mat-dialog-content"> | ||
<form [formGroup]="editProjectForm" fxLayout="column"> | ||
<p>You are on the way to edit the project name for "{{project.name}}".</p> | ||
<mat-form-field fxFlex> | ||
<input id="km-edit-project-dialog-input" matInput formControlName="name" type="text" placeholder="New project name*:" autocomplete="off"> | ||
<mat-error *ngIf="editProjectForm.controls.name.hasError('required')"> | ||
Name is <strong>required</strong> | ||
</mat-error> | ||
</mat-form-field> | ||
|
||
</form> | ||
</div> | ||
</mat-dialog-content> | ||
<mat-dialog-actions> | ||
<button mat-dialog-close mat-raised-button> | ||
Close | ||
</button> | ||
<button id="km-edit-project-dialog-edit-btn" mat-raised-button color="primary" (click)="editProject()" | ||
[disabled]="!editProjectForm.valid"> | ||
Edit | ||
</button> | ||
</mat-dialog-actions> | ||
</div> |
79 changes: 79 additions & 0 deletions
79
src/app/project/edit-project/edit-project.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {async, ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; | ||
import {MatDialogRef} from '@angular/material'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; | ||
import {SlimLoadingBarModule} from 'ng2-slim-loading-bar'; | ||
import Spy = jasmine.Spy; | ||
import {ApiService} from '../../core/services'; | ||
import {SharedModule} from '../../shared/shared.module'; | ||
import {fakeProject} from '../../testing/fake-data/project.fake'; | ||
import {asyncData} from '../../testing/services/api-mock.service'; | ||
import {MatDialogRefMock} from '../../testing/services/mat-dialog-ref-mock'; | ||
import {EditProjectComponent} from './edit-project.component'; | ||
|
||
const modules: any[] = [ | ||
BrowserModule, | ||
BrowserAnimationsModule, | ||
SlimLoadingBarModule.forRoot(), | ||
SharedModule, | ||
]; | ||
|
||
describe('EditProjectComponent', () => { | ||
let fixture: ComponentFixture<EditProjectComponent>; | ||
let component: EditProjectComponent; | ||
let editProjectSpy: Spy; | ||
|
||
beforeEach(async(() => { | ||
const apiMock = jasmine.createSpyObj('ApiService', ['editProject']); | ||
editProjectSpy = apiMock.editProject.and.returnValue(asyncData(fakeProject())); | ||
|
||
TestBed | ||
.configureTestingModule({ | ||
imports: [ | ||
...modules, | ||
], | ||
declarations: [ | ||
EditProjectComponent, | ||
], | ||
providers: [ | ||
{provide: MatDialogRef, useClass: MatDialogRefMock}, | ||
{provide: ApiService, useValue: apiMock}, | ||
], | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(async(() => { | ||
fixture = TestBed.createComponent(EditProjectComponent); | ||
component = fixture.componentInstance; | ||
component.project = fakeProject(); | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should create the edit project component', async(() => { | ||
expect(component).toBeTruthy(); | ||
})); | ||
|
||
it('should have invalid form after creating', () => { | ||
expect(component.editProjectForm.valid).toBeFalsy(); | ||
}); | ||
|
||
it('should have required fields', () => { | ||
expect(component.editProjectForm.valid).toBeFalsy('form is initially not valid'); | ||
expect(component.editProjectForm.controls.name.valid).toBeFalsy('name field is initially not valid'); | ||
expect(component.editProjectForm.controls.name.hasError('required')) | ||
.toBeTruthy('name field has initially required error'); | ||
|
||
component.editProjectForm.controls.name.patchValue('new-project-name'); | ||
expect(component.editProjectForm.controls.name.hasError('required')) | ||
.toBeFalsy('name field has no required error after setting name'); | ||
}); | ||
|
||
it('should call editProject method', fakeAsync(() => { | ||
component.editProjectForm.controls.name.patchValue('new-project-name'); | ||
component.editProject(); | ||
tick(); | ||
|
||
expect(editProjectSpy.and.callThrough()).toHaveBeenCalled(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {Component, Input, OnInit} from '@angular/core'; | ||
import {FormControl, FormGroup, Validators} from '@angular/forms'; | ||
import {MatDialogRef} from '@angular/material'; | ||
import {ApiService} from '../../core/services'; | ||
import {NotificationActions} from '../../redux/actions/notification.actions'; | ||
import {EditProjectEntity, ProjectEntity} from '../../shared/entity/ProjectEntity'; | ||
|
||
@Component({ | ||
selector: 'kubermatic-edit-project', | ||
templateUrl: './edit-project.component.html', | ||
}) | ||
export class EditProjectComponent implements OnInit { | ||
@Input() project: ProjectEntity; | ||
editProjectForm: FormGroup; | ||
|
||
constructor(private api: ApiService, private dialogRef: MatDialogRef<EditProjectComponent>) {} | ||
|
||
ngOnInit(): void { | ||
this.editProjectForm = new FormGroup({ | ||
name: new FormControl('', [Validators.required]), | ||
}); | ||
} | ||
|
||
editProject(): void { | ||
const editProjectEntity: EditProjectEntity = { | ||
name: this.editProjectForm.controls.name.value, | ||
}; | ||
|
||
this.api.editProject(this.project.id, editProjectEntity).subscribe((res) => { | ||
this.dialogRef.close(res); | ||
NotificationActions.success('Success', `Project has been edited successfully`); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ export class ProjectEntity { | |
name: string; | ||
status: string; | ||
} | ||
|
||
export class EditProjectEntity { | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters