@@ -7,12 +7,13 @@ import { createUpdateAction, newActionEvent } from '../../src/foundation.js';
7
7
8
8
describe ( 'EditingElement' , ( ) => {
9
9
let elm : MockEditor ;
10
+ let doc : XMLDocument ;
10
11
let parent : Element ;
11
12
let element : Element ;
12
13
let reference : Node | null ;
13
14
14
15
beforeEach ( async ( ) => {
15
- const doc = await fetch ( '/test/testfiles/Editing.scd' )
16
+ doc = await fetch ( '/test/testfiles/Editing.scd' )
16
17
. then ( response => response . text ( ) )
17
18
. then ( str => new DOMParser ( ) . parseFromString ( str , 'application/xml' ) ) ;
18
19
elm = < MockEditor > (
@@ -114,6 +115,22 @@ describe('EditingElement', () => {
114
115
expect ( parent . querySelectorAll ( 'Bay[name="Q01"]' ) . length ) . to . be . equal ( 1 ) ;
115
116
} ) ;
116
117
118
+ it ( 'does not creates an element on id attribute conflict' , ( ) => {
119
+ const newElement = elm . doc ! . createElement ( 'DOType' ) ;
120
+ newElement ?. setAttribute ( 'id' , 'testId' ) ;
121
+
122
+ elm . dispatchEvent (
123
+ newActionEvent ( {
124
+ new : {
125
+ parent : doc . querySelector ( 'DataTypeTemplates' ) ! ,
126
+ element : newElement ,
127
+ reference : null ,
128
+ } ,
129
+ } )
130
+ ) ;
131
+ expect ( doc . querySelector ( 'DOType' ) ) . to . be . null ;
132
+ } ) ;
133
+
117
134
it ( 'deletes an element on receiving a Delete action' , ( ) => {
118
135
elm . dispatchEvent (
119
136
newActionEvent ( {
@@ -163,7 +180,7 @@ describe('EditingElement', () => {
163
180
expect ( testNode . parentNode ) . to . null ;
164
181
} ) ;
165
182
166
- it ( 'replaces an element on receiving an Delete action' , ( ) => {
183
+ it ( 'replaces an element on receiving an Replace action' , ( ) => {
167
184
elm . dispatchEvent (
168
185
newActionEvent ( {
169
186
old : {
@@ -201,6 +218,46 @@ describe('EditingElement', () => {
201
218
) . to . equal ( parent . querySelector ( 'Bay[name="Q02"]' ) ) ;
202
219
} ) ;
203
220
221
+ it ( 'replaces id defined element on receiving Replace action' , ( ) => {
222
+ expect ( doc . querySelector ( 'LNodeType[id="testId"]' ) ) . to . not . be . null ;
223
+
224
+ const newElement = doc . createElement ( 'LNodeType' ) ;
225
+ newElement ?. setAttribute ( 'id' , 'testId3' ) ;
226
+
227
+ elm . dispatchEvent (
228
+ newActionEvent ( {
229
+ old : {
230
+ element : doc . querySelector ( 'LNodeType[id="testId"]' ) ! ,
231
+ } ,
232
+ new : {
233
+ element : newElement ,
234
+ } ,
235
+ } )
236
+ ) ;
237
+ expect ( doc . querySelector ( 'LNodeType[id="testId"]' ) ) . to . be . null ;
238
+ expect ( doc . querySelector ( 'LNodeType[id="testId3"]' ) ) . to . not . be . null ;
239
+ } ) ;
240
+
241
+ it ( 'does not replace an element with name conflict' , ( ) => {
242
+ expect ( doc . querySelector ( 'LNodeType[id="testId"]' ) ) . to . not . be . null ;
243
+
244
+ const newElement = elm . doc ! . createElement ( 'LNodeType' ) ;
245
+ newElement ?. setAttribute ( 'id' , 'testId1' ) ;
246
+
247
+ elm . dispatchEvent (
248
+ newActionEvent ( {
249
+ old : {
250
+ element : doc . querySelector ( 'LNodeType[id="testId"]' ) ! ,
251
+ } ,
252
+ new : {
253
+ element : newElement ,
254
+ } ,
255
+ } )
256
+ ) ;
257
+ expect ( doc . querySelector ( 'LNodeType[id="testId"]' ) ) . to . not . be . null ;
258
+ expect ( doc . querySelector ( 'LNodeType[id="testId1"]' ) ) . to . be . null ;
259
+ } ) ;
260
+
204
261
it ( 'moves an element on receiving a Move action' , ( ) => {
205
262
elm . dispatchEvent (
206
263
newActionEvent ( {
@@ -278,6 +335,20 @@ describe('EditingElement', () => {
278
335
expect ( element ) . to . not . have . attribute ( 'desc' ) ;
279
336
} ) ;
280
337
338
+ it ( 'not update an element with id conflict' , ( ) => {
339
+ const newAttributes : Record < string , string | null > = { } ;
340
+ newAttributes [ 'id' ] = 'testId1' ;
341
+
342
+ elm . dispatchEvent (
343
+ newActionEvent (
344
+ createUpdateAction ( doc . querySelector ( 'LNodeType' ) ! , newAttributes )
345
+ )
346
+ ) ;
347
+
348
+ expect ( doc . querySelector ( 'LNodeType[id="testId"]' ) ) . to . exist ;
349
+ expect ( doc . querySelector ( 'LNodeType[id="testId1"]' ) ) . to . not . exist ;
350
+ } ) ;
351
+
281
352
it ( 'does not update an element with name conflict' , ( ) => {
282
353
const newAttributes : Record < string , string | null > = { } ;
283
354
newAttributes [ 'name' ] = 'Q02' ;
@@ -291,6 +362,20 @@ describe('EditingElement', () => {
291
362
expect ( element ) . to . have . attribute ( 'desc' , 'Bay' ) ;
292
363
} ) ;
293
364
365
+ it ( 'does not update an element with id conflict' , ( ) => {
366
+ const newAttributes : Record < string , string | null > = { } ;
367
+ newAttributes [ 'id' ] = 'testId1' ;
368
+
369
+ elm . dispatchEvent (
370
+ newActionEvent (
371
+ createUpdateAction ( doc . querySelector ( 'LNodeType' ) ! , newAttributes )
372
+ )
373
+ ) ;
374
+
375
+ expect ( doc . querySelector ( 'LNodeType[id="testId"]' ) ) . to . exist ;
376
+ expect ( doc . querySelector ( 'LNodeType[id="testId1"]' ) ) . to . not . exist ;
377
+ } ) ;
378
+
294
379
it ( 'carries out subactions sequentially on receiving a ComplexAction' , ( ) => {
295
380
const child3 = elm . doc ! . createElement ( 'newBay' ) ;
296
381
elm . dispatchEvent (
0 commit comments