11/* eslint-disable @typescript-eslint/no-unused-expressions */
2- import { expect } from " @open-wc/testing" ;
2+ import { expect } from ' @open-wc/testing' ;
33
44import {
55 insert ,
@@ -11,35 +11,34 @@ import {
1111 UndoRedoTestCase ,
1212 undoRedoTestCases ,
1313 xmlAttributeName ,
14- } from " @omicronenergy/oscd-test-utils/arbitraries.js" ;
14+ } from ' @omicronenergy/oscd-test-utils' ;
1515
16- import { sclDocString } from "@omicronenergy/oscd-test-utils/scl-sample-docs.js" ;
16+ import { EditV2 , Insert } from '@openscd/oscd-api' ;
17+ import { isEditV2 } from '@openscd/oscd-api/utils.js' ;
1718
18- import { EditV2 , Insert } from "@omicronenergy/oscd-api" ;
19- import { isEditV2 } from "@omicronenergy/oscd-api/utils.js" ;
19+ import { handleEdit } from './handleEdit.js' ;
2020
21- import { handleEdit } from "./handleEdit.js" ;
21+ import { assert , property } from 'fast-check' ;
22+ import { sclDocString } from './XMLEditor.spec.js' ;
2223
23- import { assert , property } from "fast-check" ;
24-
25- it ( "fails at distinguishing EditV2" , ( ) => {
26- expect ( isEditV2 ( [ { node : "notanode" , parent : "notanode" , reference : 42 } ] ) ) . to
24+ it ( 'fails at distinguishing EditV2' , ( ) => {
25+ expect ( isEditV2 ( [ { node : 'notanode' , parent : 'notanode' , reference : 42 } ] ) ) . to
2726 . be . false ;
2827} ) ;
2928
30- describe ( " handleEdit" , ( ) => {
29+ describe ( ' handleEdit' , ( ) => {
3130 let sclDoc : XMLDocument ;
3231
3332 beforeEach ( async ( ) => {
34- sclDoc = new DOMParser ( ) . parseFromString ( sclDocString , " application/xml" ) ;
33+ sclDoc = new DOMParser ( ) . parseFromString ( sclDocString , ' application/xml' ) ;
3534 } ) ;
3635
37- it ( " does nothing given invalid input" , ( ) => {
36+ it ( ' does nothing given invalid input' , ( ) => {
3837 const sclDocStringBefore = new XMLSerializer ( ) . serializeToString ( sclDoc ) ;
3938
4039 const parent = sclDoc . documentElement ;
41- const node = sclDoc . createElement ( " test" ) ;
42- const reference = sclDoc . querySelector ( " Substation" ) ;
40+ const node = sclDoc . createElement ( ' test' ) ;
41+ const reference = sclDoc . querySelector ( ' Substation' ) ;
4342 const invalidedit = {
4443 parent,
4544 someinvalidkey : node ,
@@ -50,71 +49,71 @@ describe("handleEdit", () => {
5049
5150 const sclDocStringAfter = new XMLSerializer ( ) . serializeToString ( sclDoc ) ;
5251
53- expect ( undoEdit ) . to . be . an ( " array" ) . that . is . empty ;
52+ expect ( undoEdit ) . to . be . an ( ' array' ) . that . is . empty ;
5453 expect ( sclDocStringBefore ) . to . equal ( sclDocStringAfter ) ;
5554 } ) ;
5655
57- it ( " inserts an element given an Insert" , ( ) => {
56+ it ( ' inserts an element given an Insert' , ( ) => {
5857 const parent = sclDoc . documentElement ;
59- const node = sclDoc . createElement ( " test" ) ;
60- const reference = sclDoc . querySelector ( " Substation" ) ;
58+ const node = sclDoc . createElement ( ' test' ) ;
59+ const reference = sclDoc . querySelector ( ' Substation' ) ;
6160 handleEdit ( { parent, node, reference } ) ;
62- expect ( sclDoc . documentElement . querySelector ( " test" ) ) . to . have . property (
63- " nextSibling" ,
61+ expect ( sclDoc . documentElement . querySelector ( ' test' ) ) . to . have . property (
62+ ' nextSibling' ,
6463 reference ,
6564 ) ;
6665 } ) ;
6766
68- it ( " removes an element given a Remove" , ( ) => {
69- const node = sclDoc . querySelector ( " Substation" ) ! ;
67+ it ( ' removes an element given a Remove' , ( ) => {
68+ const node = sclDoc . querySelector ( ' Substation' ) ! ;
7069 handleEdit ( { node } ) ;
71- expect ( sclDoc . querySelector ( " Substation" ) ) . to . not . exist ;
70+ expect ( sclDoc . querySelector ( ' Substation' ) ) . to . not . exist ;
7271 } ) ;
7372
7473 it ( "updates an element's attributes given a SetAttributes" , ( ) => {
75- const element = sclDoc . querySelector ( " Substation" ) ! ;
74+ const element = sclDoc . querySelector ( ' Substation' ) ! ;
7675 handleEdit ( {
7776 element,
7877 attributes : {
79- name : "A2" ,
78+ name : 'A2' ,
8079 desc : null ,
81- [ " __proto__" ] : " a string" , // covers a rare edge case branch
82- " 42isnotValid" : " something" ,
80+ [ ' __proto__' ] : ' a string' , // covers a rare edge case branch
81+ ' 42isnotValid' : ' something' ,
8382 } ,
8483 attributesNS : {
85- " http://example.org/somePreexistingExtensionNamespace" : {
86- " ens1:test" : null ,
84+ ' http://example.org/somePreexistingExtensionNamespace' : {
85+ ' ens1:test' : null ,
8786 } ,
88- " http://example.org/myns" : {
89- " myns:attr" : " value1" ,
90- " myns:attr2" : " value1" ,
91- " myns:-is-not-valid-either" : " something" ,
87+ ' http://example.org/myns' : {
88+ ' myns:attr' : ' value1' ,
89+ ' myns:attr2' : ' value1' ,
90+ ' myns:-is-not-valid-either' : ' something' ,
9291 } ,
9392 } ,
9493 } ) ;
9594
96- expect ( element . getAttribute ( " name" ) ) . to . equal ( "A2" ) ;
97- expect ( element . getAttribute ( " desc" ) ) . to . be . null ;
98- expect ( element . getAttribute ( " __proto__" ) ) . to . equal ( " a string" ) ;
99- expect ( element . getAttribute ( " myns:attr" ) ) . to . equal ( " value1" ) ;
100- expect ( element . getAttribute ( " myns:attr2" ) ) . to . equal ( " value1" ) ;
101- expect ( element . getAttribute ( " 42isnotValid" ) ) . to . not . exist ;
95+ expect ( element . getAttribute ( ' name' ) ) . to . equal ( 'A2' ) ;
96+ expect ( element . getAttribute ( ' desc' ) ) . to . be . null ;
97+ expect ( element . getAttribute ( ' __proto__' ) ) . to . equal ( ' a string' ) ;
98+ expect ( element . getAttribute ( ' myns:attr' ) ) . to . equal ( ' value1' ) ;
99+ expect ( element . getAttribute ( ' myns:attr2' ) ) . to . equal ( ' value1' ) ;
100+ expect ( element . getAttribute ( ' 42isnotValid' ) ) . to . not . exist ;
102101 expect (
103- element . getAttributeNS ( " http://example.org/myns" , " -is-not-valid-either" ) ,
102+ element . getAttributeNS ( ' http://example.org/myns' , ' -is-not-valid-either' ) ,
104103 ) . to . not . exist ;
105- expect ( element . getAttribute ( " myns:-is-not-valid-either" ) ) . to . not . exist ;
104+ expect ( element . getAttribute ( ' myns:-is-not-valid-either' ) ) . to . not . exist ;
106105 expect (
107106 element . getAttributeNS (
108- " http://example.org/somePreexistingExtensionNamespace" ,
109- " test" ,
107+ ' http://example.org/somePreexistingExtensionNamespace' ,
108+ ' test' ,
110109 ) ,
111110 ) . to . be . null ;
112111 } ) ;
113112
114113 it ( "sets an element's textContent given a SetTextContent" , ( ) => {
115- const element = sclDoc . querySelector ( " SCL" ) ! ;
114+ const element = sclDoc . querySelector ( ' SCL' ) ! ;
116115
117- const newTextContent = " someNewTextContent" ;
116+ const newTextContent = ' someNewTextContent' ;
118117 handleEdit ( {
119118 element,
120119 textContent : newTextContent ,
@@ -123,49 +122,49 @@ describe("handleEdit", () => {
123122 expect ( element . textContent ) . to . equal ( newTextContent ) ;
124123 } ) ;
125124
126- it ( " processes complex edits in the given order" , ( ) => {
125+ it ( ' processes complex edits in the given order' , ( ) => {
127126 const parent = sclDoc . documentElement ;
128- const reference = sclDoc . querySelector ( " Substation" ) ;
129- const node1 = sclDoc . createElement ( " test1" ) ;
130- const node2 = sclDoc . createElement ( " test2" ) ;
127+ const reference = sclDoc . querySelector ( ' Substation' ) ;
128+ const node1 = sclDoc . createElement ( ' test1' ) ;
129+ const node2 = sclDoc . createElement ( ' test2' ) ;
131130 handleEdit ( [
132131 { parent, node : node1 , reference } ,
133132 { parent, node : node2 , reference } ,
134133 ] ) ;
135- expect ( sclDoc . documentElement . querySelector ( " test1" ) ) . to . have . property (
136- " nextSibling" ,
134+ expect ( sclDoc . documentElement . querySelector ( ' test1' ) ) . to . have . property (
135+ ' nextSibling' ,
137136 node2 ,
138137 ) ;
139- expect ( sclDoc . documentElement . querySelector ( " test2" ) ) . to . have . property (
140- " nextSibling" ,
138+ expect ( sclDoc . documentElement . querySelector ( ' test2' ) ) . to . have . property (
139+ ' nextSibling' ,
141140 reference ,
142141 ) ;
143142 } ) ;
144143
145- it ( " returns an undo edit that undoes the original edit" , ( ) => {
146- const node = sclDoc . querySelector ( " Substation" ) ! ;
144+ it ( ' returns an undo edit that undoes the original edit' , ( ) => {
145+ const node = sclDoc . querySelector ( ' Substation' ) ! ;
147146 const undoEdit = handleEdit ( { node } ) ; // do edit
148147 handleEdit ( undoEdit ) ; // undo edit
149- expect ( sclDoc . querySelector ( " Substation" ) ) . to . exist ;
148+ expect ( sclDoc . querySelector ( ' Substation' ) ) . to . exist ;
150149 } ) ;
151150
152- it ( " returns the original edit when called on an undo edit" , ( ) => {
153- const node = sclDoc . querySelector ( " Substation" ) ! ;
151+ it ( ' returns the original edit when called on an undo edit' , ( ) => {
152+ const node = sclDoc . querySelector ( ' Substation' ) ! ;
154153 const undoEdit = handleEdit ( { node } ) ;
155154 const redoEdit = handleEdit ( undoEdit ) ;
156155 handleEdit ( redoEdit ) ;
157- expect ( sclDoc . querySelector ( " Substation" ) ) . to . not . exist ;
156+ expect ( sclDoc . querySelector ( ' Substation' ) ) . to . not . exist ;
158157 } ) ;
159158
160- describe ( " generally" , ( ) => {
161- it ( " inserts elements given Inserts" , ( ) =>
159+ describe ( ' generally' , ( ) => {
160+ it ( ' inserts elements given Inserts' , ( ) =>
162161 assert (
163162 property (
164163 testDocs . chain ( ( [ doc1 , doc2 ] ) => {
165164 const nodes = doc1 . nodes . concat ( doc2 . nodes ) ;
166165 return insert ( nodes ) ;
167166 } ) ,
168- ( edit ) => {
167+ edit => {
169168 handleEdit ( edit ) ;
170169 if ( isValidInsert ( edit ) )
171170 return (
@@ -184,24 +183,24 @@ describe("handleEdit", () => {
184183 const nodes = doc1 . nodes . concat ( doc2 . nodes ) ;
185184 return setTextContent ( nodes ) ;
186185 } ) ,
187- ( edit ) => {
186+ edit => {
188187 handleEdit ( edit ) ;
189188
190189 return edit . element . textContent === edit . textContent ;
191190 } ,
192191 ) ,
193192 ) ) ;
194193
195- it ( " updates attributes given SetAttributes" , ( ) =>
194+ it ( ' updates attributes given SetAttributes' , ( ) =>
196195 assert (
197196 property (
198197 testDocs . chain ( ( [ { nodes } ] ) => setAttributes ( nodes ) ) ,
199- ( edit ) => {
198+ edit => {
200199 handleEdit ( edit ) ;
201200 const attributesHandledCorrectly = edit . attributes
202201 ? Object . entries ( edit . attributes )
203202 . filter ( ( [ name ] ) => xmlAttributeName . test ( name ) )
204- . map ( ( entry ) => entry as [ string , string | null ] )
203+ . map ( entry => entry as [ string , string | null ] )
205204 . every (
206205 ( [ name , value ] ) =>
207206 edit . element . getAttribute ( name ) === value ,
@@ -210,15 +209,15 @@ describe("handleEdit", () => {
210209 const attributesNSHandledCorrectly = edit . attributesNS
211210 ? Object . entries ( edit . attributesNS )
212211 . map (
213- ( entry ) => entry as [ string , Record < string , string | null > ] ,
212+ entry => entry as [ string , Record < string , string | null > ] ,
214213 )
215214 . every ( ( [ ns , attributes ] ) => {
216215 const unprefixedAttributes = Object . fromEntries (
217216 Object . entries ( attributes )
218217 . filter ( ( [ name ] ) => xmlAttributeName . test ( name ) )
219- . map ( ( entry ) => entry as [ string , string | null ] )
218+ . map ( entry => entry as [ string , string | null ] )
220219 . map ( ( [ name , value ] ) => [
221- name . split ( ":" , 2 ) . pop ( ) ,
220+ name . split ( ':' , 2 ) . pop ( ) ,
222221 value ,
223222 ] )
224223 . filter ( ( [ name ] ) => name ) ,
@@ -234,7 +233,7 @@ describe("handleEdit", () => {
234233 ) ,
235234 ) ) . timeout ( 20000 ) ;
236235
237- it ( " removes elements given Removes" , ( ) =>
236+ it ( ' removes elements given Removes' , ( ) =>
238237 assert (
239238 property (
240239 testDocs . chain ( ( [ { nodes } ] ) => remove ( nodes ) ) ,
@@ -245,12 +244,12 @@ describe("handleEdit", () => {
245244 ) ,
246245 ) ) ;
247246
248- it ( " leaves the document unchanged after undoing all edits" , ( ) =>
247+ it ( ' leaves the document unchanged after undoing all edits' , ( ) =>
249248 assert (
250249 property (
251- testDocs . chain ( ( docs ) => undoRedoTestCases ( ...docs ) ) ,
250+ testDocs . chain ( docs => undoRedoTestCases ( ...docs ) ) ,
252251 ( { doc1, doc2, edits } : UndoRedoTestCase ) => {
253- const [ oldDoc1 , oldDoc2 ] = [ doc1 , doc2 ] . map ( ( doc ) =>
252+ const [ oldDoc1 , oldDoc2 ] = [ doc1 , doc2 ] . map ( doc =>
254253 doc . cloneNode ( true ) ,
255254 ) ;
256255 const undoEdits : EditV2 [ ] = [ ] ;
@@ -270,16 +269,16 @@ describe("handleEdit", () => {
270269 ) ,
271270 ) ) . timeout ( 20000 ) ;
272271
273- it ( " changes the document the same way when redoing undone edits" , ( ) =>
272+ it ( ' changes the document the same way when redoing undone edits' , ( ) =>
274273 assert (
275274 property (
276- testDocs . chain ( ( docs ) => undoRedoTestCases ( ...docs ) ) ,
275+ testDocs . chain ( docs => undoRedoTestCases ( ...docs ) ) ,
277276 ( { doc1, doc2, edits } : UndoRedoTestCase ) => {
278277 const undoEdits : EditV2 [ ] = [ ] ;
279278 edits . forEach ( ( a : EditV2 ) => {
280279 undoEdits . unshift ( handleEdit ( a ) ) ;
281280 } ) ;
282- const [ oldDoc1 , oldDoc2 ] = [ doc1 , doc2 ] . map ( ( doc ) =>
281+ const [ oldDoc1 , oldDoc2 ] = [ doc1 , doc2 ] . map ( doc =>
283282 new XMLSerializer ( ) . serializeToString ( doc ) ,
284283 ) ;
285284 const redoEdits : EditV2 [ ] = [ ] ;
@@ -288,7 +287,7 @@ describe("handleEdit", () => {
288287 redoEdits . unshift ( handleEdit ( undoEdits ) ) ;
289288 handleEdit ( redoEdits ) ;
290289 }
291- const [ newDoc1 , newDoc2 ] = [ doc1 , doc2 ] . map ( ( doc ) =>
290+ const [ newDoc1 , newDoc2 ] = [ doc1 , doc2 ] . map ( doc =>
292291 new XMLSerializer ( ) . serializeToString ( doc ) ,
293292 ) ;
294293 return oldDoc1 === newDoc1 && oldDoc2 === newDoc2 ;
0 commit comments