@@ -1546,4 +1546,109 @@ QUnit.module('graph', function(hooks) {
1546
1546
assert . notOk ( graph . hasActiveBatch ( ) ) ;
1547
1547
} ) ;
1548
1548
} ) ;
1549
+
1550
+ QUnit . module ( 'graph.transferCellEmbeds()' , function ( ) {
1551
+
1552
+ QUnit . test ( 'should transfer embeds from one element to another' , function ( assert ) {
1553
+
1554
+ const originalElement = new joint . shapes . standard . Rectangle ( ) ;
1555
+ const child = new joint . shapes . standard . Rectangle ( ) ;
1556
+ const replacementElement = new joint . shapes . standard . Rectangle ( ) ;
1557
+
1558
+ originalElement . embed ( child ) ;
1559
+
1560
+ this . graph . addCells ( [ originalElement , child , replacementElement ] ) ;
1561
+ this . graph . transferCellEmbeds ( originalElement , replacementElement ) ;
1562
+
1563
+ assert . equal ( replacementElement . getEmbeddedCells ( ) [ 0 ] , child ) ;
1564
+ assert . equal ( originalElement . getEmbeddedCells ( ) . length , 0 ) ;
1565
+ } ) ;
1566
+
1567
+ QUnit . test ( 'should transfer embeds from an element to a link' , function ( assert ) {
1568
+
1569
+ const link = new joint . shapes . standard . Link ( ) ;
1570
+ const child = new joint . shapes . standard . Rectangle ( ) ;
1571
+ const element = new joint . shapes . standard . Rectangle ( ) ;
1572
+
1573
+ element . embed ( child ) ;
1574
+
1575
+ this . graph . addCells ( [ link , child , element ] ) ;
1576
+ this . graph . transferCellEmbeds ( element , link ) ;
1577
+
1578
+ assert . equal ( link . getEmbeddedCells ( ) [ 0 ] , child ) ;
1579
+ assert . equal ( element . getEmbeddedCells ( ) . length , 0 ) ;
1580
+ } ) ;
1581
+ } ) ;
1582
+
1583
+ QUnit . module ( 'graph.transferCellConnectedLinks()' , function ( ) {
1584
+
1585
+ QUnit . test ( 'should transfer links of an element' , function ( assert ) {
1586
+
1587
+ const originalElement = new joint . shapes . standard . Rectangle ( ) ;
1588
+ const link1 = new joint . shapes . standard . Link ( { source : { id : originalElement . id } } ) ;
1589
+ const link2 = new joint . shapes . standard . Link ( { target : { id : originalElement . id } } ) ;
1590
+ const replacementElement = new joint . shapes . standard . Rectangle ( ) ;
1591
+
1592
+ this . graph . addCells ( [ originalElement , link1 , link2 , replacementElement ] ) ;
1593
+ this . graph . transferCellConnectedLinks ( originalElement , replacementElement ) ;
1594
+
1595
+ assert . equal ( link1 . source ( ) . id , replacementElement . id ) ;
1596
+ assert . equal ( link2 . target ( ) . id , replacementElement . id ) ;
1597
+ } ) ;
1598
+
1599
+ QUnit . test ( 'should transfer links of a link' , function ( assert ) {
1600
+
1601
+ const originalLink = new joint . shapes . standard . Link ( ) ;
1602
+ const link1 = new joint . shapes . standard . Link ( { source : { id : originalLink . id } } ) ;
1603
+ const link2 = new joint . shapes . standard . Link ( { target : { id : originalLink . id } } ) ;
1604
+ const replacementLink = new joint . shapes . standard . Link ( ) ;
1605
+
1606
+ this . graph . addCells ( [ originalLink , link1 , link2 , replacementLink ] ) ;
1607
+ this . graph . transferCellConnectedLinks ( originalLink , replacementLink ) ;
1608
+
1609
+ assert . equal ( link1 . source ( ) . id , replacementLink . id ) ;
1610
+ assert . equal ( link2 . target ( ) . id , replacementLink . id ) ;
1611
+ } ) ;
1612
+
1613
+ QUnit . test ( 'should work when transferring links from a link to an element' , function ( assert ) {
1614
+
1615
+ const originalLink = new joint . shapes . standard . Link ( ) ;
1616
+ const link1 = new joint . shapes . standard . Link ( { source : { id : originalLink . id } } ) ;
1617
+ const link2 = new joint . shapes . standard . Link ( { target : { id : originalLink . id } } ) ;
1618
+ const element = new joint . shapes . standard . Rectangle ( ) ;
1619
+
1620
+ this . graph . addCells ( [ originalLink , link1 , link2 , element ] ) ;
1621
+ this . graph . transferCellConnectedLinks ( originalLink , element ) ;
1622
+
1623
+ assert . equal ( link1 . source ( ) . id , element . id ) ;
1624
+ assert . equal ( link2 . target ( ) . id , element . id ) ;
1625
+ } ) ;
1626
+
1627
+ QUnit . test ( 'should work when transferring links from an element to a link' , function ( assert ) {
1628
+
1629
+ const originalElement = new joint . shapes . standard . Rectangle ( ) ;
1630
+ const link1 = new joint . shapes . standard . Link ( { source : { id : originalElement . id } } ) ;
1631
+ const link2 = new joint . shapes . standard . Link ( { target : { id : originalElement . id } } ) ;
1632
+ const replacementLink = new joint . shapes . standard . Link ( ) ;
1633
+
1634
+ this . graph . addCells ( [ originalElement , link1 , link2 , replacementLink ] ) ;
1635
+ this . graph . transferCellConnectedLinks ( originalElement , replacementLink ) ;
1636
+
1637
+ assert . equal ( link1 . source ( ) . id , replacementLink . id ) ;
1638
+ assert . equal ( link2 . target ( ) . id , replacementLink . id ) ;
1639
+ } ) ;
1640
+
1641
+ QUnit . test ( 'should work with loop links' , function ( assert ) {
1642
+
1643
+ const originalElement = new joint . shapes . standard . Rectangle ( ) ;
1644
+ const link = new joint . shapes . standard . Link ( { source : { id : originalElement . id } , target : { id : originalElement . id } } ) ;
1645
+ const replacementElement = new joint . shapes . standard . Rectangle ( ) ;
1646
+
1647
+ this . graph . addCells ( [ originalElement , link , replacementElement ] ) ;
1648
+ this . graph . transferCellConnectedLinks ( originalElement , replacementElement ) ;
1649
+
1650
+ assert . equal ( link . source ( ) . id , replacementElement . id ) ;
1651
+ assert . equal ( link . target ( ) . id , replacementElement . id ) ;
1652
+ } ) ;
1653
+ } ) ;
1549
1654
} ) ;
0 commit comments