Merge branch 'master' into Topology-summary---prototype

This commit is contained in:
Piotr Pekala 2019-08-21 00:14:45 -07:00
commit b9a2879f60
5 changed files with 46 additions and 0 deletions

View File

@ -40,6 +40,9 @@
<button mat-icon-button matTooltip="Delete project" (click)="delete(row)" *ngIf="row.status == 'closed'">
<mat-icon aria-label="Delete project">delete</mat-icon>
</button>
<button mat-icon-button matTooltip="Duplicate project" (click)="duplicate(row)" *ngIf="row.status == 'closed'">
<mat-icon aria-label="Duplicate project">filter_2</mat-icon>
</button>
<button mat-icon-button matTooltip="Open project" (click)="open(row)" *ngIf="row.status == 'closed'">
<mat-icon aria-label="Open project">play_arrow</mat-icon>
</button>

View File

@ -85,6 +85,28 @@ describe('ProjectsComponent', () => {
expect(mockedProjectService.delete).toHaveBeenCalled();
});
it('should call project service after duplicate action', () => {
spyOn(mockedProjectService, 'duplicate').and.returnValue(of());
let project = new Project();
project.project_id = '1';
project.status = 'closed';
component.duplicate(project);
expect(mockedProjectService.duplicate).toHaveBeenCalled();
});
it('should call refresh after duplicate action', () => {
spyOn(component, 'refresh');
let project = new Project();
project.project_id = '1';
project.status = 'closed';
component.duplicate(project);
expect(component.refresh).toHaveBeenCalled();
});
describe('ProjectComponent open', () => {
let project: Project;

View File

@ -107,6 +107,12 @@ export class ProjectsComponent implements OnInit {
);
}
duplicate(project: Project) {
this.projectService.duplicate(this.server, project.project_id, project.name).subscribe(() => {
this.refresh();
});
}
addBlankProject() {
const dialogRef = this.dialog.open(AddBlankProjectDialogComponent, {
width: '400px',

View File

@ -41,6 +41,10 @@ export class MockedProjectService {
delete(server: Server, project_id: string) {
return of(project_id);
}
duplicate(server: Server, project_id: string) {
return of(project_id);
}
}
describe('ProjectService', () => {
@ -132,6 +136,13 @@ describe('ProjectService', () => {
expect(req.request.method).toEqual('DELETE');
});
it('should duplicate the project', () => {
service.duplicate(server, 'projectId', 'projectName').subscribe();
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/projects/projectId/duplicate');
expect(req.request.method).toEqual('POST');
});
it('should get notifications path of project', () => {
const path = service.notificationsPath(server, 'myproject');
expect(path).toEqual('ws://127.0.0.1:3080/v2/projects/myproject/notifications/ws');

View File

@ -53,6 +53,10 @@ export class ProjectService {
return this.httpServer.get(server, `/projects/${project_id}/stats`);
}
duplicate(server: Server, project_id: string, project_name): Observable<any> {
return this.httpServer.post(server, `/projects/${project_id}/duplicate`, { name: project_name });
}
notificationsPath(server: Server, project_id: string): string {
return `ws://${server.host}:${server.port}/v2/projects/${project_id}/notifications/ws`;
}