mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-01 06:50:42 +00:00
Unit test for drawing resizing component added
This commit is contained in:
parent
6fc98e3577
commit
6c2399357d
@ -3,7 +3,7 @@ import { CommonModule } from '@angular/common';
|
||||
import { MatMenuModule, MatIconModule } from '@angular/material';
|
||||
|
||||
import { DrawLinkToolComponent } from './components/draw-link-tool/draw-link-tool.component';
|
||||
import { DrawingResizingComponent } from './components/drawing-resizing/drawing-resizing.components';
|
||||
import { DrawingResizingComponent } from './components/drawing-resizing/drawing-resizing.component';
|
||||
|
||||
import { CssFixer } from './helpers/css-fixer';
|
||||
import { FontFixer } from './helpers/font-fixer';
|
||||
|
@ -36,9 +36,6 @@ export class D3MapComponent implements OnInit, OnChanges, OnDestroy {
|
||||
@Input() width = 1500;
|
||||
@Input() height = 600;
|
||||
|
||||
@Output() nodeDragged = new EventEmitter<DraggedDataEvent<Node>>();
|
||||
@Output() drawingDragged = new EventEmitter<DraggedDataEvent<Drawing>>();
|
||||
@Output() onLinkCreated = new EventEmitter<MapLinkCreated>();
|
||||
@ViewChild('svg') svgRef: ElementRef;
|
||||
|
||||
private parentNativeElement: any;
|
||||
@ -86,9 +83,6 @@ export class D3MapComponent implements OnInit, OnChanges, OnDestroy {
|
||||
|
||||
@Input('draw-link-tool') drawLinkTool: boolean;
|
||||
|
||||
//@Input('drawing-selected') selectedDrawing: string;
|
||||
public drawingSelected = "";
|
||||
|
||||
@Input('readonly') set readonly(value) {
|
||||
this.mapSettings.isReadOnly = value;
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
|
||||
import { DrawingResizingComponent } from './drawing-resizing.component'
|
||||
import { DrawingsWidget } from '../../widgets/drawings';
|
||||
import { DrawingsEventSource } from '../../events/drawings-event-source';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
import { ResizingEnd } from '../../events/resizing';
|
||||
import { MapDrawing } from '../../models/map/map-drawing';
|
||||
|
||||
export class DrawingWidgetMock {
|
||||
resizingFinished = new EventEmitter<ResizingEnd<MapDrawing>>();
|
||||
constructor(){}
|
||||
|
||||
public emitEvent(){
|
||||
const evt = new ResizingEnd<MapDrawing>();
|
||||
evt.x = 0;
|
||||
evt.y = 0;
|
||||
evt.width = 10;
|
||||
evt.height = 10;
|
||||
evt.datum = {} as MapDrawing;
|
||||
|
||||
this.resizingFinished.emit(evt);
|
||||
}
|
||||
}
|
||||
|
||||
describe('DrawizngResizingComponent', () => {
|
||||
let component: DrawingResizingComponent;
|
||||
let fixture: ComponentFixture<DrawingResizingComponent>;
|
||||
let drawingWidgetMock = new DrawingWidgetMock;
|
||||
let drawingEventSource = new DrawingsEventSource
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
NoopAnimationsModule
|
||||
],
|
||||
providers: [
|
||||
{ provide: DrawingsWidget, useValue: drawingWidgetMock },
|
||||
{ provide: DrawingsEventSource, useValue: drawingEventSource}
|
||||
],
|
||||
declarations: [
|
||||
DrawingResizingComponent
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DrawingResizingComponent);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should emit event after size changes', () => {
|
||||
spyOn(drawingEventSource.resized, 'emit');
|
||||
|
||||
drawingWidgetMock.emitEvent();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(drawingEventSource.resized.emit).toHaveBeenCalled();
|
||||
});
|
||||
});
|
@ -12,7 +12,7 @@ import { ResizingEnd } from '../../events/resizing';
|
||||
styleUrls: ['./drawing-resizing.component.scss']
|
||||
})
|
||||
export class DrawingResizingComponent implements OnInit, OnDestroy{
|
||||
private resizingFinished: Subscription;
|
||||
resizingFinished: Subscription;
|
||||
|
||||
constructor(
|
||||
private drawingsWidget: DrawingsWidget,
|
@ -90,7 +90,9 @@ export class DrawingsWidget implements Widget {
|
||||
if ((datum.element.height + evt.dy) < 0) {
|
||||
isReflectedVertical = true;
|
||||
y = topEdge;
|
||||
console.log(y);
|
||||
datum.element.height = Math.abs(datum.element.height + evt.dy);
|
||||
console.log(datum.element.height);
|
||||
} else {
|
||||
datum.element.height += evt.dy;
|
||||
|
||||
@ -104,9 +106,11 @@ export class DrawingsWidget implements Widget {
|
||||
y = evt.sourceEvent.clientY - this.context.getZeroZeroTransformationPoint().y;
|
||||
|
||||
if ((datum.element.height + dy) < 0){
|
||||
y = topEdge;
|
||||
isReflectedVertical = false;
|
||||
y = topEdge;
|
||||
console.log(y);
|
||||
datum.element.height = Math.abs(datum.element.height + evt.dy);
|
||||
console.log(datum.element.height);
|
||||
} else {
|
||||
datum.y = evt.sourceEvent.clientY - this.context.getZeroZeroTransformationPoint().y;
|
||||
datum.element.height += dy;
|
||||
|
Loading…
x
Reference in New Issue
Block a user