|
17 | 17 | empty = double(:items => []) |
18 | 18 |
|
19 | 19 | fields = [a,b,empty] |
20 | | - expect(helper.has_facet_values?(fields)).to be_true |
| 20 | + expect(helper.has_facet_values?(fields)).to be true |
21 | 21 | end |
22 | 22 |
|
23 | 23 | it "should be false if all facets are empty" do |
24 | 24 |
|
25 | 25 | empty = double(:items => []) |
26 | 26 |
|
27 | 27 | fields = [empty] |
28 | | - expect(helper.has_facet_values?(fields)).to be_false |
| 28 | + expect(helper.has_facet_values?(fields)).to be false |
29 | 29 | end |
30 | 30 | end |
31 | 31 |
|
|
45 | 45 |
|
46 | 46 | it "should render facets with items" do |
47 | 47 | a = double(:items => [1,2], :name=>'basic_field') |
48 | | - expect(helper.should_render_facet?(a)).to be_true |
| 48 | + expect(helper.should_render_facet?(a)).to be true |
49 | 49 | end |
50 | 50 | it "should not render facets without items" do |
51 | 51 | empty = double(:items => [], :name=>'basic_field') |
52 | | - expect(helper.should_render_facet?(empty)).to be_false |
| 52 | + expect(helper.should_render_facet?(empty)).to be false |
53 | 53 | end |
54 | 54 |
|
55 | 55 | it "should not render facets where show is set to false" do |
56 | 56 | a = double(:items => [1,2], :name=>'no_show') |
57 | | - expect(helper.should_render_facet?(a)).to be_false |
| 57 | + expect(helper.should_render_facet?(a)).to be false |
58 | 58 | end |
59 | 59 |
|
60 | 60 | it "should call a helper to determine if it should render a field" do |
61 | 61 | helper.stub(:my_helper => true) |
62 | 62 | a = double(:items => [1,2], :name=>'helper_show') |
63 | | - expect(helper.should_render_facet?(a)).to be_true |
| 63 | + expect(helper.should_render_facet?(a)).to be true |
64 | 64 | end |
65 | 65 |
|
66 | 66 | it "should call a helper to determine if it should render a field" do |
67 | 67 | a = double(:items => [1,2], :name=>'helper_with_an_arg_show') |
68 | 68 | helper.should_receive(:my_helper_with_an_arg).with(@config.facet_fields['helper_with_an_arg_show'], a).and_return(true) |
69 | | - expect(helper.should_render_facet?(a)).to be_true |
| 69 | + expect(helper.should_render_facet?(a)).to be true |
70 | 70 | end |
71 | 71 |
|
72 | 72 |
|
73 | 73 | it "should evaluate a Proc to determine if it should render a field" do |
74 | 74 | a = double(:items => [1,2], :name=>'lambda_show') |
75 | | - expect(helper.should_render_facet?(a)).to be_true |
| 75 | + expect(helper.should_render_facet?(a)).to be true |
76 | 76 |
|
77 | 77 | a = double(:items => [1,2], :name=>'lambda_no_show') |
78 | | - expect(helper.should_render_facet?(a)).to be_false |
| 78 | + expect(helper.should_render_facet?(a)).to be false |
79 | 79 | end |
80 | 80 | end |
81 | 81 |
|
|
90 | 90 | end |
91 | 91 |
|
92 | 92 | it "should be collapsed by default" do |
93 | | - expect(helper.should_collapse_facet?(@config.facet_fields['basic_field'])).to be_true |
| 93 | + expect(helper.should_collapse_facet?(@config.facet_fields['basic_field'])).to be true |
94 | 94 | end |
95 | 95 |
|
96 | 96 | it "should not be collapsed if the configuration says so" do |
97 | | - expect(helper.should_collapse_facet?(@config.facet_fields['no_collapse'])).to be_false |
| 97 | + expect(helper.should_collapse_facet?(@config.facet_fields['no_collapse'])).to be false |
98 | 98 | end |
99 | 99 |
|
100 | 100 | it "should not be collapsed if it is in the params" do |
101 | 101 | params[:f] = { basic_field: [1], no_collapse: [2] }.with_indifferent_access |
102 | | - expect(helper.should_collapse_facet?(@config.facet_fields['basic_field'])).to be_false |
103 | | - expect(helper.should_collapse_facet?(@config.facet_fields['no_collapse'])).to be_false |
| 102 | + expect(helper.should_collapse_facet?(@config.facet_fields['basic_field'])).to be false |
| 103 | + expect(helper.should_collapse_facet?(@config.facet_fields['no_collapse'])).to be false |
104 | 104 | end |
105 | 105 |
|
106 | 106 | end |
|
152 | 152 | field.should be_a_kind_of Blacklight::SolrResponse::Facets::FacetField |
153 | 153 |
|
154 | 154 | expect(field.name).to eq'my_query_facet_field' |
155 | | - expect(field.items).to have(2).items |
| 155 | + expect(field.items.size).to eq 2 |
156 | 156 | expect(field.items.map { |x| x.value }).to_not include 'field:not_appearing_in_the_config' |
157 | 157 |
|
158 | 158 | facet_item = field.items.select { |x| x.value == 'a_simple_query' }.first |
|
180 | 180 |
|
181 | 181 | expect(field.name).to eq 'my_pivot_facet_field' |
182 | 182 |
|
183 | | - expect(field.items).to have(1).item |
| 183 | + expect(field.items.size).to eq 1 |
184 | 184 |
|
185 | 185 | expect(field.items.first).to respond_to(:items) |
186 | 186 |
|
187 | | - expect(field.items.first.items).to have(1).item |
| 187 | + expect(field.items.first.items.size).to eq 1 |
188 | 188 | expect(field.items.first.items.first.fq).to eq({ 'field_a' => 'a' }) |
189 | 189 | end |
190 | 190 | end |
|
281 | 281 | end |
282 | 282 | end |
283 | 283 |
|
| 284 | + describe "render_facet_limit_list" do |
| 285 | + let(:f1) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '792', value: 'Book') } |
| 286 | + let(:f2) { Blacklight::SolrResponse::Facets::FacetItem.new(hits: '65', value: 'Musical Score') } |
| 287 | + let(:paginator) { Blacklight::Solr::FacetPaginator.new([f1, f2], limit: 10) } |
| 288 | + subject { helper.render_facet_limit_list(paginator, 'type_solr_field') } |
| 289 | + before do |
| 290 | + allow(helper).to receive(:search_action_path) do |*args| |
| 291 | + catalog_index_path *args |
| 292 | + end |
| 293 | + end |
| 294 | + it "should draw a list of elements" do |
| 295 | + expect(subject).to have_selector 'li', count: 2 |
| 296 | + expect(subject).to have_selector 'li:first-child a.facet_select', text: 'Book' |
| 297 | + expect(subject).to have_selector 'li:nth-child(2) a.facet_select', text: 'Musical Score' |
| 298 | + end |
| 299 | + |
| 300 | + context "when one of the facet items is rendered as nil" do |
| 301 | + # An app may override render_facet_item to filter out some undesired facet items by returning nil. |
| 302 | + |
| 303 | + before { allow(helper).to receive(:render_facet_item).and_return("<a class=\"facet_select\">Book</a>".html_safe, nil) } |
| 304 | + |
| 305 | + it "should draw a list of elements" do |
| 306 | + expect(subject).to have_selector 'li', count: 1 |
| 307 | + expect(subject).to have_selector 'li:first-child a.facet_select', text: 'Book' |
| 308 | + end |
| 309 | + |
| 310 | + end |
| 311 | + end |
| 312 | + |
284 | 313 | describe "facet_field_in_params?" do |
285 | 314 | it "should check if the facet field is selected in the user params" do |
286 | 315 | helper.stub(:params => { :f => { "some-field" => ["x"]}}) |
287 | | - expect(helper.facet_field_in_params?("some-field")).to be_true |
288 | | - expect(helper.facet_field_in_params?("other-field")).to_not be_true |
| 316 | + expect(helper.facet_field_in_params?("some-field")).to be_truthy |
| 317 | + expect(helper.facet_field_in_params?("other-field")).to_not be true |
289 | 318 | end |
290 | 319 | end |
291 | 320 |
|
|
300 | 329 | helper.should_receive(:facet_display_value).and_return('Z') |
301 | 330 | helper.should_receive(:add_facet_params_and_redirect).and_return({controller:'catalog'}) |
302 | 331 |
|
303 | | - helper.stub(:search_action_path) do |*args| |
| 332 | + allow(helper).to receive(:search_action_path) do |*args| |
304 | 333 | catalog_index_path *args |
305 | 334 | end |
306 | 335 | end |
|
0 commit comments