@@ -885,14 +885,14 @@ describe('gridstack', function() {
885885
886886 } ) ;
887887
888- describe ( 'addWidget() with bad string value widget options ' , function ( ) {
888+ describe ( 'addWidget()' , function ( ) {
889889 beforeEach ( function ( ) {
890890 document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
891891 } ) ;
892892 afterEach ( function ( ) {
893893 document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
894894 } ) ;
895- it ( 'should use default' , function ( ) {
895+ it ( 'bad string options should use default' , function ( ) {
896896 let grid = GridStack . init ( ) ;
897897 let widget = grid . addWidget ( widgetHTML , { x : 'foo' , y : null , width : 'bar' , height : '' } as any ) ;
898898
@@ -901,24 +901,26 @@ describe('gridstack', function() {
901901 expect ( parseInt ( widget . getAttribute ( 'data-gs-width' ) , 10 ) ) . toBe ( 1 ) ;
902902 expect ( parseInt ( widget . getAttribute ( 'data-gs-height' ) , 10 ) ) . toBe ( 1 ) ;
903903 } ) ;
904- } ) ;
905-
906- describe ( 'addWidget with null options, ' , function ( ) {
907- beforeEach ( function ( ) {
908- document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
909- } ) ;
910- afterEach ( function ( ) {
911- document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
912- } ) ;
913- it ( 'should clear x position' , function ( ) {
904+ it ( 'null options should clear x position' , function ( ) {
914905 let grid = GridStack . init ( { float : true } ) ;
915906 let widgetHTML = '<div class="grid-stack-item" data-gs-x="9"><div class="grid-stack-item-content"></div></div>' ;
916907 let widget = grid . addWidget ( widgetHTML , { x :null , y :null , width :undefined } ) ;
917908
918909 expect ( parseInt ( widget . getAttribute ( 'data-gs-x' ) , 10 ) ) . toBe ( 8 ) ;
919910 expect ( parseInt ( widget . getAttribute ( 'data-gs-y' ) , 10 ) ) . toBe ( 0 ) ;
920911 } ) ;
921- } ) ;
912+ it ( 'width attr should be retained' , function ( ) { // #1276
913+ let grid = GridStack . init ( { float : true } ) ;
914+ let widgetHTML = '<div class="grid-stack-item" data-gs-width="3" data-gs-max-width="4" data-gs-id="foo"><div class="grid-stack-item-content"></div></div>' ;
915+ let widget = grid . addWidget ( widgetHTML , { x : 1 , y : 5 } ) ;
916+ expect ( parseInt ( widget . getAttribute ( 'data-gs-x' ) , 10 ) ) . toBe ( 1 ) ;
917+ expect ( parseInt ( widget . getAttribute ( 'data-gs-y' ) , 10 ) ) . toBe ( 5 ) ;
918+ expect ( parseInt ( widget . getAttribute ( 'data-gs-width' ) , 10 ) ) . toBe ( 3 ) ;
919+ expect ( parseInt ( widget . getAttribute ( 'data-gs-max-width' ) , 10 ) ) . toBe ( 4 ) ;
920+ expect ( parseInt ( widget . getAttribute ( 'data-gs-height' ) , 10 ) ) . toBe ( 1 ) ;
921+ expect ( widget . getAttribute ( 'data-gs-id' ) ) . toBe ( 'foo' ) ;
922+ } ) ;
923+ } ) ;
922924
923925 describe ( 'method getFloat()' , function ( ) {
924926 beforeEach ( function ( ) {
0 commit comments