'use strict'; /* global bootstrapViewer, inject */ var labelEditingModule = require('../../../../lib/features/label-editing'), coreModule = require('../../../../lib/core'), draggingModule = require('diagram-js/lib/features/dragging'), modelingModule = require('diagram-js/lib/features/modeling'); var LabelUtil = require('../../../../lib/features/label-editing/LabelUtil'); var MEDIUM_LINE_HEIGHT = 14; var DELTA = 3; function triggerKeyEvent(element, event, code) { var e = document.createEvent('Events'); if (e.initEvent) { e.initEvent(event, true, true); } e.keyCode = code; e.which = code; return element.dispatchEvent(e); } function expectBounds(parent, bounds) { expect(parent.offsetLeft).to.be.closeTo(bounds.x, DELTA); expect(parent.offsetTop).to.be.closeTo(bounds.y, DELTA); expect(parent.offsetWidth).to.be.closeTo(bounds.width, DELTA); expect(parent.offsetHeight).to.be.closeTo(bounds.height, DELTA); } describe('features - label-editing', function() { var diagramXML = require('../../../fixtures/bpmn/features/label-editing/labels.bpmn'); describe('basics', function() { var testModules = [ labelEditingModule, coreModule, draggingModule, modelingModule ]; beforeEach(bootstrapViewer(diagramXML, { modules: testModules })); it('should register on dblclick', inject(function(elementRegistry, directEditing, eventBus) { // given var shape = elementRegistry.get('Task_1'); // when eventBus.fire('element.dblclick', { element: shape }); // then expect(directEditing.isActive()).to.be.true; // clean up directEditing._textbox.destroy(); })); it('should cancel on ', inject(function(elementRegistry, directEditing, eventBus) { // given var shape = elementRegistry.get('Task_1'), task = shape.businessObject; var oldName = task.name; // activate eventBus.fire('element.dblclick', { element: shape }); var textbox = directEditing._textbox.content; // when // change + ESC is pressed textbox.innerText = 'new value'; triggerKeyEvent(textbox, 'keydown', 27); // then expect(directEditing.isActive()).to.be.false; expect(task.name).to.equal(oldName); })); it('should complete on drag start', inject(function(elementRegistry, directEditing, dragging) { // given var shape = elementRegistry.get('Task_1'), task = shape.businessObject; directEditing.activate(shape); directEditing._textbox.content.textContent = 'FOO BAR'; // when dragging.init(null, { x: 0, y: 0 }, 'foo'); // then expect(task.name).to.equal('FOO BAR'); })); it('should submit on root element click', inject(function(elementRegistry, directEditing, canvas, eventBus) { // given var shape = elementRegistry.get('Task_1'), task = shape.businessObject; // activate eventBus.fire('element.dblclick', { element: shape }); var newName = 'new value'; // a