|
37 | 37 | end
|
38 | 38 |
|
39 | 39 | context 'outside of an HTML context' do
|
40 |
| - let(:options) { { format: 'text' } } |
| 40 | + context 'when options determines format' do |
| 41 | + let(:options) { { format: 'text' } } |
41 | 42 |
|
42 |
| - let(:values) { ['"blah"', "<notatag>"] } |
43 |
| - let(:field_config) { Blacklight::Configuration::NullField.new itemprop: 'some-prop' } |
| 43 | + let(:values) { ['"blah"', "<notatag>"] } |
| 44 | + let(:field_config) { Blacklight::Configuration::NullField.new itemprop: 'some-prop' } |
44 | 45 |
|
45 |
| - it 'does not HTML escape values or inject HTML tags' do |
46 |
| - expect(rendered).to eq '"blah" and <notatag>' |
| 46 | + it 'does not HTML escape values or inject HTML tags' do |
| 47 | + expect(rendered).to eq '"blah" and <notatag>' |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + context 'when context determines format' do |
| 52 | + let(:values) { ['"blah"', "<notatag>"] } |
| 53 | + let(:field_config) { Blacklight::Configuration::NullField.new itemprop: 'some-prop' } |
| 54 | + let(:controller) { CatalogController.new } |
| 55 | + let(:search_state) { Blacklight::SearchState.new({ format: 'text' }, controller.blacklight_config, controller) } |
| 56 | + |
| 57 | + before { allow(context).to receive(:search_state).and_return(search_state) } |
| 58 | + |
| 59 | + it 'does not HTML escape values or inject HTML tags' do |
| 60 | + expect(rendered).to eq '"blah" and <notatag>' |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + context 'when link_to_facet is in the config' do |
| 66 | + let(:values) { %w[book manuscript] } |
| 67 | + let(:field_config) { Blacklight::Configuration::Field.new(field: 'format', key: 'format', link_to_facet: true) } |
| 68 | + let(:controller) { CatalogController.new } |
| 69 | + let(:search_state) { Blacklight::SearchState.new({}, controller.blacklight_config, controller) } |
| 70 | + |
| 71 | + before do |
| 72 | + allow(context).to receive(:search_state).and_return(search_state) |
| 73 | + allow(context).to receive(:search_action_path) { |f| "/catalog?f[format][]=#{f['f']['format'].first}" } |
| 74 | + allow(context).to receive(:link_to) { |value, link| ActiveSupport::SafeBuffer.new("<a href=#{link}>#{value}</a>") } |
| 75 | + end |
| 76 | + |
| 77 | + it 'renders html' do |
| 78 | + expect(rendered).to eq "<a href=/catalog?f[format][]=book>book</a> and <a href=/catalog?f[format][]=manuscript>manuscript</a>" |
| 79 | + end |
| 80 | + |
| 81 | + context 'outside html context' do |
| 82 | + let(:values) { %w[book manuscript] } |
| 83 | + let(:field_config) { Blacklight::Configuration::Field.new(field: 'format', link_to_facet: true) } |
| 84 | + let(:search_state) { Blacklight::SearchState.new({ format: 'json' }, CatalogController.blacklight_config, CatalogController.new) } |
| 85 | + |
| 86 | + it 'does not render html' do |
| 87 | + expect(rendered).to eq "book and manuscript" |
| 88 | + end |
47 | 89 | end
|
48 | 90 | end
|
49 | 91 | end
|
|
0 commit comments