This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
TimerDurationSpec.js
181 lines (120 loc) · 4.05 KB
/
TimerDurationSpec.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/
import {
bootstrapModeler,
inject
} from 'bpmn-js/test/helper';
import {
triggerValue
} from './helper';
import TestContainer from 'mocha-test-container-support';
import propertiesPanelModule from 'bpmn-js-properties-panel';
import {
query as domQuery
} from 'min-dom';
import {
getBusinessObject
} from 'bpmn-js/lib/util/ModelUtil';
import eventDefinitionHelper from 'bpmn-js-properties-panel/lib/helper/EventDefinitionHelper';
import coreModule from 'bpmn-js/lib/core';
import selectionModule from 'diagram-js/lib/features/selection';
import modelingModule from 'bpmn-js/lib/features/modeling';
import propertiesProviderModule from '../';
describe('customs - timer-event duration property', function() {
const diagramXML = require('./TimerDuration.bpmn');
const testModules = [
coreModule, selectionModule, modelingModule,
propertiesPanelModule,
propertiesProviderModule
];
let container;
beforeEach(function() {
container = TestContainer.get(this);
});
beforeEach(bootstrapModeler(diagramXML, {
modules: testModules
}));
beforeEach(inject(function(commandStack, propertiesPanel) {
const undoButton = document.createElement('button');
undoButton.textContent = 'UNDO';
undoButton.addEventListener('click', () => {
commandStack.undo();
});
container.appendChild(undoButton);
propertiesPanel.attachTo(container);
}));
describe('of time duration', function() {
let input, timeDuration;
beforeEach(inject(function(elementRegistry, selection) {
// given
const shape = elementRegistry.get('TimerEvent_1');
selection.select(shape);
const bo = getBusinessObject(shape);
const timerDefinition = eventDefinitionHelper.getTimerEventDefinition(bo);
timeDuration = timerDefinition.timeDuration;
input = getInputField(container, 'camunda-timer-event-duration', 'timerDefinition');
// when
triggerValue(input, 'foo', 'change');
}));
describe('in the DOM', function() {
it('should execute', function() {
// then
expect(input.value).to.equal('foo');
});
it('should undo', inject(function(commandStack) {
// when
commandStack.undo();
// then
expect(input.value).to.equal('duration');
}));
it('should redo', inject(function(commandStack) {
// when
commandStack.undo();
commandStack.redo();
// then
expect(input.value).to.equal('foo');
}));
describe('on the business object', function() {
it('should execute', function() {
// then
expect(timeDuration.body).to.equal('foo');
});
it('should undo', inject(function(commandStack) {
// when
commandStack.undo();
// then
expect(timeDuration.body).to.equal('duration');
}));
it('should redo', inject(function(commandStack) {
// when
commandStack.undo();
commandStack.redo();
// then
expect(timeDuration.body).to.equal('foo');
}));
});
});
});
});
// helper /////////
const getGeneralTab = (container) => {
return domQuery('div[data-tab="general"]', container);
};
const getDetailsGroup = (container) => {
const tab = getGeneralTab(container);
return domQuery('div[data-group="details"]', tab);
};
const getEntry = (container, entryId) => {
return domQuery('div[data-entry="' + entryId + '"]', getDetailsGroup(container));
};
const getInputField = (container, entryId, inputName) => {
const selector = 'input' + (inputName ? '[name="' + inputName + '"]' : '');
return domQuery(selector, getEntry(container, entryId));
};