@@ -37,6 +37,13 @@ describe('dc.selectMenu', function() {
37
37
it ( 'creates select tag' , function ( ) {
38
38
expect ( chart . selectAll ( "select" ) . length ) . toEqual ( 1 ) ;
39
39
} ) ;
40
+ it ( 'select tag is not a multiple select by default' , function ( ) {
41
+ expect ( chart . selectAll ( "select" ) . attr ( "multiple" ) ) . toBeNull ( ) ;
42
+ } ) ;
43
+ it ( 'can be made into a multiple' , function ( ) {
44
+ chart . multiple ( true ) . redraw ( ) ;
45
+ expect ( chart . selectAll ( "select" ) . attr ( "multiple" ) ) . toBeTruthy ( ) ;
46
+ } ) ;
40
47
it ( 'creates prompt option with empty value' , function ( ) {
41
48
var option = chart . selectAll ( "option" ) [ 0 ] [ 0 ] ;
42
49
expect ( option ) . toBeTruthy ( ) ;
@@ -76,36 +83,82 @@ describe('dc.selectMenu', function() {
76
83
last_option = getOption ( chart , last_index ) ;
77
84
expect ( last_option . text ) . toEqual ( "Mississippi: 2" ) ;
78
85
} ) ;
79
- } )
86
+ } ) ;
87
+
88
+ describe ( 'regular single select' , function ( ) {
89
+ describe ( 'selecting an option' , function ( ) {
90
+ it ( 'filters dimension based on selected option\'s value' , function ( ) {
91
+ chart . onChange ( stateGroup . all ( ) [ 0 ] . key ) ;
92
+ expect ( chart . filter ( ) ) . toEqual ( "California" ) ;
93
+ } ) ;
94
+ it ( 'replaces filter on second selection' , function ( ) {
95
+ chart . onChange ( stateGroup . all ( ) [ 0 ] . key ) ;
96
+ chart . onChange ( stateGroup . all ( ) [ 1 ] . key ) ;
97
+ expect ( chart . filter ( ) ) . toEqual ( "Colorado" ) ;
98
+ expect ( chart . filters ( ) . length ) . toEqual ( 1 ) ;
99
+ } ) ;
100
+ it ( 'actually filters dimension' , function ( ) {
101
+ chart . onChange ( stateGroup . all ( ) [ 0 ] . key ) ;
102
+ expect ( regionGroup . all ( ) [ 0 ] . value ) . toEqual ( 0 ) ;
103
+ expect ( regionGroup . all ( ) [ 3 ] . value ) . toEqual ( 2 ) ;
104
+ } ) ;
105
+ it ( 'removes filter when prompt option is selected' , function ( ) {
106
+ chart . onChange ( null ) ;
107
+ expect ( chart . hasFilter ( ) ) . not . toBeTruthy ( ) ;
108
+ expect ( regionGroup . all ( ) [ 0 ] . value ) . toEqual ( 1 ) ;
109
+ } ) ;
110
+ } ) ;
111
+
112
+ describe ( 'redraw with existing filter' , function ( ) {
113
+ it ( 'selects option corresponding to active filter' , function ( ) {
114
+ chart . onChange ( stateGroup . all ( ) [ 0 ] . key ) ;
115
+ chart . redraw ( ) ;
116
+ expect ( chart . selectAll ( "select" ) [ 0 ] [ 0 ] . value ) . toEqual ( "California" ) ;
117
+ } ) ;
118
+ } ) ;
119
+
120
+ afterEach ( function ( ) {
121
+ chart . onChange ( null ) ;
122
+ } ) ;
123
+ } ) ;
80
124
81
- describe ( 'selecting an option ' , function ( ) {
82
- it ( 'filters dimension based on selected option\'s value' , function ( ) {
83
- chart . onChange ( stateGroup . all ( ) [ 0 ] . key ) ;
84
- expect ( chart . filter ( ) ) . toEqual ( "California" ) ;
125
+ describe ( 'multiple select ' , function ( ) {
126
+ beforeEach ( function ( ) {
127
+ chart . multiple ( true ) ;
128
+ chart . onChange ( [ stateGroup . all ( ) [ 0 ] . key , stateGroup . all ( ) [ 1 ] . key ] ) ;
85
129
} ) ;
86
- it ( 'replaces filter on second selection' , function ( ) {
87
- chart . onChange ( stateGroup . all ( ) [ 0 ] . key ) ;
88
- chart . onChange ( stateGroup . all ( ) [ 1 ] . key ) ;
89
- expect ( chart . filter ( ) ) . toEqual ( "Colorado" ) ;
90
- expect ( chart . filters ( ) . length ) . toEqual ( 1 ) ;
130
+ it ( 'adds filters based on selections' , function ( ) {
131
+ expect ( chart . filters ( ) ) . toEqual ( [ "California" , "Colorado" ] ) ;
132
+ expect ( chart . filters ( ) . length ) . toEqual ( 2 ) ;
91
133
} ) ;
92
134
it ( 'actually filters dimension' , function ( ) {
93
- chart . onChange ( stateGroup . all ( ) [ 0 ] . key ) ;
94
- expect ( regionGroup . all ( ) [ 0 ] . value ) . toEqual ( 0 ) ;
95
135
expect ( regionGroup . all ( ) [ 3 ] . value ) . toEqual ( 2 ) ;
136
+ expect ( regionGroup . all ( ) [ 4 ] . value ) . toEqual ( 2 ) ;
96
137
} ) ;
97
- it ( 'removes filter when prompt option is selected' , function ( ) {
98
- chart . onChange ( '' ) ;
138
+ it ( 'removes all filters when prompt option is selected' , function ( ) {
139
+ chart . onChange ( null ) ;
99
140
expect ( chart . hasFilter ( ) ) . not . toBeTruthy ( ) ;
100
141
expect ( regionGroup . all ( ) [ 0 ] . value ) . toEqual ( 1 ) ;
101
142
} ) ;
102
- } ) ;
143
+ it ( 'selects all options corresponding to active filters on redraw' , function ( ) {
144
+ var selectedOptions = chart . selectAll ( "select" ) . selectAll ( "option" ) [ 0 ] . filter ( function ( d ) {
145
+ return d . selected ;
146
+ } ) ;
147
+ expect ( selectedOptions . length ) . toEqual ( 2 ) ;
148
+ expect ( selectedOptions . map ( function ( d ) { return d . value ; } ) ) . toEqual ( [ "California" , "Colorado" ] ) ;
149
+ } ) ;
150
+ it ( 'does not deselect previously filtered options when new option is added' , function ( ) {
151
+ chart . onChange ( [ stateGroup . all ( ) [ 0 ] . key , stateGroup . all ( ) [ 1 ] . key , stateGroup . all ( ) [ 5 ] . key ] ) ;
103
152
104
- describe ( 'redraw with existing filter' , function ( ) {
105
- it ( 'selects option corresponding to active filter' , function ( ) {
106
- chart . onChange ( stateGroup . all ( ) [ 0 ] . key ) ;
107
- chart . redraw ( ) ;
108
- expect ( chart . selectAll ( "select" ) [ 0 ] [ 0 ] . value ) . toEqual ( "California" ) ;
153
+ var selectedOptions = chart . selectAll ( "select" ) . selectAll ( "option" ) [ 0 ] . filter ( function ( d ) {
154
+ return d . selected ;
155
+ } ) ;
156
+ expect ( selectedOptions . length ) . toEqual ( 3 ) ;
157
+ expect ( selectedOptions . map ( function ( d ) { return d . value ; } ) ) . toEqual ( [ "California" , "Colorado" , "Ontario" ] ) ;
158
+ } ) ;
159
+
160
+ afterEach ( function ( ) {
161
+ chart . onChange ( null ) ;
109
162
} ) ;
110
163
} ) ;
111
164
@@ -136,7 +189,4 @@ describe('dc.selectMenu', function() {
136
189
function getOption ( chart , i ) {
137
190
return chart . selectAll ( "option.dc-select-option" ) [ 0 ] [ i ] ;
138
191
}
139
-
140
-
141
- } ) ;
142
-
192
+ } ) ;
0 commit comments