mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-01 15:00:49 +00:00
Interface labels tests
This commit is contained in:
parent
a88d829f4d
commit
712aef6834
@ -1,14 +1,12 @@
|
||||
import { Selection } from "d3-selection";
|
||||
|
||||
import { TestSVGCanvas } from "../../testing";
|
||||
import { LayersWidget } from "./layers";
|
||||
import { Layer } from "../models/layer";
|
||||
import { Node } from "../models/node";
|
||||
import { Link } from "../models/link";
|
||||
import { InterfaceLabelWidget } from "./interface-label";
|
||||
import { LinkNode } from "../models/link-node";
|
||||
import { Label } from "../models/label";
|
||||
import { InterfaceLabel } from "../models/interface-label";
|
||||
import { InterfaceLabelWidget } from "./interface-label";
|
||||
|
||||
|
||||
describe('InterfaceLabelsWidget', () => {
|
||||
@ -44,29 +42,29 @@ describe('InterfaceLabelsWidget', () => {
|
||||
link_node_2.label.text = "Interface 2";
|
||||
link_node_2.label.x = -30;
|
||||
link_node_2.label.y = -40;
|
||||
link_node_1.label.style = "";
|
||||
link_node_2.label.style = "";
|
||||
|
||||
const link_1 = new Link();
|
||||
link_1.link_id = "link1";
|
||||
link_1.source = node_1;
|
||||
link_1.target = node_2;
|
||||
link_1.nodes = [ link_node_1, link_node_2];
|
||||
link_1.nodes = [link_node_1, link_node_2];
|
||||
link_1.link_type = "ethernet";
|
||||
|
||||
links = [link_1];
|
||||
|
||||
const linksSelection = svg.canvas
|
||||
.selectAll<SVGGElement, Link>('g.link')
|
||||
.data(links);
|
||||
.selectAll<SVGGElement, Link>('g.link')
|
||||
.data(links);
|
||||
|
||||
linksEnter = linksSelection
|
||||
.enter()
|
||||
.append<SVGGElement>('g')
|
||||
.attr('class', 'link');
|
||||
.enter()
|
||||
.append<SVGGElement>('g')
|
||||
.attr('class', 'link');
|
||||
|
||||
linksSelection
|
||||
.exit()
|
||||
.remove();
|
||||
.exit()
|
||||
.remove();
|
||||
|
||||
widget = new InterfaceLabelWidget();
|
||||
});
|
||||
@ -94,7 +92,7 @@ describe('InterfaceLabelsWidget', () => {
|
||||
expect(targetInterface.getAttribute('x')).toEqual('270');
|
||||
expect(targetInterface.getAttribute('y')).toEqual('360');
|
||||
expect(targetInterface.getAttribute('transform')).toEqual('rotate(0, 270, 360)');
|
||||
expect(sourceInterface.getAttribute('style')).toEqual('');
|
||||
expect(targetInterface.getAttribute('style')).toEqual('');
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,24 +1,25 @@
|
||||
import { anything, instance, mock, verify } from "ts-mockito";
|
||||
import { Selection } from "d3-selection";
|
||||
|
||||
|
||||
import { TestSVGCanvas } from "../../testing";
|
||||
import { LayersWidget } from "./layers";
|
||||
import { Layer } from "../models/layer";
|
||||
import { LinksWidget } from "./links";
|
||||
import { Node } from "../models/node";
|
||||
import { Link } from "../models/link";
|
||||
import { InterfaceLabelWidget } from "./interface-label";
|
||||
|
||||
|
||||
describe('LinksWidget', () => {
|
||||
let svg: TestSVGCanvas;
|
||||
let widget: LinksWidget;
|
||||
let layersWidget: LayersWidget;
|
||||
let layersEnter: Selection<SVGGElement, Layer, SVGGElement, any>;
|
||||
let layer: Layer;
|
||||
|
||||
beforeEach(() => {
|
||||
svg = new TestSVGCanvas();
|
||||
widget = new LinksWidget();
|
||||
|
||||
|
||||
const node_1 = new Node();
|
||||
node_1.node_id = "1";
|
||||
node_1.x = 10;
|
||||
@ -28,7 +29,7 @@ describe('LinksWidget', () => {
|
||||
node_2.node_id = "2";
|
||||
node_2.x = 100;
|
||||
node_2.y = 100;
|
||||
|
||||
|
||||
const link_1 = new Link();
|
||||
link_1.link_id = "link1";
|
||||
link_1.source = node_1;
|
||||
@ -39,7 +40,7 @@ describe('LinksWidget', () => {
|
||||
layer.index = 1;
|
||||
|
||||
layer.links = [link_1];
|
||||
|
||||
|
||||
const layers = [layer];
|
||||
|
||||
const layersSelection = svg.canvas
|
||||
@ -61,6 +62,10 @@ describe('LinksWidget', () => {
|
||||
});
|
||||
|
||||
it('should draw links', () => {
|
||||
const interfaceLabelWidgetMock = mock(InterfaceLabelWidget);
|
||||
const interfaceLabelWidget = instance(interfaceLabelWidgetMock);
|
||||
spyOn(widget, 'getInterfaceLabelWidget').and.returnValue(interfaceLabelWidget);
|
||||
|
||||
widget.draw(layersEnter);
|
||||
|
||||
const drew = svg.canvas.selectAll<SVGGElement, Link>('g.link');
|
||||
@ -69,6 +74,8 @@ describe('LinksWidget', () => {
|
||||
expect(linkNode.getAttribute('map-source')).toEqual('1');
|
||||
expect(linkNode.getAttribute('map-target')).toEqual('2');
|
||||
expect(linkNode.getAttribute('transform')).toEqual('translate (0, 0)');
|
||||
|
||||
verify(interfaceLabelWidgetMock.draw(anything())).called();
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -14,6 +14,20 @@ import { InterfaceLabelWidget } from "./interface-label";
|
||||
export class LinksWidget implements Widget {
|
||||
private multiLinkCalculatorHelper = new MultiLinkCalculatorHelper();
|
||||
|
||||
private interfaceLabelWidget: InterfaceLabelWidget;
|
||||
|
||||
constructor() {
|
||||
this.interfaceLabelWidget = new InterfaceLabelWidget();
|
||||
}
|
||||
|
||||
public getInterfaceLabelWidget() {
|
||||
return this.interfaceLabelWidget;
|
||||
}
|
||||
|
||||
public setInterfaceLabelWidget(interfaceLabelWidget: InterfaceLabelWidget) {
|
||||
this.interfaceLabelWidget = interfaceLabelWidget;
|
||||
}
|
||||
|
||||
public getLinkWidget(link: Link) {
|
||||
if (link.link_type === 'serial') {
|
||||
return new SerialLinkWidget();
|
||||
@ -97,8 +111,7 @@ export class LinksWidget implements Widget {
|
||||
return null;
|
||||
});
|
||||
|
||||
const interfaceLabel = new InterfaceLabelWidget();
|
||||
interfaceLabel.draw(selection);
|
||||
this.getInterfaceLabelWidget().draw(selection);
|
||||
}
|
||||
|
||||
public draw(view: SVGSelection, links?: Link[]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user