2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
bootstrapViewer,
|
|
|
|
inject
|
|
|
|
} from 'test/TestHelper';
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-03-14 20:43:53 +00:00
|
|
|
var pick = require('min-dash').pick;
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import labelEditingModule from 'lib/features/label-editing';
|
|
|
|
import coreModule from 'lib/core';
|
|
|
|
import draggingModule from 'diagram-js/lib/features/dragging';
|
|
|
|
import modelingModule from 'lib/features/modeling';
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2017-10-22 20:23:51 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
describe('features - label-editing preview', function() {
|
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
var diagramXML = require('./LabelEditing.bpmn');
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
beforeEach(bootstrapViewer(diagramXML, {
|
|
|
|
modules: [
|
|
|
|
labelEditingModule,
|
|
|
|
coreModule,
|
|
|
|
draggingModule,
|
|
|
|
modelingModule
|
|
|
|
]
|
|
|
|
}));
|
2017-06-27 07:37:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('activate', function() {
|
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
it('[external labels AND text annotations ] should add marker to hide element on activate', inject(
|
|
|
|
function(directEditing, elementRegistry) {
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// given
|
|
|
|
var textAnnotation = elementRegistry.get('TextAnnotation_1');
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// when
|
|
|
|
directEditing.activate(textAnnotation);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// then
|
|
|
|
var gfx = elementRegistry.getGraphics(textAnnotation);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
expect(gfx.classList.contains('djs-element-hidden')).to.be.true;
|
|
|
|
}
|
|
|
|
));
|
2017-06-27 07:37:58 +00:00
|
|
|
|
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
it('[internal labels] should add marker to hide label on activate', inject(
|
|
|
|
function(directEditing, elementRegistry) {
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// when
|
|
|
|
directEditing.activate(task);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// then
|
|
|
|
var gfx = elementRegistry.getGraphics(task);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
expect(gfx.classList.contains('djs-label-hidden')).to.be.true;
|
|
|
|
}
|
|
|
|
));
|
2017-06-27 07:37:58 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('resize', function() {
|
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
it('[text annotations] should resize preview on resize', inject(
|
|
|
|
function(directEditing, elementRegistry, eventBus, labelEditingPreview) {
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// given
|
|
|
|
var textAnnotation = elementRegistry.get('TextAnnotation_1');
|
|
|
|
directEditing.activate(textAnnotation);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// when
|
|
|
|
eventBus.fire('directEditing.resize', {
|
|
|
|
width: 200,
|
|
|
|
height: 200,
|
|
|
|
dx: 100,
|
|
|
|
dy: 100
|
|
|
|
});
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// then
|
|
|
|
var bounds = bbox(labelEditingPreview.path);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
expect(bounds).to.eql({ x: 0, y: 0, width: 10, height: 300 });
|
|
|
|
}
|
|
|
|
));
|
2017-06-27 07:37:58 +00:00
|
|
|
|
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
it('[text annotations] should resize preview below 0', inject(
|
|
|
|
function(directEditing, elementRegistry, eventBus, labelEditingPreview) {
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// given
|
|
|
|
var textAnnotation = elementRegistry.get('TextAnnotation_1');
|
|
|
|
directEditing.activate(textAnnotation);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// when
|
|
|
|
eventBus.fire('directEditing.resize', {
|
|
|
|
width: 200,
|
|
|
|
height: 200,
|
|
|
|
dx: -300,
|
|
|
|
dy: -300
|
|
|
|
});
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// then
|
|
|
|
var bounds = bbox(labelEditingPreview.path);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
expect(bounds).to.eql({ x: 0, y: 0, width: 10, height: 0 });
|
|
|
|
}
|
|
|
|
));
|
2017-06-27 07:37:58 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('complete/cancel', function() {
|
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
it('[external labels AND text annotations] should remove marker to hide element on complete', inject(
|
|
|
|
function(directEditing, elementRegistry) {
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// given
|
|
|
|
var textAnnotation = elementRegistry.get('TextAnnotation_1');
|
|
|
|
directEditing.activate(textAnnotation);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// when
|
|
|
|
directEditing.complete();
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// then
|
|
|
|
var gfx = elementRegistry.getGraphics(textAnnotation);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
expect(gfx.classList.contains('djs-element-hidden')).to.be.false;
|
|
|
|
}
|
|
|
|
));
|
2017-06-27 07:37:58 +00:00
|
|
|
|
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
it('[internal labels] should remove marker to hide label on complete', inject(
|
|
|
|
function(directEditing, elementRegistry) {
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// given
|
|
|
|
var task = elementRegistry.get('Task_1');
|
|
|
|
directEditing.activate(task);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// when
|
|
|
|
directEditing.complete();
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// then
|
|
|
|
var gfx = elementRegistry.getGraphics(task);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
expect(gfx.classList.contains('djs-label-hidden')).to.be.false;
|
|
|
|
}
|
|
|
|
));
|
2017-06-27 07:37:58 +00:00
|
|
|
|
|
|
|
});
|
2017-10-22 20:23:51 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function bbox(el) {
|
|
|
|
return pick(el.getBBox(), [ 'x', 'y', 'width', 'height' ]);
|
|
|
|
}
|