@@ -12,106 +12,63 @@ define([
12
12
} ) ;
13
13
} ) ;
14
14
15
- describe ( '"initObservable" method' , function ( ) {
16
- it ( 'Check for defined ' , function ( ) {
17
- expect ( sortByObj . hasOwnProperty ( 'initObservable' ) ) . toBeDefined ( ) ;
18
- } ) ;
19
- it ( 'Check method type' , function ( ) {
20
- var type = typeof sortByObj . initObservable ;
21
-
22
- expect ( type ) . toEqual ( 'function' ) ;
23
- } ) ;
24
- it ( 'Check returned value if method called without arguments' , function ( ) {
25
- expect ( sortByObj . initObservable ( ) ) . toBeDefined ( ) ;
26
- } ) ;
27
- it ( 'Check returned value type if method called without arguments' , function ( ) {
28
- var type = typeof sortByObj . initObservable ( ) ;
29
- expect ( type ) . toEqual ( 'object' ) ;
30
- } ) ;
31
- } ) ;
32
-
33
15
describe ( '"preparedOptions" method' , function ( ) {
34
- it ( 'Check for defined ' , function ( ) {
35
- expect ( sortByObj . hasOwnProperty ( 'preparedOptions' ) ) . toBeDefined ( ) ;
36
- } ) ;
37
- it ( 'Check method type' , function ( ) {
38
- var type = typeof sortByObj . preparedOptions ;
39
- expect ( type ) . toEqual ( 'function' ) ;
40
- } ) ;
41
-
42
- it ( 'Check "options" array is empty if sortable is set false' , function ( ) {
16
+ it ( 'return empty array if sorting is disabled for the columns' , function ( ) {
43
17
var columns = [ {
44
18
sortable : false ,
45
19
label : 'magento' ,
46
- index : 'test '
20
+ index : 'name '
47
21
} ] ,
48
- expectedValue = [ ] ;
22
+ options = [ ] ;
49
23
sortByObj . preparedOptions ( columns ) ;
50
- expect ( sortByObj . options ) . toEqual ( expectedValue ) ;
24
+ expect ( sortByObj . options ) . toEqual ( options ) ;
51
25
} ) ;
52
26
53
- it ( 'Check " options" array is set the correct value ' , function ( ) {
27
+ it ( 'return array of options if sorting is enabled for the columns ' , function ( ) {
54
28
var columns = [ {
55
29
sortable : true ,
56
30
label : 'magento' ,
57
- index : 'test '
31
+ index : 'name '
58
32
} ] ,
59
- expectedValue = [ {
60
- value : 'test ' ,
33
+ options = [ {
34
+ value : 'name ' ,
61
35
label : 'magento'
62
36
} ] ;
63
37
sortByObj . preparedOptions ( columns ) ;
64
- expect ( sortByObj . options ) . toEqual ( expectedValue ) ;
38
+ expect ( sortByObj . options ) . toEqual ( options ) ;
65
39
} ) ;
66
40
67
- it ( 'Check "isVisible" set true if column is sortable' , function ( ) {
41
+ it ( 'return "isVisible" method true if column is sortable' , function ( ) {
68
42
var columns = [ {
69
43
sortable : true ,
70
44
label : 'magento' ,
71
- index : 'test '
45
+ index : 'name '
72
46
} ] ;
73
- spyOn ( sortByObj , "isVisible" ) . and . callFake ( function ( ) {
74
- return true ;
75
- } ) ;
76
47
sortByObj . preparedOptions ( columns ) ;
77
- expect ( sortByObj . isVisible ) . toHaveBeenCalled ( ) ;
78
48
expect ( sortByObj . isVisible ( ) ) . toBeTruthy ( ) ;
79
49
} ) ;
80
50
81
- it ( 'Check "isVisible" set true if column is sortable' , function ( ) {
51
+ it ( 'return "isVisible" method false if column is sortable' , function ( ) {
82
52
var columns = [ {
83
- sortable : true ,
53
+ sortable : false ,
84
54
label : 'magento' ,
85
- index : 'test '
55
+ index : 'name '
86
56
} ] ;
87
- spyOn ( sortByObj , "isVisible" ) . and . callFake ( function ( ) {
88
- return false ;
89
- } ) ;
90
57
sortByObj . preparedOptions ( columns ) ;
91
- expect ( sortByObj . isVisible ) . toHaveBeenCalled ( ) ;
92
58
expect ( sortByObj . isVisible ( ) ) . toBeFalsy ( ) ;
93
59
} ) ;
94
60
} ) ;
95
61
describe ( '"applyChanges" method' , function ( ) {
96
- it ( 'Check for defined ' , function ( ) {
97
- expect ( sortByObj . hasOwnProperty ( 'applyChanges' ) ) . toBeDefined ( ) ;
98
- } ) ;
99
- it ( 'Check method type' , function ( ) {
100
- var type = typeof sortByObj . applyChanges ;
101
- expect ( type ) . toEqual ( 'function' ) ;
102
- } ) ;
103
-
104
- it ( 'Check "selectedOption" method has been called' , function ( ) {
105
- spyOn ( sortByObj , 'selectedOption' ) ;
62
+ it ( 'return applied option' , function ( ) {
63
+ var applied = {
64
+ field : 'selectedOption' ,
65
+ direction : 'desc'
66
+ } ;
67
+ spyOn ( sortByObj , 'selectedOption' ) . and . returnValue ( 'selectedOption' ) ;
106
68
sortByObj . applyChanges ( ) ;
69
+ expect ( sortByObj . applied ( ) ) . toEqual ( applied ) ;
107
70
expect ( sortByObj . selectedOption ) . toHaveBeenCalled ( ) ;
108
71
} ) ;
109
-
110
- it ( 'Check "applied" method has been called' , function ( ) {
111
- spyOn ( sortByObj , 'applied' ) ;
112
- sortByObj . applyChanges ( ) ;
113
- expect ( sortByObj . applied ) . toHaveBeenCalled ( ) ;
114
- } ) ;
115
72
} ) ;
116
73
} ) ;
117
74
} ) ;
0 commit comments