mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-23 14:52:22 +00:00
Update duplicate-action-component
This commit is contained in:
parent
6e23aed7b9
commit
5c99ec64eb
@ -10,12 +10,15 @@ import { Node } from '../../../../../cartography/models/node';
|
||||
import { Drawing } from '../../../../../cartography/models/drawing';
|
||||
import { of } from 'rxjs';
|
||||
import { DuplicateActionComponent } from './duplicate-action.component';
|
||||
import { ToasterService } from '../../../../../services/toaster.service';
|
||||
import { MockedToasterService } from '../../../../../services/toaster.service.spec';
|
||||
|
||||
describe('DuplicateActionComponent', () => {
|
||||
fdescribe('DuplicateActionComponent', () => {
|
||||
let component: DuplicateActionComponent;
|
||||
let fixture: ComponentFixture<DuplicateActionComponent>;
|
||||
let mockedNodeService: MockedNodeService = new MockedNodeService();
|
||||
let mockedDrawingService: MockedDrawingService = new MockedDrawingService();
|
||||
let mockedToasterService = new MockedToasterService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@ -24,7 +27,8 @@ describe('DuplicateActionComponent', () => {
|
||||
{ provide: NodesDataSource, useClass: NodesDataSource },
|
||||
{ provide: DrawingsDataSource, useClass: DrawingsDataSource },
|
||||
{ provide: NodeService, useValue: mockedNodeService },
|
||||
{ provide: DrawingService, useValue: mockedDrawingService }
|
||||
{ provide: DrawingService, useValue: mockedDrawingService },
|
||||
{ provide: ToasterService, useValue: mockedToasterService }
|
||||
],
|
||||
declarations: [DuplicateActionComponent]
|
||||
}).compileComponents();
|
||||
@ -52,7 +56,7 @@ describe('DuplicateActionComponent', () => {
|
||||
});
|
||||
|
||||
it('should call duplicate action in node service', () => {
|
||||
let node = { node_id: '1' } as Node;
|
||||
let node = { node_id: '1', status: 'stopped'} as Node;
|
||||
component.nodes = [node];
|
||||
component.drawings = [];
|
||||
spyOn(mockedNodeService, 'duplicate').and.returnValue(of());
|
||||
@ -65,7 +69,7 @@ describe('DuplicateActionComponent', () => {
|
||||
it('should call duplicate action in both services', () => {
|
||||
let drawing = { drawing_id: '1' } as Drawing;
|
||||
component.drawings = [drawing];
|
||||
let node = { node_id: '1' } as Node;
|
||||
let node = { node_id: '1', status: 'stopped' } as Node;
|
||||
component.nodes = [node];
|
||||
spyOn(mockedDrawingService, 'duplicate').and.returnValue(of());
|
||||
spyOn(mockedNodeService, 'duplicate').and.returnValue(of());
|
||||
|
@ -7,6 +7,7 @@ import { NodeService } from '../../../../../services/node.service';
|
||||
import { DrawingService } from '../../../../../services/drawing.service';
|
||||
import { NodesDataSource } from '../../../../../cartography/datasources/nodes-datasource';
|
||||
import { DrawingsDataSource } from '../../../../../cartography/datasources/drawings-datasource';
|
||||
import { ToasterService } from '../../../../../services/toaster.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-duplicate-action',
|
||||
@ -22,14 +23,20 @@ export class DuplicateActionComponent {
|
||||
private nodeService: NodeService,
|
||||
private nodesDataSource: NodesDataSource,
|
||||
private drawingService: DrawingService,
|
||||
private drawingsDataSource: DrawingsDataSource
|
||||
private drawingsDataSource: DrawingsDataSource,
|
||||
private toasterService: ToasterService
|
||||
) {}
|
||||
|
||||
duplicate() {
|
||||
let runningNodes: string = '';
|
||||
for(let node of this.nodes) {
|
||||
this.nodeService.duplicate(this.server, node).subscribe((node: Node) => {
|
||||
this.nodesDataSource.add(node);
|
||||
});
|
||||
if (node.status === 'stopped') {
|
||||
this.nodeService.duplicate(this.server, node).subscribe((node: Node) => {
|
||||
this.nodesDataSource.add(node);
|
||||
});
|
||||
} else {
|
||||
runningNodes += `${node.name}, `;
|
||||
}
|
||||
}
|
||||
|
||||
for(let drawing of this.drawings) {
|
||||
@ -37,5 +44,8 @@ export class DuplicateActionComponent {
|
||||
this.drawingsDataSource.add(drawing);
|
||||
})
|
||||
}
|
||||
|
||||
runningNodes = runningNodes.substring(0, runningNodes.length-2);
|
||||
this.toasterService.error(`Cannot duplicate node data for nodes: ${runningNodes}`);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user