mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-19 21:17:51 +00:00
ts-mockito and tests LayersWidget
This commit is contained in:
parent
dab3db3f17
commit
38e172f9b6
@ -66,6 +66,7 @@
|
||||
"node-sass": "^4.5.3",
|
||||
"popper.js": "^1.12.3",
|
||||
"protractor": "~5.3.0",
|
||||
"ts-mockito": "^2.3.0",
|
||||
"ts-node": "~5.0.0",
|
||||
"tslint": "~5.9.1",
|
||||
"typescript": ">=2.4.0 <2.6.0"
|
||||
|
@ -1,19 +1,53 @@
|
||||
import { instance, mock, when } from "ts-mockito";
|
||||
|
||||
import { TestSVGCanvas } from "../../testing";
|
||||
import { LayersWidget } from "./layers";
|
||||
import { Layer } from "../models/layer";
|
||||
import { LinksWidget } from "./links";
|
||||
import { NodesWidget } from "./nodes";
|
||||
import { DrawingsWidget } from "./drawings";
|
||||
import { GraphLayout } from "./graph";
|
||||
|
||||
|
||||
describe('LayersWidget', () => {
|
||||
let svg: TestSVGCanvas;
|
||||
let widget: LayersWidget;
|
||||
let mockedGraphLayout: GraphLayout;
|
||||
let mockedLinksWidget: LinksWidget;
|
||||
let mockedNodesWidget: NodesWidget;
|
||||
let mockedDrawingsWidget: DrawingsWidget;
|
||||
|
||||
beforeEach(() => {
|
||||
svg = new TestSVGCanvas();
|
||||
widget = new LayersWidget();
|
||||
mockedGraphLayout = mock(GraphLayout);
|
||||
mockedLinksWidget = mock(LinksWidget);
|
||||
mockedNodesWidget = mock(NodesWidget);
|
||||
mockedDrawingsWidget = mock(DrawingsWidget);
|
||||
when(mockedGraphLayout.getLinksWidget()).thenReturn(instance(mockedLinksWidget));
|
||||
when(mockedGraphLayout.getNodesWidget()).thenReturn(instance(mockedNodesWidget));
|
||||
when(mockedGraphLayout.getDrawingsWidget()).thenReturn(instance(mockedDrawingsWidget));
|
||||
|
||||
widget.graphLayout = instance(mockedGraphLayout);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
svg.destroy();
|
||||
});
|
||||
|
||||
it('canvas should transformed', () => {
|
||||
// expect(canvas.attr('transform')).toEqual('translate(100, 100) scale(1)');
|
||||
it('should draw layers', () => {
|
||||
const layer_1 = new Layer();
|
||||
layer_1.index = 1;
|
||||
const layer_2 = new Layer();
|
||||
layer_2.index = 2;
|
||||
const layers = [layer_1, layer_2];
|
||||
|
||||
widget.draw(svg.canvas, layers);
|
||||
|
||||
const drew = svg.canvas.selectAll<SVGGElement, Layer>('g.layer');
|
||||
expect(drew.size()).toEqual(2);
|
||||
expect(drew.nodes()[0].getAttribute('data-index')).toEqual('1');
|
||||
expect(drew.nodes()[1].getAttribute('data-index')).toEqual('2');
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -8565,6 +8565,12 @@ truncate-utf8-bytes@^1.0.0:
|
||||
dependencies:
|
||||
utf8-byte-length "^1.0.1"
|
||||
|
||||
ts-mockito@^2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-mockito/-/ts-mockito-2.3.0.tgz#c1836f04ec037cad82cfd7b3b66d52fc75adfcc7"
|
||||
dependencies:
|
||||
lodash "^4.17.5"
|
||||
|
||||
ts-node@~5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-5.0.0.tgz#9aa573889ad7949411f972981c209e064705e36f"
|
||||
|
Loading…
Reference in New Issue
Block a user