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