@@ -71,25 +71,66 @@ class FilterHelperTest < ActionView::TestCase
7171 original_query = {
7272 page : 1 ,
7373 q : 'data' ,
74- contentType : 'dataset'
74+ contentType : [ 'dataset' ]
7575 }
7676 expected_query = {
7777 page : 1 ,
7878 q : 'data'
7979 }
80- assert_equal expected_query , remove_filter ( original_query , ' contentType')
80+ assert_equal expected_query , remove_filter ( original_query , : contentType, 'dataset ')
8181 end
8282
8383 test 'remove_filter will reset a page count when called' do
8484 original_query = {
8585 page : 3 ,
8686 q : 'data' ,
87- contentType : 'dataset'
87+ contentType : [ 'dataset' ]
8888 }
8989 expected_query = {
9090 page : 1 ,
9191 q : 'data'
9292 }
93- assert_equal expected_query , remove_filter ( original_query , 'contentType' )
93+ assert_equal expected_query , remove_filter ( original_query , :contentType , 'dataset' )
94+ end
95+
96+ test 'remove_filter removes only one filter parameter if multiple are applied' do
97+ original_query = {
98+ page : 3 ,
99+ q : 'data' ,
100+ contentType : [ 'dataset' , 'microfiche' , 'vinyl record' ]
101+ }
102+ expected_query = {
103+ page : 1 ,
104+ q : 'data' ,
105+ contentType : [ 'dataset' , 'vinyl record' ]
106+ }
107+ assert_equal expected_query , remove_filter ( original_query , :contentType , 'microfiche' )
108+ end
109+
110+ test 'filter_applied? returns true if a filter is applied' do
111+ query = {
112+ page : 3 ,
113+ q : 'data' ,
114+ contentType : [ 'dataset' ]
115+ }
116+ assert filter_applied? ( query [ :contentType ] , 'dataset' )
117+ end
118+
119+ test 'filter_applied? returns false if the filter does not include the target term' do
120+ query = {
121+ page : 3 ,
122+ q : 'data' ,
123+ contentType : [ 'dataset' ]
124+ }
125+ assert_not filter_applied? ( query [ :contentType ] , 'microfiche' )
126+ end
127+
128+ # This is an unlikely state to reach, but better safe than sorry
129+ test 'filter_applied? returns false if no filter is supplied in the query' do
130+ query = {
131+ page : 3 ,
132+ q : 'data' ,
133+ }
134+ assert_not filter_applied? ( query [ :contentType ] , 'dataset' )
94135 end
95136end
0 commit comments