@@ -899,14 +899,14 @@ describe('gridstack', function() {
899899
900900 } ) ;
901901
902- describe ( 'addWidget() with bad string value widget options ' , function ( ) {
902+ describe ( 'addWidget()' , function ( ) {
903903 beforeEach ( function ( ) {
904904 document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
905905 } ) ;
906906 afterEach ( function ( ) {
907907 document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
908908 } ) ;
909- it ( 'should use default' , function ( ) {
909+ it ( 'bad string options should use default' , function ( ) {
910910 var grid = GridStack . init ( ) ;
911911 var widget = grid . addWidget ( widgetHTML , { x : 'foo' , y : null , width : 'bar' , height : '' } ) ;
912912 var $widget = $ ( widget ) ;
@@ -915,23 +915,27 @@ describe('gridstack', function() {
915915 expect ( parseInt ( $widget . attr ( 'data-gs-width' ) , 10 ) ) . toBe ( 1 ) ;
916916 expect ( parseInt ( $widget . attr ( 'data-gs-height' ) , 10 ) ) . toBe ( 1 ) ;
917917 } ) ;
918- } ) ;
919-
920- describe ( 'addWidget with null options, ' , function ( ) {
921- beforeEach ( function ( ) {
922- document . body . insertAdjacentHTML ( 'afterbegin' , gridstackHTML ) ;
923- } ) ;
924- afterEach ( function ( ) {
925- document . body . removeChild ( document . getElementById ( 'gs-cont' ) ) ;
926- } ) ;
927- it ( 'should clear x position' , function ( ) {
918+ it ( 'null options should clear x position' , function ( ) {
928919 var grid = GridStack . init ( { float : true } ) ;
929920 var widgetHTML = '<div class="grid-stack-item" data-gs-x="9"><div class="grid-stack-item-content"></div></div>' ;
930921 var widget = grid . addWidget ( widgetHTML , null , null , undefined ) ;
931922 var $widget = $ ( widget ) ;
932923 expect ( parseInt ( $widget . attr ( 'data-gs-x' ) , 10 ) ) . toBe ( 8 ) ;
933924 expect ( parseInt ( $widget . attr ( 'data-gs-y' ) , 10 ) ) . toBe ( 0 ) ;
934925 } ) ;
926+ it ( 'width attr should be retained' , function ( ) { // #1276
927+ var grid = GridStack . init ( { float : true } ) ;
928+ var 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>' ;
929+ var widget = grid . addWidget ( widgetHTML , 1 , 5 ) ;
930+ var $widget = $ ( widget ) ;
931+ expect ( parseInt ( $widget . attr ( 'data-gs-x' ) , 10 ) ) . toBe ( 1 ) ;
932+ expect ( parseInt ( $widget . attr ( 'data-gs-y' ) , 10 ) ) . toBe ( 5 ) ;
933+ expect ( parseInt ( $widget . attr ( 'data-gs-width' ) , 10 ) ) . toBe ( 3 ) ;
934+ expect ( parseInt ( $widget . attr ( 'data-gs-max-width' ) , 10 ) ) . toBe ( 4 ) ;
935+ expect ( parseInt ( $widget . attr ( 'data-gs-height' ) , 10 ) ) . toBe ( 1 ) ;
936+ expect ( $widget . attr ( 'data-gs-id' ) ) . toBe ( 'foo' ) ;
937+ } ) ;
938+
935939 } ) ;
936940
937941 describe ( 'method float()' , function ( ) {
0 commit comments