blacklight 7.5.1 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +23 -34
  3. data/.travis.yml +3 -3
  4. data/VERSION +1 -1
  5. data/app/helpers/blacklight/blacklight_helper_behavior.rb +4 -2
  6. data/app/helpers/blacklight/catalog_helper_behavior.rb +0 -2
  7. data/app/presenters/blacklight/document_presenter.rb +27 -36
  8. data/app/presenters/blacklight/field_presenter.rb +31 -6
  9. data/app/presenters/blacklight/index_presenter.rb +2 -2
  10. data/app/presenters/blacklight/show_presenter.rb +3 -3
  11. data/app/views/catalog/_constraints.html.erb +1 -1
  12. data/app/views/catalog/_facet_pagination.html.erb +2 -2
  13. data/app/views/catalog/_field.json.jbuilder +2 -2
  14. data/app/views/catalog/_index.html.erb +3 -3
  15. data/app/views/catalog/_search_form.html.erb +1 -1
  16. data/app/views/catalog/_show.html.erb +3 -3
  17. data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
  18. data/app/views/catalog/_start_over.html.erb +1 -0
  19. data/app/views/catalog/_thumbnail.html.erb +1 -1
  20. data/app/views/catalog/index.json.jbuilder +2 -1
  21. data/app/views/catalog/show.html.erb +1 -1
  22. data/app/views/catalog/show.json.jbuilder +2 -1
  23. data/app/views/layouts/blacklight/base.html.erb +2 -2
  24. data/config/locales/blacklight.ar.yml +2 -0
  25. data/config/locales/blacklight.de.yml +2 -0
  26. data/config/locales/blacklight.en.yml +2 -0
  27. data/config/locales/blacklight.es.yml +2 -0
  28. data/config/locales/blacklight.fr.yml +2 -0
  29. data/config/locales/blacklight.hu.yml +2 -0
  30. data/config/locales/blacklight.it.yml +2 -0
  31. data/config/locales/blacklight.nl.yml +2 -0
  32. data/config/locales/blacklight.pt-BR.yml +2 -0
  33. data/config/locales/blacklight.sq.yml +2 -0
  34. data/config/locales/blacklight.zh.yml +2 -0
  35. data/lib/blacklight/configuration/field.rb +5 -4
  36. data/spec/helpers/blacklight_helper_spec.rb +17 -0
  37. data/spec/helpers/catalog_helper_spec.rb +0 -7
  38. data/spec/presenters/blacklight/document_presenter_spec.rb +22 -62
  39. data/spec/presenters/blacklight/field_presenter_spec.rb +268 -0
  40. data/spec/presenters/blacklight/index_presenter_spec.rb +0 -142
  41. data/spec/presenters/blacklight/show_presenter_spec.rb +0 -177
  42. metadata +6 -3
@@ -20,12 +20,12 @@ module Blacklight
20
20
  # @see #document_heading
21
21
  # @return [String]
22
22
  def html_title
23
- return field_values(view_config.html_title_field) if view_config.html_title_field.is_a? Blacklight::Configuration::Field
23
+ return field_value(view_config.html_title_field) if view_config.html_title_field.is_a? Blacklight::Configuration::Field
24
24
 
25
25
  if view_config.html_title_field
26
26
  fields = Array.wrap(view_config.html_title_field) + [configuration.document_model.unique_key]
27
- f = fields.lazy.map { |field| field_config(field) }.detect { |field_config| retrieve_values(field_config).any? }
28
- field_values(f)
27
+ f = fields.lazy.map { |field| field_config(field) }.detect { |field_config| field_presenter(field_config).any? }
28
+ field_value(f)
29
29
  else
30
30
  heading
31
31
  end
@@ -2,7 +2,7 @@
2
2
  <div id="appliedParams" class="clearfix constraints-container">
3
3
  <h2 class="sr-only"><%= t('blacklight.search.search_constraints_header') %></h2>
4
4
 
5
- <%=link_to t('blacklight.search.start_over'), start_over_path, class: "catalog_startOverLink btn btn-primary" %>
5
+ <%= render 'start_over' %>
6
6
  <span class="constraints-label sr-only"><%= t('blacklight.search.filters.title') %></span>
7
7
  <%= render_constraints(params) %>
8
8
  </div>
@@ -1,10 +1,10 @@
1
1
  <div class="prev_next_links btn-group">
2
2
  <%= link_to_previous_page @pagination, raw(t('views.pagination.previous')), params: search_state.to_h, param_name: blacklight_config.facet_paginator_class.request_keys[:page], class: 'btn btn-link', data: { blacklight_modal: "preserve" } do %>
3
- <span class="disabled btn btn-disabled"><%= raw(t('views.pagination.previous')) %></span>
3
+ <%= content_tag :span, raw(t('views.pagination.previous')), class: 'disabled btn btn-disabled' %>
4
4
  <% end %>
5
5
 
6
6
  <%= link_to_next_page @pagination, raw(t('views.pagination.next')), params: search_state.to_h, param_name: blacklight_config.facet_paginator_class.request_keys[:page], class: 'btn btn-link', data: { blacklight_modal: "preserve" } do %>
7
- <span class="disabled btn btn-disabled"><%= raw(t('views.pagination.next')) %></span>
7
+ <%= content_tag :span, raw(t('views.pagination.next')), class: 'disabled btn btn-disabled' %>
8
8
  <% end %>
9
9
  </div>
10
10
 
@@ -4,7 +4,7 @@ json.set!(field_name) do
4
4
  json.id "#{document_url}##{field_name}"
5
5
  json.type 'document_value'
6
6
  json.attributes do
7
- json.value doc_presenter.field_value(field)
8
- json.label field.display_label(view_type)
7
+ json.value field_presenter.render
8
+ json.label field_presenter.label(view_type)
9
9
  end
10
10
  end
@@ -2,9 +2,9 @@
2
2
  <%# default partial to display solr document fields in catalog index view -%>
3
3
  <dl class="document-metadata dl-invert row">
4
4
 
5
- <% doc_presenter.fields_to_render.each do |field_name, field| -%>
6
- <dt class="blacklight-<%= field_name.parameterize %> col-md-3"><%= render_index_field_label document, field: field_name %></dt>
7
- <dd class="blacklight-<%= field_name.parameterize %> col-md-9"><%= doc_presenter.field_value field %></dd>
5
+ <% doc_presenter.fields_to_render.each do |field_name, field, field_presenter| -%>
6
+ <dt class="blacklight-<%= field_name.parameterize %> col-md-3"><%= render_index_field_label document, label: field_presenter.label, field: field_name %></dt>
7
+ <dd class="blacklight-<%= field_name.parameterize %> col-md-9"><%= field_presenter.render %></dd>
8
8
  <% end -%>
9
9
 
10
10
  </dl>
@@ -1,4 +1,4 @@
1
- <%= form_tag search_action_url, method: :get, class: 'search-query-form', role: 'search' do %>
1
+ <%= form_tag search_action_url, method: :get, class: 'search-query-form', role: 'search', 'aria-label' => t('blacklight.search.form.submit') do %>
2
2
  <%= render_hash_as_hidden_fields(search_state.params_for_search.except(:q, :search_field, :qt, :page, :utf8)) %>
3
3
  <% if search_fields.length > 1 %>
4
4
  <label for="search_field" class="sr-only"><%= t('blacklight.search.form.search_field.label') %></label>
@@ -1,8 +1,8 @@
1
1
  <% doc_presenter = show_presenter(document) %>
2
2
  <%# default partial to display solr document fields in catalog show view -%>
3
3
  <dl class="row dl-invert document-metadata">
4
- <% doc_presenter.fields_to_render.each do |field_name, field| -%>
5
- <dt class="blacklight-<%= field_name.parameterize %> col-md-3"><%= render_document_show_field_label document, field: field_name %></dt>
6
- <dd class="blacklight-<%= field_name.parameterize %> col-md-9"><%= doc_presenter.field_value field %></dd>
4
+ <% doc_presenter.fields_to_render.each do |field_name, field, field_presenter| -%>
5
+ <dt class="blacklight-<%= field_name.parameterize %> col-md-3"><%= render_document_show_field_label document, label: field_presenter.label, field: field_name %></dt>
6
+ <dd class="blacklight-<%= field_name.parameterize %> col-md-9"><%= field_presenter.render %></dd>
7
7
  <% end -%>
8
8
  </dl>
@@ -1,4 +1,4 @@
1
- <div id="sortAndPerPage" class="sort-pagination d-md-flex justify-content-between">
1
+ <div id="sortAndPerPage" class="sort-pagination d-md-flex justify-content-between" role="navigation" aria-label="<%= t('blacklight.search.per_page.aria_label')%>">
2
2
  <%= render partial: "paginate_compact", object: @response if show_pagination? %>
3
3
  <%= render_results_collection_tools wrapping_class: "search-widgets" %>
4
4
  </div>
@@ -0,0 +1 @@
1
+ <%= link_to t('blacklight.search.start_over'), start_over_path, class: "catalog_startOverLink btn btn-primary" %>
@@ -1,4 +1,4 @@
1
- <% if presenter(document).thumbnail.exists? && tn = presenter(document).thumbnail.thumbnail_tag({}, counter: document_counter_with_offset(document_counter)) %>
1
+ <% if presenter(document).thumbnail.exists? && tn = presenter(document).thumbnail.thumbnail_tag({ alt: '' }, 'aria-hidden': true, tabindex: -1, counter: document_counter_with_offset(document_counter)) %>
2
2
  <div class="document-thumbnail">
3
3
  <%= tn %>
4
4
  </div>
@@ -17,11 +17,12 @@ json.data do
17
17
  json.id document.id
18
18
  json.type doc_presenter.display_type.first
19
19
  json.attributes do
20
- doc_presenter.fields_to_render.each do |field_name, field|
20
+ doc_presenter.fields_to_render.each do |field_name, field, field_presenter|
21
21
  json.partial! 'field', field: field,
22
22
  field_name: field_name,
23
23
  document_url: document_url,
24
24
  doc_presenter: doc_presenter,
25
+ field_presenter: field_presenter,
25
26
  view_type: 'index'
26
27
  end
27
28
  end
@@ -1,6 +1,6 @@
1
1
  <% if current_search_session %>
2
2
  <div id="appliedParams" class="clearfix constraints-container">
3
- <%= link_to t('blacklight.search.start_over'), start_over_path, class: "catalog_startOverLink btn btn-primary" %>
3
+ <%= render 'start_over' %>
4
4
  <%= link_back_to_catalog class: 'btn btn-outline-secondary' %>
5
5
  </div>
6
6
  <% end %>
@@ -11,11 +11,12 @@ json.data do
11
11
  json.id @document.id
12
12
  json.type doc_presenter.display_type.first
13
13
  json.attributes do
14
- doc_presenter.fields_to_render.each do |field_name, field|
14
+ doc_presenter.fields_to_render.each do |field_name, field, field_presenter|
15
15
  json.partial! 'field', field: field,
16
16
  field_name: field_name,
17
17
  document_url: document_url,
18
18
  doc_presenter: doc_presenter,
19
+ field_presenter: field_presenter,
19
20
  view_type: 'show'
20
21
  end
21
22
  end
@@ -17,11 +17,11 @@
17
17
  <%= content_for(:head) %>
18
18
  </head>
19
19
  <body class="<%= render_body_class %>">
20
- <div id="skip-link">
20
+ <nav id="skip-link" role="navigation" aria-label="<%= t('blacklight.skip_links') %>">
21
21
  <%= link_to t('blacklight.skip_links.search_field'), '#search_field', class: 'element-invisible element-focusable rounded-bottom py-2 px-3', data: { turbolinks: 'false' } %>
22
22
  <%= link_to t('blacklight.skip_links.main_content'), '#main-container', class: 'element-invisible element-focusable rounded-bottom py-2 px-3', data: { turbolinks: 'false' } %>
23
23
  <%= content_for(:skip_links) %>
24
- </div>
24
+ </nav>
25
25
  <%= render partial: 'shared/header_navbar' %>
26
26
 
27
27
  <main id="main-container" class="<%= container_classes %>" role="main" aria-label="<%= t('blacklight.main.aria.main_container') %>">
@@ -22,6 +22,7 @@ ar:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: 'تخطي الروابط'
25
26
  main_content: 'انتقل إلى المحتوى الرئيسي'
26
27
  search_field: 'انتقل إلى البحث'
27
28
  first_result: 'انتقل إلى النتيجة الأولى'
@@ -159,6 +160,7 @@ ar:
159
160
  button_label_html: '%{count}<span class="d-none d-sm-inline"> لكل صفحة</span>'
160
161
  title: 'عدد النتائج المعروضة في الصفحة'
161
162
  submit: 'تحديث'
163
+ aria_label: 'الملاحة النتائج'
162
164
  sort:
163
165
  label: 'ترتيب حسب %{field}' # TODO: Remove during major release
164
166
  label_html: 'ترتيب <span class="d-none d-sm-inline"> حسب %{field}</span>'
@@ -22,6 +22,7 @@ de:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: 'Links überspringen'
25
26
  main_content: 'Zum Hauptinhalt gehen'
26
27
  search_field: 'Gehen Sie zur Suchleiste'
27
28
  first_result: 'Gehe zum ersten Suchergebnis'
@@ -151,6 +152,7 @@ de:
151
152
  button_label_html: '%{count}<span class="d-none d-sm-inline"> pro Seite</span>'
152
153
  title: 'Anzahl der Ergebnisse, die pro Seite angezeigt werden'
153
154
  submit: 'Aktualisieren'
155
+ aria_label: 'Ergebnisnavigation'
154
156
  sort:
155
157
  label: 'Ordnen nach %{field}' # TODO: Remove during major release
156
158
  label_html: 'Ordnen<span class="d-none d-sm-inline"> nach %{field}</span>'
@@ -22,6 +22,7 @@ en:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: 'Skip links'
25
26
  main_content: 'Skip to main content'
26
27
  search_field: 'Skip to search'
27
28
  first_result: 'Skip to first result'
@@ -151,6 +152,7 @@ en:
151
152
  button_label_html: '%{count}<span class="d-none d-sm-inline"> per page</span>'
152
153
  title: 'Number of results to display per page'
153
154
  submit: 'Update'
155
+ aria_label: 'Results navigation'
154
156
  sort:
155
157
  label: 'Sort by %{field}' # TODO: Remove during major release
156
158
  label_html: 'Sort<span class="d-none d-sm-inline"> by %{field}</span>'
@@ -22,6 +22,7 @@ es:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: 'Saltar enlaces'
25
26
  main_content: 'Saltar al contenido principal'
26
27
  search_field: 'Salta a la búsqueda'
27
28
  first_result: 'Salta al primer resultado de búsqueda'
@@ -151,6 +152,7 @@ es:
151
152
  button_label_html: '%{count}<span class="d-none d-sm-inline"> por página</span>'
152
153
  title: 'El número de resultados a mostrar por página'
153
154
  submit: 'Actualización'
155
+ aria_label: 'Navegación de resultados'
154
156
  sort:
155
157
  label: 'Ordenar por %{field}' # TODO: Remove during major release
156
158
  label_html: 'Ordenar<span class="d-none d-sm-inline"> por %{field}</span>'
@@ -22,6 +22,7 @@ fr:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: 'Sauter les liens'
25
26
  main_content: 'Aller au contenu principal'
26
27
  search_field: 'Aller à la recherche'
27
28
  first_result: 'Aller au premier résultat de recherche'
@@ -154,6 +155,7 @@ fr:
154
155
  button_label_html: '%{count}<span class="d-none d-sm-inline"> par page</span>'
155
156
  title: 'Nombre de résultats à afficher par page'
156
157
  submit: 'mettre à jour'
158
+ aria_label: 'Navigation dans les résultats'
157
159
  sort:
158
160
  label: 'Trier par %{field}' # TODO: Remove during major release
159
161
  label_html: 'Trier<span class="d-none d-sm-inline"> par %{field}</span>'
@@ -22,6 +22,7 @@ hu:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: 'átugrani a linkeket'
25
26
  main_content: 'Ugrás a tartalomra'
26
27
  search_field: 'Ugrás a keresésre'
27
28
  first_result: 'Ugrás az első keresési eredményre'
@@ -151,6 +152,7 @@ hu:
151
152
  button_label_html: '%{count}<span class="d-none d-sm-inline"> oldalanként</span>'
152
153
  title: 'Az eredmények száma oldalanként'
153
154
  submit: 'Frissítés'
155
+ aria_label: 'Eredmények navigáció'
154
156
  sort:
155
157
  label: 'Rendezés %{field}' # TODO: Remove during major release
156
158
  label_html: 'Rendezés<span class="d-none d-sm-inline"> %{field}</span>'
@@ -22,6 +22,7 @@ it:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: 'Saltare i collegamenti'
25
26
  main_content: 'Vai al contenuto principale'
26
27
  search_field: 'Vai alla ricerca'
27
28
  first_result: 'Vai al primo risultato di ricerca'
@@ -151,6 +152,7 @@ it:
151
152
  button_label_html: '%{count}<span class="d-none d-sm-inline"> per pagina</span>'
152
153
  title: 'Risultati per pagina'
153
154
  submit: 'Aggiorna'
155
+ aria_label: 'Navigazione dei risultati'
154
156
  sort:
155
157
  label: 'Ordina per %{field}' # TODO: Remove during major release
156
158
  label_html: 'Ordina<span class="d-none d-sm-inline"> per %{field}</span>'
@@ -22,6 +22,7 @@ nl:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: 'links overslaan'
25
26
  main_content: 'Ga naar de hoofdinhoud'
26
27
  search_field: 'Ga naar de zoekopdracht'
27
28
  first_result: 'Ga naar het eerste zoekresultaat'
@@ -151,6 +152,7 @@ nl:
151
152
  button_label_html: '%{count}<span class="d-none d-sm-inline"> per pagina</span>'
152
153
  title: 'Toon aantal zoekresultaten per pagina'
153
154
  submit: 'Update'
155
+ aria_label: 'Resultaten navigatie'
154
156
  sort:
155
157
  label: 'Sorteer op %{field}' # TODO: Remove during major release
156
158
  label_html: 'Sorteer<span class="d-none d-sm-inline"> op %{field}</span>'
@@ -23,6 +23,7 @@ pt-BR:
23
23
  blacklight:
24
24
  application_name: 'Blacklight'
25
25
  skip_links:
26
+ label: 'pular links'
26
27
  main_content: 'Ir para o conteúdo principal'
27
28
  search_field: 'Ir para a pesquisa'
28
29
  first_result: 'Ir para o primeiro resultado da pesquisa'
@@ -152,6 +153,7 @@ pt-BR:
152
153
  button_label_html: '%{count}<span class="d-none d-sm-inline"> por página</span>'
153
154
  title: 'Número de resultados para mostrar por página'
154
155
  submit: 'Atualizar'
156
+ aria_label: 'Navegação de resultados'
155
157
  sort:
156
158
  label: 'Ordenar por %{field}' # TODO: Remove during major release
157
159
  label_html: 'Ordenar<span class="d-none d-sm-inline"> por %{field}</span>'
@@ -22,6 +22,7 @@ sq:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: 'lidhjet e kaloni'
25
26
  main_content: 'Shkoni tek përmbajtja kryesore'
26
27
  search_field: 'Shkoni në kërkim'
27
28
  first_result: 'Shkoni te rezultati i parë i kërkimit'
@@ -151,6 +152,7 @@ sq:
151
152
  button_label_html: '%{count}<span class="d-none d-sm-inline"> për faqe</span>'
152
153
  title: 'Numri i rezultateve që do të shfaqen për faqe'
153
154
  submit: 'Përditëso'
155
+ aria_label: 'Rezultatet e lundrimit'
154
156
  sort:
155
157
  label: 'Klasifikoj sipas %{field}' # TODO: Remove during major release
156
158
  label_html: 'Klasifikoj<span class="d-none d-sm-inline"> sipas %{field}</span>'
@@ -22,6 +22,7 @@ zh:
22
22
  blacklight:
23
23
  application_name: 'Blacklight'
24
24
  skip_links:
25
+ label: '跳过链接'
25
26
  main_content: '转到主要内容'
26
27
  search_field: '转到搜索'
27
28
  first_result: '转到第一个搜索结果'
@@ -151,6 +152,7 @@ zh:
151
152
  button_label_html: '%{count}<span class="d-none d-sm-inline"> 每页</span>'
152
153
  title: '每页显示结果数'
153
154
  submit: '更新'
155
+ aria_label: '结果导航'
154
156
  sort:
155
157
  label: '按 %{field} 排序' # TODO: Remove during major release
156
158
  label_html: '<span class="d-none d-sm-inline">按 %{field} </span>排序'
@@ -19,12 +19,13 @@ module Blacklight
19
19
  raise ArgumentError, "Must supply a field name" if self.field.nil?
20
20
  end
21
21
 
22
- def display_label(context = nil)
22
+ def display_label(context = nil, **options)
23
23
  field_label(
24
24
  (:"blacklight.search.fields.#{context}.#{key}" if context),
25
25
  :"blacklight.search.fields.#{key}",
26
26
  label,
27
- default_label
27
+ default_label,
28
+ **options
28
29
  )
29
30
  end
30
31
 
@@ -50,10 +51,10 @@ module Blacklight
50
51
  # before falling back to the label
51
52
  # @param [Symbol] any number of additional keys
52
53
  # @param [Symbol] ...
53
- def field_label *i18n_keys
54
+ def field_label *i18n_keys, **options
54
55
  first, *rest = i18n_keys.compact
55
56
 
56
- I18n.t(first, default: rest)
57
+ I18n.t(first, default: rest, **options)
57
58
  end
58
59
  end
59
60
  end
@@ -208,6 +208,23 @@ RSpec.describe BlacklightHelper do
208
208
  end
209
209
  end
210
210
 
211
+ describe '#render_index_field_label' do
212
+ let(:doc) { SolrDocument.new({}) }
213
+
214
+ before do
215
+ allow(helper).to receive_messages(document_index_view_type: :current_view)
216
+ end
217
+
218
+ it 'accepts an explicit field label' do
219
+ expect(helper.render_index_field_label(doc, field: 'xyz', label: 'some label')).to eq 'some label:'
220
+ end
221
+
222
+ it 'calculates the appropriate field label for a field' do
223
+ allow(helper).to receive(:blacklight_config).and_return(CatalogController.blacklight_config)
224
+ expect(helper.render_index_field_label(doc, field: 'xyz')).to eq 'Xyz:'
225
+ end
226
+ end
227
+
211
228
  describe "render_grouped_response?" do
212
229
  it "checks if the response ivar contains grouped data" do
213
230
  assign(:response, instance_double(Blacklight::Solr::Response, grouped?: true))
@@ -39,13 +39,6 @@ RSpec.describe CatalogHelper do
39
39
  expect(html).to be_html_safe
40
40
  end
41
41
 
42
- it "with an empty page of results" do
43
- @response = double(limit_value: -1)
44
-
45
- html = page_entries_info(@response)
46
- expect(html).to be_blank
47
- end
48
-
49
42
  context "when response.entry_name is nil" do
50
43
  it "does not raise an error" do
51
44
  collection = mock_response total: 10
@@ -1,81 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Blacklight::DocumentPresenter do
4
- let(:presenter) { described_class.new(doc, view_context) }
5
- let(:doc) { instance_double(SolrDocument) }
6
- let(:blacklight_config) { instance_double(Blacklight::Configuration) }
7
- let(:view_context) { double('View context', should_render_field?: true, blacklight_config: blacklight_config) }
4
+ subject(:presenter) { described_class.new(doc, request_context) }
8
5
 
9
- describe '#fields_to_render' do
10
- subject { presenter.fields_to_render }
11
-
12
- let(:field_config) { double(field: 'asdf') }
13
-
14
- context 'when all of the fields have values' do
15
- before do
16
- allow(presenter).to receive_messages(fields: { 'title' => field_config },
17
- render_field?: true,
18
- has_value?: true)
19
- end
6
+ let(:doc) { SolrDocument.new('asdf' => 'asdf') }
7
+ let(:blacklight_config) { Blacklight::Configuration.new }
8
+ let(:request_context) { double('View context', should_render_field?: true, blacklight_config: blacklight_config) }
9
+ let(:controller) { double }
10
+ let(:params) { {} }
11
+ let(:search_state) { Blacklight::SearchState.new(params, blacklight_config, controller) }
20
12
 
21
- it { is_expected.to eq('title' => field_config) }
22
- end
13
+ before do
14
+ allow(request_context).to receive(:search_state).and_return(search_state)
23
15
  end
24
16
 
25
- describe '#render_field?' do
26
- subject { presenter.send(:render_field?, field_config) }
27
-
28
- let(:field_config) { double('field config', if: true, unless: false) }
29
-
30
- before do
31
- allow(presenter).to receive_messages(document_has_value?: true)
32
- end
33
-
34
- it { is_expected.to be true }
17
+ describe '#fields_to_render' do
18
+ subject { presenter.fields_to_render.to_a }
35
19
 
36
- context 'when the view context says not to render the field' do
37
- let(:view_context) { double('View context', should_render_field?: false, blacklight_config: blacklight_config) }
20
+ let(:field_config) { Blacklight::Configuration::Field.new(field: 'asdf') }
38
21
 
22
+ context 'when all of the fields have values' do
39
23
  before do
40
- allow(field_config).to receive_messages(if: false)
24
+ allow(presenter).to receive_messages(fields: { 'title' => field_config })
41
25
  end
42
26
 
43
- it { is_expected.to be false }
27
+ it { is_expected.to include(['title', field_config, an_instance_of(Blacklight::FieldPresenter)]) }
44
28
  end
45
29
  end
46
30
 
47
- describe '#has_value?' do
48
- subject { presenter.send(:has_value?, field_config) }
49
-
50
- context 'when the document has the field value' do
51
- let(:field_config) { double(field: 'asdf', highlight: false, accessor: nil, default: nil, values: nil) }
52
-
53
- before do
54
- allow(doc).to receive(:fetch).with('asdf', nil).and_return(['value'])
55
- end
56
-
57
- it { is_expected.to be true }
58
- end
59
-
60
- context 'when the document has a highlight field value' do
61
- let(:field_config) { double(field: 'asdf', highlight: true) }
62
-
63
- before do
64
- allow(doc).to receive(:has_highlight_field?).with('asdf').and_return(true)
65
- allow(doc).to receive(:highlight_field).with('asdf').and_return(['value'])
66
- end
67
-
68
- it { is_expected.to be true }
69
- end
70
-
71
- context 'when the field is a model accessor' do
72
- let(:field_config) { double(field: 'asdf', highlight: false, accessor: true) }
73
-
74
- before do
75
- allow(doc).to receive(:send).with('asdf').and_return(['value'])
76
- end
31
+ describe '#field_value' do
32
+ let(:field_presenter) { instance_double(Blacklight::FieldPresenter, render: 'xyz') }
33
+ let(:field_config) { instance_double(Blacklight::Configuration::Field) }
34
+ let(:options) { { a: 1 } }
77
35
 
78
- it { is_expected.to be true }
36
+ it 'calls the field presenter' do
37
+ allow(Blacklight::FieldPresenter).to receive(:new).with(request_context, doc, field_config, options).and_return(field_presenter)
38
+ expect(presenter.field_value(field_config, options)).to eq 'xyz'
79
39
  end
80
40
  end
81
41
  end