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