@@ -2,6 +2,7 @@ import TestContainer from 'mocha-test-container-support';
2
2
3
3
import {
4
4
bootstrapModeler ,
5
+ bootstrapPropertiesPanel ,
5
6
inject
6
7
} from 'test/TestHelper' ;
7
8
@@ -17,12 +18,18 @@ import messageDiagramXML from './fixtures/condition-message.bpmn';
17
18
18
19
import template from './fixtures/condition.json' ;
19
20
import messageTemplates from './fixtures/condition-message.json' ;
21
+ import dropdownConditions from './fixtures/condition-dropdown.json' ;
20
22
import { getBusinessObject } from 'bpmn-js/lib/util/ModelUtil' ;
21
23
import { findExtension , findMessage , findZeebeSubscription } from 'src/cloud-element-templates/Helper' ;
22
24
import ElementTemplatesConditionChecker from 'src/cloud-element-templates/ElementTemplatesConditionChecker' ;
23
25
import { getBpmnJS } from 'bpmn-js/test/helper' ;
24
26
import { isString } from 'min-dash' ;
25
27
28
+ import {
29
+ query as domQuery
30
+ } from 'min-dom' ;
31
+
32
+ import { act } from '@testing-library/preact' ;
26
33
27
34
describe ( 'provider/cloud-element-templates - ElementTemplatesConditionChecker' , function ( ) {
28
35
@@ -1116,6 +1123,147 @@ describe('provider/cloud-element-templates - ElementTemplatesConditionChecker',
1116
1123
} )
1117
1124
) ;
1118
1125
} ) ;
1126
+
1127
+
1128
+ describe ( 'conditional dropdown choices' , function ( ) {
1129
+
1130
+ beforeEach ( bootstrapPropertiesPanel ( diagramXML , {
1131
+ container : container ,
1132
+ modules : [
1133
+ coreModule ,
1134
+ elementTemplatesModule ,
1135
+ modelingModule ,
1136
+ ElementTemplatesConditionChecker ,
1137
+ BpmnPropertiesPanelModule
1138
+ ] ,
1139
+ moddleExtensions : {
1140
+ zeebe : zeebeModdlePackage
1141
+ }
1142
+ } ) ) ;
1143
+
1144
+ beforeEach ( inject ( function ( elementTemplates ) {
1145
+ elementTemplates . set ( [ dropdownConditions ] ) ;
1146
+ } ) ) ;
1147
+
1148
+
1149
+ it ( 'should add conditional entries' , inject (
1150
+ async function ( elementRegistry , modeling , selection ) {
1151
+
1152
+ // given
1153
+ const element = elementRegistry . get ( 'Task_1' ) ;
1154
+
1155
+ changeTemplate ( element , dropdownConditions ) ;
1156
+
1157
+ // when
1158
+ await act ( ( ) => {
1159
+ selection . select ( element ) ;
1160
+ modeling . updateProperties ( element , { name : 'foo' } ) ;
1161
+ } ) ;
1162
+
1163
+ // then
1164
+ expectDropdownOptions ( container , 2 , 'foo' ) ;
1165
+ } )
1166
+ ) ;
1167
+
1168
+
1169
+ it ( 'should switch between conditional properties' , inject (
1170
+ async function ( elementRegistry , modeling , selection ) {
1171
+
1172
+ // given
1173
+ const element = elementRegistry . get ( 'Task_1' ) ;
1174
+
1175
+ changeTemplate ( element , dropdownConditions ) ;
1176
+
1177
+ // when
1178
+ await act ( ( ) => {
1179
+ selection . select ( element ) ;
1180
+ modeling . updateProperties ( element , { name : 'foo' } ) ;
1181
+ } ) ;
1182
+
1183
+ // then
1184
+ expectDropdownOptions ( container , 2 , 'foo' ) ;
1185
+
1186
+ // when
1187
+ await act ( ( ) =>
1188
+ modeling . updateProperties ( element , { name : 'bar' } )
1189
+ ) ;
1190
+
1191
+ // then
1192
+ expectDropdownOptions ( container , 2 , 'bar' ) ;
1193
+ } )
1194
+ ) ;
1195
+
1196
+
1197
+ it ( 'undo' , inject ( async function ( commandStack , elementRegistry , modeling , selection ) {
1198
+
1199
+ // given
1200
+ const element = elementRegistry . get ( 'Task_1' ) ;
1201
+
1202
+ changeTemplate ( element , dropdownConditions ) ;
1203
+
1204
+ // when
1205
+ await act ( ( ) => {
1206
+ selection . select ( element ) ;
1207
+ modeling . updateProperties ( element , { name : 'foo' } ) ;
1208
+ } ) ;
1209
+
1210
+ // assume
1211
+ expectDropdownOptions ( container , 2 , 'foo' ) ;
1212
+
1213
+ // when
1214
+ await act ( ( ) => commandStack . undo ( ) ) ;
1215
+
1216
+ // then
1217
+ expectDropdownOptions ( container , 1 , 'foobar' ) ;
1218
+ } ) ) ;
1219
+
1220
+
1221
+ it ( 'redo' , inject ( async function ( commandStack , elementRegistry , modeling , selection ) {
1222
+
1223
+ // given
1224
+ const element = elementRegistry . get ( 'Task_1' ) ;
1225
+
1226
+ changeTemplate ( element , dropdownConditions ) ;
1227
+
1228
+ // when
1229
+ await act ( ( ) => {
1230
+ selection . select ( element ) ;
1231
+ modeling . updateProperties ( element , { name : 'foo' } ) ;
1232
+ } ) ;
1233
+
1234
+ // when
1235
+ await act ( ( ) => commandStack . undo ( ) ) ;
1236
+
1237
+ // then
1238
+ expectDropdownOptions ( container , 1 , 'foobar' ) ;
1239
+
1240
+ // when
1241
+ await act ( ( ) => commandStack . redo ( ) ) ;
1242
+
1243
+ // then
1244
+ expectDropdownOptions ( container , 2 , 'foo' ) ;
1245
+ } ) ) ;
1246
+
1247
+
1248
+ it ( 'should remove conditional entries' , inject (
1249
+ async function ( elementRegistry , modeling , selection ) {
1250
+
1251
+ // given
1252
+ const element = elementRegistry . get ( 'Task_1' ) ;
1253
+
1254
+ changeTemplate ( element , dropdownConditions ) ;
1255
+
1256
+ // when
1257
+ await act ( ( ) => {
1258
+ selection . select ( element ) ;
1259
+ modeling . updateProperties ( element , { name : '' } ) ;
1260
+ } ) ;
1261
+
1262
+ // then
1263
+ expectDropdownOptions ( container , 1 , 'foobar' ) ;
1264
+ } )
1265
+ ) ;
1266
+ } ) ;
1119
1267
} ) ;
1120
1268
1121
1269
@@ -1178,4 +1326,11 @@ function expectZeebePropertyValue(businessObject, value) {
1178
1326
expect ( zeebeProperties ) . to . exist ;
1179
1327
expect ( properties ) . to . have . lengthOf ( 1 ) ;
1180
1328
expect ( properties [ 0 ] . value ) . to . eql ( value ) ;
1329
+ }
1330
+
1331
+ function expectDropdownOptions ( container , length , value ) {
1332
+ const selectOptions = domQuery ( 'select' , container ) . options ;
1333
+
1334
+ expect ( selectOptions ) . to . have . lengthOf ( length ) ;
1335
+ expect ( selectOptions [ 0 ] . value ) . to . eql ( value ) ;
1181
1336
}
0 commit comments