/
AlignElementsMenuProviderSpec.js
121 lines (92 loc) · 2.68 KB
/
AlignElementsMenuProviderSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
bootstrapModeler,
getBpmnJS,
inject
} from 'test/TestHelper';
import {
query as domQuery
} from 'min-dom';
import {
forEach
} from 'min-dash';
import alignElementsModule from 'lib/features/align-elements';
import modelingModule from 'lib/features/modeling';
import coreModule from 'lib/core';
describe('features/align-elements - popup menu', function() {
var testModules = [ alignElementsModule, modelingModule, coreModule ];
var basicXML = require('../../../fixtures/bpmn/align-elements.bpmn');
beforeEach(bootstrapModeler(basicXML, { modules: testModules }));
it('should provide alignment buttons', inject(function(elementRegistry, popupMenu) {
// given
var elements = [
elementRegistry.get('EndEvent_lane'),
elementRegistry.get('Task_lane'),
elementRegistry.get('SubProcess_lane')
];
// when
popupMenu.open(elements, 'align-elements', {
x: 0,
y: 0
});
// then
forEach([
'left',
'center',
'right',
'top',
'middle',
'bottom'
], function(alignment) {
expect(getEntry('align-elements-' + alignment)).to.exist;
});
}));
it('should close popup menu when button is clicked', inject(
function(elementRegistry, popupMenu) {
// given
var elements = [
elementRegistry.get('EndEvent_lane'),
elementRegistry.get('Task_lane'),
elementRegistry.get('SubProcess_lane')
];
popupMenu.open(elements, 'align-elements', {
x: 0,
y: 0
});
var entry = getEntry('align-elements-center');
// when
entry.click();
// then
expect(popupMenu.isOpen()).to.be.false;
})
);
it('should properly size icons even with border-box', inject(function(elementRegistry, popupMenu, canvas) {
// given
var container = canvas.getContainer();
var elements = [
elementRegistry.get('EndEvent_lane'),
elementRegistry.get('Task_lane'),
elementRegistry.get('SubProcess_lane')
];
// when
container.style['box-sizing'] = 'border-box';
popupMenu.open(elements, 'align-elements', {
x: 0,
y: 0
});
// then
var entry = getEntry('align-elements-left'),
icon = domQuery('img', entry);
var bbox = icon.getBoundingClientRect();
expect(bbox.width).to.eql(20);
expect(bbox.height).to.eql(20);
}));
});
// helper //////////////////////////////////////////////////////////////////////
function getEntry(actionName) {
return padEntry(getBpmnJS().invoke(function(popupMenu) {
return popupMenu._current.container;
}), actionName);
}
function padEntry(element, name) {
return domQuery('[data-id="' + name + '"]', element);
}