@@ -35,75 +35,90 @@ describe('dc.dataTable', function () {
35
35
return d . status ;
36
36
} ]
37
37
) ;
38
- chart . render ( ) ;
39
38
} ) ;
40
39
41
- describe ( 'creation' , function ( ) {
42
- it ( 'generates something' , function ( ) {
43
- expect ( chart ) . not . toBeNull ( ) ;
44
- } ) ;
45
- it ( 'registers' , function ( ) {
46
- expect ( dc . hasChart ( chart ) ) . toBeTruthy ( ) ;
47
- } ) ;
48
- it ( 'sets size' , function ( ) {
49
- expect ( chart . size ( ) ) . toEqual ( 3 ) ;
50
- } ) ;
51
- it ( 'sets sortBy' , function ( ) {
52
- expect ( chart . sortBy ( ) ) . not . toBeNull ( ) ;
53
- } ) ;
54
- it ( 'sets order' , function ( ) {
55
- expect ( chart . order ( ) ) . toBe ( d3 . descending ) ;
56
- } ) ;
57
- it ( 'group should be set' , function ( ) {
58
- expect ( chart . group ( ) ) . toEqual ( valueGroup ) ;
59
- } ) ;
60
- it ( 'group tr should not be undefined' , function ( ) {
61
- expect ( typeof ( chart . selectAll ( 'tr.dc-table-group' ) [ 0 ] [ 0 ] ) ) . not . toBe ( 'undefined' ) ;
62
- } ) ;
63
- it ( 'sets column span set on group tr' , function ( ) {
64
- expect ( chart . selectAll ( 'tr.dc-table-group td' ) [ 0 ] [ 0 ] . getAttribute ( 'colspan' ) ) . toEqual ( '2' ) ;
65
- } ) ;
66
- it ( 'creates id column' , function ( ) {
67
- expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 0 ] . innerHTML ) . toEqual ( '9' ) ;
68
- expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 1 ] . innerHTML ) . toEqual ( '8' ) ;
69
- expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 2 ] . innerHTML ) . toEqual ( '3' ) ;
70
- } ) ;
71
- it ( 'creates status column' , function ( ) {
72
- expect ( chart . selectAll ( 'td._1' ) [ 0 ] [ 0 ] . innerHTML ) . toEqual ( 'T' ) ;
73
- expect ( chart . selectAll ( 'td._1' ) [ 0 ] [ 1 ] . innerHTML ) . toEqual ( 'F' ) ;
74
- expect ( chart . selectAll ( 'td._1' ) [ 0 ] [ 2 ] . innerHTML ) . toEqual ( 'T' ) ;
75
- } ) ;
76
- } ) ;
77
-
78
- describe ( 'slicing entries' , function ( ) {
40
+ describe ( 'simple table' , function ( ) {
79
41
beforeEach ( function ( ) {
80
- chart . beginSlice ( 1 ) ;
81
- chart . redraw ( ) ;
42
+ chart . render ( ) ;
82
43
} ) ;
83
44
84
- it ( 'slice beginning' , function ( ) {
85
- expect ( chart . selectAll ( 'tr.dc-table-row' ) [ 0 ] . length ) . toEqual ( 2 ) ;
45
+ describe ( 'creation' , function ( ) {
46
+ it ( 'generates something' , function ( ) {
47
+ expect ( chart ) . not . toBeNull ( ) ;
48
+ } ) ;
49
+ it ( 'registers' , function ( ) {
50
+ expect ( dc . hasChart ( chart ) ) . toBeTruthy ( ) ;
51
+ } ) ;
52
+ it ( 'sets size' , function ( ) {
53
+ expect ( chart . size ( ) ) . toEqual ( 3 ) ;
54
+ } ) ;
55
+ it ( 'sets sortBy' , function ( ) {
56
+ expect ( chart . sortBy ( ) ) . not . toBeNull ( ) ;
57
+ } ) ;
58
+ it ( 'sets order' , function ( ) {
59
+ expect ( chart . order ( ) ) . toBe ( d3 . descending ) ;
60
+ } ) ;
61
+ it ( 'group should be set' , function ( ) {
62
+ expect ( chart . group ( ) ) . toEqual ( valueGroup ) ;
63
+ } ) ;
64
+ it ( 'group tr should not be undefined' , function ( ) {
65
+ expect ( typeof ( chart . selectAll ( 'tr.dc-table-group' ) [ 0 ] [ 0 ] ) ) . not . toBe ( 'undefined' ) ;
66
+ } ) ;
67
+ it ( 'sets column span set on group tr' , function ( ) {
68
+ expect ( chart . selectAll ( 'tr.dc-table-group td' ) [ 0 ] [ 0 ] . getAttribute ( 'colspan' ) ) . toEqual ( '2' ) ;
69
+ } ) ;
70
+ it ( 'creates id column' , function ( ) {
71
+ expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 0 ] . innerHTML ) . toEqual ( '9' ) ;
72
+ expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 1 ] . innerHTML ) . toEqual ( '8' ) ;
73
+ expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 2 ] . innerHTML ) . toEqual ( '3' ) ;
74
+ } ) ;
75
+ it ( 'creates status column' , function ( ) {
76
+ expect ( chart . selectAll ( 'td._1' ) [ 0 ] [ 0 ] . innerHTML ) . toEqual ( 'T' ) ;
77
+ expect ( chart . selectAll ( 'td._1' ) [ 0 ] [ 1 ] . innerHTML ) . toEqual ( 'F' ) ;
78
+ expect ( chart . selectAll ( 'td._1' ) [ 0 ] [ 2 ] . innerHTML ) . toEqual ( 'T' ) ;
79
+ } ) ;
86
80
} ) ;
87
81
88
- it ( 'slice beginning and end' , function ( ) {
89
- chart . endSlice ( 2 ) ;
90
- chart . redraw ( ) ;
82
+ describe ( 'slicing entries' , function ( ) {
83
+ beforeEach ( function ( ) {
84
+ chart . beginSlice ( 1 ) ;
85
+ chart . redraw ( ) ;
86
+ } ) ;
91
87
92
- expect ( chart . selectAll ( 'tr.dc-table-row' ) [ 0 ] . length ) . toEqual ( 1 ) ;
93
- } ) ;
94
- } ) ;
88
+ it ( 'slice beginning' , function ( ) {
89
+ expect ( chart . selectAll ( 'tr.dc-table-row' ) [ 0 ] . length ) . toEqual ( 2 ) ;
90
+ } ) ;
95
91
96
- describe ( 'external filter' , function ( ) {
97
- beforeEach ( function ( ) {
98
- countryDimension . filter ( 'CA' ) ;
99
- chart . redraw ( ) ;
92
+ it ( 'slice beginning and end' , function ( ) {
93
+ chart . endSlice ( 2 ) ;
94
+ chart . redraw ( ) ;
95
+
96
+ expect ( chart . selectAll ( 'tr.dc-table-row' ) [ 0 ] . length ) . toEqual ( 1 ) ;
97
+ } ) ;
100
98
} ) ;
101
- it ( 'renders only filtered data set' , function ( ) {
102
- expect ( chart . selectAll ( 'td._0' ) [ 0 ] . length ) . toEqual ( 2 ) ;
99
+
100
+ describe ( 'external filter' , function ( ) {
101
+ beforeEach ( function ( ) {
102
+ countryDimension . filter ( 'CA' ) ;
103
+ chart . redraw ( ) ;
104
+ } ) ;
105
+ it ( 'renders only filtered data set' , function ( ) {
106
+ expect ( chart . selectAll ( 'td._0' ) [ 0 ] . length ) . toEqual ( 2 ) ;
107
+ } ) ;
108
+ it ( 'renders the correctly filtered records' , function ( ) {
109
+ expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 0 ] . innerHTML ) . toEqual ( '7' ) ;
110
+ expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 1 ] . innerHTML ) . toEqual ( '5' ) ;
111
+ } ) ;
103
112
} ) ;
104
- it ( 'renders the correctly filtered records' , function ( ) {
105
- expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 0 ] . innerHTML ) . toEqual ( '7' ) ;
106
- expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 1 ] . innerHTML ) . toEqual ( '5' ) ;
113
+
114
+ describe ( 'ascending order' , function ( ) {
115
+ beforeEach ( function ( ) {
116
+ chart . order ( d3 . ascending ) ;
117
+ chart . redraw ( ) ;
118
+ } ) ;
119
+ it ( 'uses dimension.bottom() instead of top()' , function ( ) {
120
+ expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 0 ] . innerHTML ) . toEqual ( '1' ) ;
121
+ } ) ;
107
122
} ) ;
108
123
} ) ;
109
124
@@ -128,16 +143,6 @@ describe('dc.dataTable', function () {
128
143
} ) ;
129
144
} ) ;
130
145
131
- describe ( 'ascending order' , function ( ) {
132
- beforeEach ( function ( ) {
133
- chart . order ( d3 . ascending ) ;
134
- chart . redraw ( ) ;
135
- } ) ;
136
- it ( 'uses dimension.bottom() instead of top()' , function ( ) {
137
- expect ( chart . selectAll ( 'td._0' ) [ 0 ] [ 0 ] . innerHTML ) . toEqual ( '1' ) ;
138
- } ) ;
139
- } ) ;
140
-
141
146
describe ( 'specifying chart columns with label' , function ( ) {
142
147
beforeEach ( function ( ) {
143
148
chart . columns ( [ 'state' ] ) ;
@@ -182,14 +187,47 @@ describe('dc.dataTable', function () {
182
187
} ] ) ;
183
188
chart . render ( ) ;
184
189
} ) ;
185
- it ( 'should render result of calling function with field and header for label' , function ( ) {
190
+ it ( 'should produce correct table header with single column' , function ( ) {
191
+ var thead = chart . selectAll ( 'thead' ) ;
192
+ expect ( thead . length ) . toBe ( 1 ) ;
193
+ var tr = thead . selectAll ( 'tr' ) ;
194
+ expect ( tr . length ) . toBe ( 1 ) ;
195
+ var colheader = tr . selectAll ( 'th.dc-table-head' ) [ 0 ] . map ( function ( d ) { return d . textContent ; } ) ;
196
+ expect ( colheader . length ) . toEqual ( 1 ) ;
197
+ expect ( colheader [ 0 ] ) . toEqual ( 'Test ID' ) ;
198
+ } ) ;
199
+
200
+ it ( 'should render correct values in rows' , function ( ) {
186
201
var cols = chart . selectAll ( 'td.dc-table-column' ) [ 0 ] . map ( function ( d ) { return d . textContent ; } ) ;
187
202
var expected = [ 'test9' , 'test8' , 'test3' ] ;
188
203
expect ( cols . length ) . toEqual ( expected . length ) ;
189
- expected . forEach ( function ( d ) {
190
- expect ( cols ) . toContain ( d ) ;
204
+ expected . forEach ( function ( d , i ) {
205
+ expect ( cols [ i ] ) . toEqual ( d ) ;
191
206
} ) ;
192
- var colheader = chart . selectAll ( 'th.dc-table-head' ) [ 0 ] . map ( function ( d ) { return d . textContent ; } ) ;
207
+ } ) ;
208
+ } ) ;
209
+
210
+ describe ( 'with existing table header' , function ( ) {
211
+ beforeEach ( function ( ) {
212
+ // add some garbage for table to replace
213
+ d3 . select ( '#data-table' )
214
+ . selectAll ( 'thead' ) . data ( [ 0 ] ) . enter ( ) . append ( 'thead' )
215
+ . selectAll ( 'tr' ) . data ( [ 1 , 2 ] ) . enter ( ) . append ( 'tr' )
216
+ . selectAll ( 'th' ) . data ( [ 1 , 2 , 3 ] ) . enter ( ) . append ( 'th' ) ;
217
+ chart . columns ( [ {
218
+ label : 'Test ID' ,
219
+ format : function ( d ) {
220
+ return 'test' + d . id ;
221
+ }
222
+ } ] ) ;
223
+ chart . render ( ) ;
224
+ } ) ;
225
+ it ( 'should produce correct table header with single column' , function ( ) {
226
+ var thead = chart . selectAll ( 'thead' ) ;
227
+ expect ( thead . length ) . toBe ( 1 ) ;
228
+ var tr = thead . selectAll ( 'tr' ) ;
229
+ expect ( tr . length ) . toBe ( 1 ) ;
230
+ var colheader = tr . selectAll ( 'th.dc-table-head' ) [ 0 ] . map ( function ( d ) { return d . textContent ; } ) ;
193
231
expect ( colheader . length ) . toEqual ( 1 ) ;
194
232
expect ( colheader [ 0 ] ) . toEqual ( 'Test ID' ) ;
195
233
} ) ;
0 commit comments