123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import {
- bootstrapDiagram,
- inject
- } from 'test/TestHelper';
- import {
- createCanvasEvent as canvasEvent
- } from '../../../util/MockEvents';
- import {
- assign,
- pick
- } from 'min-dash';
- import modelingModule from 'lib/features/modeling';
- import moveModule from 'lib/features/move';
- describe('features/move - Move', function() {
- beforeEach(bootstrapDiagram({ modules: [ moveModule, modelingModule ] }));
- beforeEach(inject(function(canvas, dragging) {
- dragging.setOptions({ manual: true });
- }));
- var rootShape, parentShape, childShape, childShape2, connection;
- beforeEach(inject(function(elementFactory, canvas) {
- rootShape = elementFactory.createRoot({
- id: 'root'
- });
- canvas.setRootElement(rootShape);
- parentShape = elementFactory.createShape({
- id: 'parent',
- x: 100, y: 100, width: 300, height: 300
- });
- canvas.addShape(parentShape, rootShape);
- childShape = elementFactory.createShape({
- id: 'child',
- x: 110, y: 110, width: 100, height: 100
- });
- canvas.addShape(childShape, parentShape);
- childShape2 = elementFactory.createShape({
- id: 'child2',
- x: 200, y: 110, width: 100, height: 100
- });
- canvas.addShape(childShape2, parentShape);
- connection = elementFactory.createConnection({
- id: 'connection',
- waypoints: [ { x: 150, y: 150 }, { x: 150, y: 200 }, { x: 350, y: 150 } ],
- source: childShape,
- target: childShape2
- });
- canvas.addConnection(connection, parentShape);
- }));
- describe('event centering', function() {
- it('should emit events relative to shape center', inject(function(eventBus, move, dragging) {
- // given
- function recordEvents(prefix) {
- var events = [];
- [ 'start', 'move', 'end', 'hover', 'out', 'cancel', 'cleanup', 'init' ].forEach(function(type) {
- eventBus.on(prefix + '.' + type, function(e) {
- events.push(assign({}, e));
- });
- });
- return events;
- }
- function position(e) {
- return pick(e, [ 'x', 'y', 'dx', 'dy' ]);
- }
- var events = recordEvents('shape.move');
- // when
- move.start(canvasEvent({ x: 0, y: 0 }), childShape);
- dragging.move(canvasEvent({ x: 20, y: 20 }));
- // then
- expect(events.map(position)).to.eql([
- { },
- { x: 160, y: 160, dx: 0, dy: 0 },
- { x: 180, y: 180, dx: 20, dy: 20 }
- ]);
- }));
- });
- describe('modeling', function() {
- it('should round movement to pixels', inject(function(move, dragging, elementRegistry) {
- // given
- move.start(canvasEvent({ x: 0, y: 0 }), childShape);
- // when
- dragging.move(canvasEvent({ x: 20, y: 20 }));
- dragging.hover({
- element: parentShape,
- gfx: elementRegistry.getGraphics(parentShape)
- });
- dragging.move(canvasEvent({ x: 30.4, y: 99.7 }));
- dragging.end();
- // then
- expect(childShape.x).to.eql(140);
- expect(childShape.y).to.eql(210);
- }));
- });
- });
|