@@ -234,4 +234,86 @@ describe('SVG Export', () => {
234234
235235 expect ( svg ) . toContain ( '<line' )
236236 } )
237+
238+ it ( 'handles empty elements array' , ( ) => {
239+ const svg = generateSvg ( [ ] )
240+
241+ expect ( svg ) . toContain ( '<svg' )
242+ expect ( svg ) . toContain ( 'viewBox="0 0 800 600"' )
243+ } )
244+
245+ it ( 'escapes XML special characters in text' , ( ) => {
246+ const elements = [
247+ makeElement ( { id : 'test' , text : '<script>alert("xss")</script>' } ) ,
248+ ]
249+
250+ const svg = generateSvg ( elements )
251+
252+ expect ( svg ) . not . toContain ( '<script>' )
253+ expect ( svg ) . toContain ( '<script>' )
254+ } )
255+ } )
256+
257+ describe ( 'Layout Engine Edge Cases' , ( ) => {
258+ it ( 'handles empty elements array' , ( ) => {
259+ const result = computeLayout ( [ ] )
260+
261+ expect ( result . elementCount ) . toBe ( 0 )
262+ expect ( result . positions ) . toHaveLength ( 0 )
263+ } )
264+
265+ it ( 'handles single element' , ( ) => {
266+ const elements = [ makeElement ( { id : 'single' } ) ]
267+ const result = computeLayout ( elements )
268+
269+ expect ( result . elementCount ) . toBe ( 1 )
270+ expect ( result . positions ) . toHaveLength ( 1 )
271+ } )
272+
273+ it ( 'handles elements with missing dimensions' , ( ) => {
274+ const elements = [
275+ makeElement ( { id : 'no-dims' , width : undefined , height : undefined } ) ,
276+ ]
277+
278+ const result = computeLayout ( elements )
279+
280+ expect ( result . elementCount ) . toBe ( 1 )
281+ expect ( result . positions [ 0 ] . width ) . toBe ( 160 )
282+ expect ( result . positions [ 0 ] . height ) . toBe ( 80 )
283+ } )
284+
285+ it ( 'handles self-referencing arrows gracefully' , ( ) => {
286+ const elements = [
287+ makeElement ( { id : 'self' } ) ,
288+ makeArrow ( 'self' , 'self' ) ,
289+ ]
290+
291+ const graph = buildLayoutGraph ( elements )
292+
293+ expect ( graph . nodes ) . toHaveLength ( 1 )
294+ expect ( graph . edges ) . toHaveLength ( 0 )
295+ } )
296+
297+ it ( 'dagre handles disconnected graph' , ( ) => {
298+ const elements = [
299+ makeElement ( { id : 'a' } ) ,
300+ makeElement ( { id : 'b' } ) ,
301+ ]
302+
303+ const result = computeDagreLayout ( elements )
304+
305+ expect ( result . elementCount ) . toBe ( 2 )
306+ expect ( result . bbox . width ) . toBeGreaterThan ( 0 )
307+ } )
308+
309+ it ( 'force layout handles disconnected graph' , ( ) => {
310+ const elements = [
311+ makeElement ( { id : 'a' } ) ,
312+ makeElement ( { id : 'b' } ) ,
313+ ]
314+
315+ const result = computeForceLayout ( elements )
316+
317+ expect ( result . elementCount ) . toBe ( 2 )
318+ } )
237319} )
0 commit comments