1+ describe ( 'gridstack' , function ( ) {
2+ 'use strict' ;
3+
4+ var e ;
5+ var w ;
6+
7+ beforeEach ( function ( ) {
8+ w = window ;
9+ e = w . GridStackUI . Engine ;
10+ } ) ;
11+
12+ describe ( 'setup of gridstack' , function ( ) {
13+
14+ it ( 'should exist setup function.' , function ( ) {
15+
16+ expect ( e ) . not . toBeNull ( ) ;
17+ expect ( typeof e ) . toBe ( 'function' ) ;
18+ } ) ;
19+
20+ it ( 'should set default params correctly.' , function ( ) {
21+ e . call ( w ) ;
22+ expect ( w . width ) . toBeUndefined ( ) ;
23+ expect ( w . float ) . toBe ( false ) ;
24+ expect ( w . height ) . toEqual ( 0 ) ;
25+ expect ( w . nodes ) . toEqual ( [ ] ) ;
26+ expect ( typeof w . onchange ) . toBe ( 'function' ) ;
27+ expect ( w . _updateCounter ) . toEqual ( 0 ) ;
28+ expect ( w . _float ) . toEqual ( w . float ) ;
29+ } ) ;
30+
31+ it ( 'should set params correctly.' , function ( ) {
32+ var fkt = function ( ) { } ;
33+ var arr = [ 1 , 2 , 3 ] ;
34+
35+ e . call ( w , 1 , fkt , true , 2 , arr ) ;
36+ expect ( w . width ) . toEqual ( 1 ) ;
37+ expect ( w . float ) . toBe ( true ) ;
38+ expect ( w . height ) . toEqual ( 2 ) ;
39+ expect ( w . nodes ) . toEqual ( arr ) ;
40+ expect ( w . onchange ) . toEqual ( fkt ) ;
41+ expect ( w . _updateCounter ) . toEqual ( 0 ) ;
42+ expect ( w . _float ) . toEqual ( w . float ) ;
43+ } ) ;
44+
45+
46+ } ) ;
47+
48+ describe ( 'batch update' , function ( ) {
49+
50+ it ( 'should set float and counter when calling batchUpdate.' , function ( ) {
51+ e . prototype . batchUpdate . call ( w ) ;
52+ expect ( w . float ) . toBe ( true ) ;
53+ expect ( w . _updateCounter ) . toEqual ( 1 ) ;
54+ } ) ;
55+
56+ //test commit function
57+
58+ } ) ;
59+
60+ describe ( 'sorting of nodes' , function ( ) {
61+
62+ it ( 'should sort ascending with width.' , function ( ) {
63+ w . nodes = [ { x : 7 , y : 0 } , { x : 4 , y : 4 } , { x : 9 , y : 0 } , { x : 0 , y : 1 } ] ;
64+ e . prototype . _sortNodes . call ( w , 1 ) ;
65+ expect ( w . nodes ) . toEqual ( [ { x : 0 , y : 1 } , { x : 7 , y : 0 } , { x : 4 , y : 4 } , { x : 9 , y : 0 } ] ) ;
66+ } ) ;
67+
68+ it ( 'should sort descending with width.' , function ( ) {
69+ w . nodes = [ { x : 7 , y : 0 } , { x : 4 , y : 4 } , { x : 9 , y : 0 } , { x : 0 , y : 1 } ] ;
70+ e . prototype . _sortNodes . call ( w , - 1 ) ;
71+ expect ( w . nodes ) . toEqual ( [ { x : 9 , y : 0 } , { x : 4 , y : 4 } , { x : 7 , y : 0 } , { x : 0 , y : 1 } ] ) ;
72+ } ) ;
73+
74+ it ( 'should sort ascending without width.' , function ( ) {
75+ w . width = false ;
76+ w . nodes = [ { x : 7 , y : 0 } , { x : 4 , y : 4 } , { x : 9 , y : 0 } , { x : 0 , y : 1 } ] ;
77+ e . prototype . _sortNodes . call ( w , 1 ) ;
78+ expect ( w . nodes ) . toEqual ( [ { x : 0 , y : 1 } , { x : 7 , y : 0 } , { x : 4 , y : 4 } , { x : 9 , y : 0 } ] ) ;
79+ } ) ;
80+
81+ it ( 'should sort descending without width.' , function ( ) {
82+ w . width = false ;
83+ w . nodes = [ { x : 7 , y : 0 } , { x : 4 , y : 4 } , { x : 9 , y : 0 } , { x : 0 , y : 1 } ] ;
84+ e . prototype . _sortNodes . call ( w , - 1 ) ;
85+ expect ( w . nodes ) . toEqual ( [ { x : 9 , y : 0 } , { x : 4 , y : 4 } , { x : 7 , y : 0 } , { x : 0 , y : 1 } ] ) ;
86+ } ) ;
87+
88+ } ) ;
89+
90+
91+
92+ } ) ;
0 commit comments