@@ -1770,6 +1770,55 @@ describe('gridstack', function() {
17701770 } ) ;
17711771 } ) ;
17721772
1773+ describe ( 'load' , function ( ) {
1774+ beforeEach ( function ( ) {
1775+ document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
1776+ } ) ;
1777+ afterEach ( function ( ) {
1778+ document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
1779+ } ) ;
1780+ it ( 'after init #1693' , function ( ) {
1781+ let grid = GridStack . init ( ) ;
1782+ grid . load ( [ { id :'gsItem1' , x :0 , y :0 , w :5 , h :1 } , { id :'gsItem2' , x :6 , y :0 , w :2 , h :2 } ] ) ;
1783+
1784+ let el1 = document . getElementById ( 'item1' )
1785+ expect ( parseInt ( el1 . getAttribute ( 'gs-x' ) ) ) . toBe ( 0 ) ;
1786+ expect ( parseInt ( el1 . getAttribute ( 'gs-y' ) ) ) . toBe ( 0 ) ;
1787+ expect ( parseInt ( el1 . getAttribute ( 'gs-w' ) ) ) . toBe ( 5 ) ;
1788+ expect ( parseInt ( el1 . getAttribute ( 'gs-h' ) ) ) . toBe ( 1 ) ;
1789+
1790+ let el2 = document . getElementById ( 'item2' )
1791+ expect ( parseInt ( el2 . getAttribute ( 'gs-x' ) ) ) . toBe ( 6 ) ;
1792+ expect ( parseInt ( el2 . getAttribute ( 'gs-y' ) ) ) . toBe ( 0 ) ;
1793+ expect ( parseInt ( el2 . getAttribute ( 'gs-w' ) ) ) . toBe ( 2 ) ;
1794+ expect ( parseInt ( el2 . getAttribute ( 'gs-h' ) ) ) . toBe ( 2 ) ;
1795+ } ) ;
1796+ it ( 'after init replace nodes' , function ( ) {
1797+ let grid = GridStack . init ( ) ;
1798+ expect ( document . getElementById ( 'item1' ) ) . not . toBe ( null ) ;
1799+ expect ( document . getElementById ( 'item2' ) ) . not . toBe ( null ) ;
1800+
1801+ // this will replace with 2 new nodes
1802+ grid . load ( [ { id :'new1' , x :0 , y :0 , w :5 , h :1 } , { id :'new2' , x :6 , y :0 , w :2 , h :2 } ] ) ;
1803+ expect ( grid . engine . nodes . length ) . toBe ( 2 ) ;
1804+
1805+ expect ( document . getElementById ( 'item1' ) ) . toBe ( null ) ;
1806+ let el1 = grid . engine . nodes . find ( n => n . id === 'new1' ) . el ;
1807+ expect ( parseInt ( el1 . getAttribute ( 'gs-x' ) ) ) . toBe ( 0 ) ;
1808+ expect ( parseInt ( el1 . getAttribute ( 'gs-y' ) ) ) . toBe ( 0 ) ;
1809+ expect ( parseInt ( el1 . getAttribute ( 'gs-w' ) ) ) . toBe ( 5 ) ;
1810+ expect ( parseInt ( el1 . getAttribute ( 'gs-h' ) ) ) . toBe ( 1 ) ;
1811+
1812+ expect ( document . getElementById ( 'item2' ) ) . toBe ( null ) ;
1813+ let el2 = grid . engine . nodes . find ( n => n . id === 'new2' ) . el ;
1814+ expect ( parseInt ( el2 . getAttribute ( 'gs-x' ) ) ) . toBe ( 6 ) ;
1815+ expect ( parseInt ( el2 . getAttribute ( 'gs-y' ) ) ) . toBe ( 0 ) ;
1816+ expect ( parseInt ( el2 . getAttribute ( 'gs-w' ) ) ) . toBe ( 2 ) ;
1817+ expect ( parseInt ( el2 . getAttribute ( 'gs-h' ) ) ) . toBe ( 2 ) ;
1818+ } ) ;
1819+
1820+ } ) ;
1821+
17731822 // ..and finally track log warnings at the end, instead of displaying them....
17741823 describe ( 'obsolete warnings' , function ( ) {
17751824 console . warn = jasmine . createSpy ( 'log' ) ; // track warnings instead of displaying them
0 commit comments