@@ -4,9 +4,15 @@ import { SinonSpy, spy } from 'sinon';
4
4
import '../../mock-wizard.js' ;
5
5
import { MockWizard } from '../../mock-wizard.js' ;
6
6
7
- import { isUpdate , Update , WizardInput } from '../../../src/foundation.js' ;
7
+ import {
8
+ isDelete ,
9
+ isUpdate ,
10
+ Update ,
11
+ WizardInput ,
12
+ } from '../../../src/foundation.js' ;
8
13
import {
9
14
editSampledValueControlWizard ,
15
+ removeSampledValueControlAction ,
10
16
selectSampledValueControlWizard ,
11
17
} from '../../../src/wizards/sampledvaluecontrol.js' ;
12
18
import fc , { integer } from 'fast-check' ;
@@ -265,6 +271,118 @@ describe('Wizards for SCL element SampledValueControl', () => {
265
271
'Signature'
266
272
) ;
267
273
} ) ;
274
+
275
+ describe ( 'contains a remove button that' , ( ) => {
276
+ const ln01smv = < Element > new DOMParser ( ) . parseFromString (
277
+ `<LN0 lnClass="LLN0" lnType="myType">
278
+ <DataSet name="myDataSet"/>
279
+ <DataSet name="myDataSet2"/>
280
+ <SampledValueControl name="myName" datSet="myDataSet"/>
281
+ <ReportControl name="myName2" datSet="myDataSet2"/>
282
+ </LN0>` ,
283
+ 'application/xml'
284
+ ) . documentElement ;
285
+
286
+ const ln02smv2 = < Element > new DOMParser ( ) . parseFromString (
287
+ `<LN0 lnClass="LLN0" lnType="myType">
288
+ <DataSet name="myDataSet"/>
289
+ <SampledValueControl name="myName" datSet="myDataSet"/>
290
+ <SampledValueControl name="myName2" datSet="myDataSet"/>
291
+ </LN0>` ,
292
+ 'application/xml'
293
+ ) . documentElement ;
294
+
295
+ const ln02gse = < Element > new DOMParser ( ) . parseFromString (
296
+ `<LN0 lnClass="LLN0" lnType="myType">
297
+ <DataSet name="myDataSet"/>
298
+ <SampledValueControl name="myName" datSet="myDataSet"/>
299
+ <GSEControl name="myName2" datSet="myDataSet"/>
300
+ </LN0>` ,
301
+ 'application/xml'
302
+ ) . documentElement ;
303
+
304
+ const ln02rp = < Element > new DOMParser ( ) . parseFromString (
305
+ `<LN0 lnClass="LLN0" lnType="myType">
306
+ <DataSet name="myDataSet"/>
307
+ <ReportControl name="myName" datSet="myDataSet"/>
308
+ <SampledValueControl name="myName2" datSet="myDataSet"/>
309
+ </LN0>` ,
310
+ 'application/xml'
311
+ ) . documentElement ;
312
+
313
+ const missingparent = < Element > (
314
+ new DOMParser ( ) . parseFromString (
315
+ `<SampledValueControl name="myName" datSet="myDataSet"/>` ,
316
+ 'application/xml'
317
+ ) . documentElement
318
+ ) ;
319
+
320
+ it ( 'removes SampledValueControl and its referenced DataSet if no other SampledValueControl is assigned' , ( ) => {
321
+ const sampledValueControl = ln01smv . querySelector (
322
+ 'SampledValueControl'
323
+ ) ! ;
324
+ const actions = removeSampledValueControlAction ( sampledValueControl ) ;
325
+ expect ( actions . length ) . to . equal ( 2 ) ;
326
+ expect ( actions [ 0 ] ) . to . satisfy ( isDelete ) ;
327
+ expect ( actions [ 0 ] . old . element ) . to . equal ( sampledValueControl ) ;
328
+ expect ( actions [ 1 ] ) . to . satisfy ( isDelete ) ;
329
+ expect ( actions [ 1 ] . old . element ) . to . equal (
330
+ ln01smv . querySelector ( 'DataSet' )
331
+ ) ;
332
+ } ) ;
333
+
334
+ it ( 'does not remove DataSet with another SampledValueControl referenced' , ( ) => {
335
+ const sampledValueControl = ln02smv2 . querySelector (
336
+ 'SampledValueControl'
337
+ ) ! ;
338
+ const actions = removeSampledValueControlAction ( sampledValueControl ) ;
339
+ expect ( actions . length ) . to . equal ( 1 ) ;
340
+ expect ( actions [ 0 ] ) . to . satisfy ( isDelete ) ;
341
+ expect ( actions [ 0 ] . old . element ) . to . equal ( sampledValueControl ) ;
342
+ } ) ;
343
+
344
+ it ( 'does not remove DataSet with another GSEControl referenced' , ( ) => {
345
+ const sampledValueControl = ln02gse . querySelector (
346
+ 'SampledValueControl'
347
+ ) ! ;
348
+ const actions = removeSampledValueControlAction ( sampledValueControl ) ;
349
+ expect ( actions . length ) . to . equal ( 1 ) ;
350
+ expect ( actions [ 0 ] ) . to . satisfy ( isDelete ) ;
351
+ expect ( actions [ 0 ] . old . element ) . to . equal ( sampledValueControl ) ;
352
+ } ) ;
353
+
354
+ it ( 'does not remove DataSet with another ReportControl referenced' , ( ) => {
355
+ const sampledValueControl = ln02rp . querySelector (
356
+ 'SampledValueControl'
357
+ ) ! ;
358
+ const actions = removeSampledValueControlAction ( sampledValueControl ) ;
359
+ expect ( actions . length ) . to . equal ( 1 ) ;
360
+ expect ( actions [ 0 ] ) . to . satisfy ( isDelete ) ;
361
+ expect ( actions [ 0 ] . old . element ) . to . equal ( sampledValueControl ) ;
362
+ } ) ;
363
+
364
+ it ( 'does not remove with missing parent element' , ( ) => {
365
+ const actions = removeSampledValueControlAction ( missingparent ) ;
366
+ expect ( actions . length ) . to . equal ( 0 ) ;
367
+ } ) ;
368
+
369
+ it ( 'removes referenced SMV element in the Communication section' , ( ) => {
370
+ const sampledValueControl = doc . querySelector (
371
+ 'IED[name="IED3"] SampledValueControl'
372
+ ) ! ;
373
+ const actions = removeSampledValueControlAction ( sampledValueControl ) ;
374
+ expect ( actions . length ) . to . equal ( 3 ) ;
375
+ expect ( actions [ 0 ] ) . to . satisfy ( isDelete ) ;
376
+ expect ( actions [ 0 ] . old . element ) . to . equal ( sampledValueControl ) ;
377
+ expect ( actions [ 1 ] ) . to . satisfy ( isDelete ) ;
378
+ expect ( actions [ 2 ] ) . to . satisfy ( isDelete ) ;
379
+ expect ( actions [ 2 ] . old . element ) . to . equal (
380
+ doc . querySelector (
381
+ 'Communication SMV[ldInst="MU01"][cbName="MSVCB01"]'
382
+ )
383
+ ) ;
384
+ } ) ;
385
+ } ) ;
268
386
} ) ;
269
387
270
388
describe ( 'define a select wizard that' , ( ) => {
0 commit comments