From 3ed183a756dbb0abc9dccac666971d541f79ba2f Mon Sep 17 00:00:00 2001 From: Yetrina Battad Date: Wed, 19 Jun 2024 13:16:09 +1000 Subject: [PATCH] feat: render chronlist, bibref and tables in notes --- .rubocop.yml | 4 + Gemfile | 4 +- Gemfile.lock | 83 +++--- .../nla/_nla-custom-bootstrap.scss | 13 + app/controllers/catalog_controller.rb | 11 + app/models/solr_document.rb | 28 +- app/presenters/rendering/bibref.rb | 32 +++ app/presenters/rendering/chronlist.rb | 53 ++++ app/presenters/rendering/table.rb | 43 +++ app/presenters/subnotes_presenter.rb | 62 +++++ config/locales/en.yml | 3 + spec/files/notes/chronlist.json | 231 ++++++++++++++++ spec/files/notes/chronlist_calendar.json | 242 ++++++++++++++++ spec/files/notes/multiple_bibref.json | 6 + spec/files/notes/table.json | 261 ++++++++++++++++++ spec/models/solr_document_spec.rb | 9 +- spec/presenters/rendering/bibref_spec.rb | 47 ++++ spec/presenters/rendering/chronlist_spec.rb | 54 ++++ spec/presenters/rendering/table_spec.rb | 31 +++ spec/presenters/subnotes_presenter_spec.rb | 89 ++++++ spec/rails_helper.rb | 1 + spec/support/presenter_test_helpers.rb | 11 + 22 files changed, 1262 insertions(+), 56 deletions(-) create mode 100644 app/presenters/rendering/bibref.rb create mode 100644 app/presenters/rendering/chronlist.rb create mode 100644 app/presenters/rendering/table.rb create mode 100644 app/presenters/subnotes_presenter.rb create mode 100644 spec/files/notes/chronlist.json create mode 100644 spec/files/notes/chronlist_calendar.json create mode 100644 spec/files/notes/multiple_bibref.json create mode 100644 spec/files/notes/table.json create mode 100644 spec/presenters/rendering/bibref_spec.rb create mode 100644 spec/presenters/rendering/chronlist_spec.rb create mode 100644 spec/presenters/rendering/table_spec.rb create mode 100644 spec/presenters/subnotes_presenter_spec.rb create mode 100644 spec/support/presenter_test_helpers.rb diff --git a/.rubocop.yml b/.rubocop.yml index 11c577da..199f67ff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -35,6 +35,10 @@ RSpec/ExampleLength: Enabled: false RSpec/MultipleExpectations: Enabled: false +RSpec/MultipleMemoizedHelpers: + Enabled: false +RSpec/VerifiedDoubles: + Enabled: false Bundler/DuplicatedGem: Enabled: false Capybara: diff --git a/Gemfile b/Gemfile index 1e963ecc..33e23738 100644 --- a/Gemfile +++ b/Gemfile @@ -97,7 +97,7 @@ gem "blacklight_range_limit", git: "https://github.com/nla/blacklight_range_limi group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[mri mingw x64_mingw] - gem "standard", require: false + gem "standard", "~> 1.37", require: false gem "rubocop-rails", require: false gem "rubocop-rspec", require: false gem "rubocop-performance", require: false @@ -111,6 +111,8 @@ group :development, :test do gem "shoulda-matchers" gem "factory_bot_rails" gem "faker" + + gem "foreman" end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 88491db3..edf5938e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,13 +102,13 @@ GEM i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - addressable (2.8.5) + addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) aes_key_wrap (1.1.0) annotaterb (4.9.0) anyway_config (2.6.4) ruby-next-core (~> 1.0) - arclight (1.0.1) + arclight (1.4.0) blacklight (>= 8.0.0, < 9) gretel rails (~> 7.0) @@ -118,7 +118,7 @@ GEM awesome_print (1.9.2) base64 (0.2.0) bcrypt (3.1.20) - benchmark-ips (2.12.0) + benchmark-ips (2.13.0) better_errors (2.10.1) erubi (>= 1.0.0) rack (>= 0.9.0) @@ -128,7 +128,7 @@ GEM bindex (0.8.1) binding_of_caller (1.0.1) debug_inspector (>= 1.2.0) - blacklight (8.2.0) + blacklight (8.3.0) globalid i18n (>= 1.7.0) jbuilder (~> 2.7) @@ -138,7 +138,7 @@ GEM view_component (>= 2.66, < 4) blacklight-locale_picker (1.1.0) rails (>= 5.2.3, < 7.2) - bootsnap (1.17.0) + bootsnap (1.18.3) msgpack (~> 1.2) brakeman (6.1.2) racc @@ -146,11 +146,11 @@ GEM bundler-audit (0.9.1) bundler (>= 1.2.0, < 3) thor (~> 1.0) - capybara (3.39.2) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) @@ -158,7 +158,8 @@ GEM cgi (0.4.1) concurrent-ruby (1.3.3) connection_pool (2.4.1) - crack (0.4.5) + crack (1.0.0) + bigdecimal rexml crass (1.0.6) cssbundling-rails (1.4.0) @@ -195,10 +196,10 @@ GEM warden (~> 1.2.3) diff-lcs (1.5.1) docile (1.4.0) - domain_name (0.6.20231109) + domain_name (0.6.20240107) dot-properties (0.1.4) bundler (>= 2.2.33) - dotenv (3.0.3) + dotenv (3.1.2) dry-initializer (3.1.1) erubi (1.13.0) factory_bot (6.4.6) @@ -206,19 +207,21 @@ GEM factory_bot_rails (6.4.3) factory_bot (~> 6.4) railties (>= 5.0.0) - faker (3.2.2) + faker (3.4.1) i18n (>= 1.8.11, < 2) - faraday (2.9.0) + faraday (2.9.1) faraday-net_http (>= 2.0, < 3.2) faraday-follow_redirects (0.3.0) faraday (>= 1, < 3) faraday-net_http (3.1.0) net-http - ffi (1.16.3) - ffi-compiler (1.0.1) - ffi (>= 1.0.0) + ffi (1.17.0-arm64-darwin) + ffi (1.17.0-x86_64-linux-gnu) + ffi-compiler (1.3.2) + ffi (>= 1.15.5) rake flamegraph (0.9.5) + foreman (0.88.1) fuubar (2.5.1) rspec-core (~> 3.0) ruby-progressbar (~> 1.4) @@ -226,29 +229,30 @@ GEM ffi (~> 1.0) globalid (1.2.1) activesupport (>= 6.1) - gretel (4.6.0) + gretel (5.0.0) actionview (>= 5.1, < 7.2) railties (>= 5.1, < 7.2) - hashdiff (1.0.1) + hashdiff (1.1.0) hashie (5.0.0) heapy (0.2.0) thor hiredis (0.6.3) hiredis-client (0.18.0) redis-client (= 0.18.0) - http (5.1.1) + http (5.2.0) addressable (~> 2.8) + base64 (~> 0.1) http-cookie (~> 1.0) http-form_data (~> 2.2) - llhttp-ffi (~> 0.4.0) - http-cookie (1.0.5) + llhttp-ffi (~> 0.5.0) + http-cookie (1.0.6) domain_name (~> 0.5) http-form_data (2.3.0) httpclient (2.8.3) i18n (1.14.5) concurrent-ruby (~> 1.0) io-console (0.7.2) - irb (1.13.1) + irb (1.13.2) rdoc (>= 4.0.0) reline (>= 0.4.2) jbuilder (2.12.0) @@ -282,7 +286,7 @@ GEM kaminari-core (1.2.2) language_server-protocol (3.17.0.3) lint_roller (1.1.0) - llhttp-ffi (0.4.0) + llhttp-ffi (0.5.0) ffi-compiler (~> 1.0) rake (~> 13.0) lograge (0.14.0) @@ -306,7 +310,7 @@ GEM marc (~> 1.0) marcel (1.0.4) matrix (0.4.2) - memory_profiler (1.0.1) + memory_profiler (1.0.2) method_source (1.1.0) mini_histogram (0.3.1) mini_mime (1.1.5) @@ -319,7 +323,7 @@ GEM mysql2 (0.5.6) net-http (0.4.1) uri - net-imap (0.4.12) + net-imap (0.4.13) date net-protocol net-pop (0.1.2) @@ -364,7 +368,7 @@ GEM prometheus-client (4.2.2) psych (5.1.2) stringio - public_suffix (5.0.4) + public_suffix (5.1.0) puma (6.4.2) nio4r (~> 2.0) racc (1.8.0) @@ -417,9 +421,9 @@ GEM redis-client (0.18.0) connection_pool regexp_parser (2.9.2) - reline (0.5.8) + reline (0.5.9) io-console (~> 0.5) - request_store (1.5.1) + request_store (1.7.0) rack (>= 1.4) responders (3.1.1) actionpack (>= 5.2) @@ -427,7 +431,7 @@ GEM retriable (3.1.2) rexml (3.3.0) strscan - rouge (4.2.0) + rouge (4.3.0) rsolr (2.6.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) @@ -468,11 +472,11 @@ GEM rubocop-performance (1.21.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.23.1) + rubocop-rails (2.25.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) - rubocop-ast (>= 1.30.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) rubocop-rspec (3.0.1) rubocop (~> 1.61) ruby-next-core (1.0.3) @@ -485,7 +489,7 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - shoulda-matchers (6.1.0) + shoulda-matchers (6.2.0) activesupport (>= 5.2.0) simplecov (0.22.0) docile (~> 1.1) @@ -527,13 +531,13 @@ GEM rubocop-performance (~> 1.21.0) stimulus-rails (1.3.3) railties (>= 6.0.0) - stringio (3.1.0) - strong_migrations (1.7.0) + stringio (3.1.1) + strong_migrations (1.8.0) activerecord (>= 5.2) strscan (3.1.0) thor (1.3.1) timeout (0.4.1) - traject (3.8.1) + traject (3.8.2) concurrent-ruby (>= 0.8.0) dot-properties (>= 0.1.1) hashie (>= 3.1, < 6) @@ -549,7 +553,7 @@ GEM deprecation jsonpath traject (~> 3.0) - turbo-rails (1.5.0) + turbo-rails (2.0.5) actionpack (>= 6.0.0) activejob (>= 6.0.0) railties (>= 6.0.0) @@ -572,7 +576,7 @@ GEM activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webmock (3.19.1) + webmock (3.23.1) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -600,7 +604,7 @@ GEM railties yabeda (~> 0.8) yell (2.2.2) - zeitwerk (2.6.15) + zeitwerk (2.6.16) zk (1.10.0) zookeeper (~> 1.5.0) zookeeper (1.5.5) @@ -630,6 +634,7 @@ DEPENDENCIES factory_bot_rails faker flamegraph + foreman fuubar hiredis (~> 0.6.3) hiredis-client (~> 0.18.0) @@ -659,7 +664,7 @@ DEPENDENCIES solr_wrapper (>= 0.3) sprockets-rails stackprof - standard + standard (~> 1.37) stimulus-rails strong_migrations (~> 1.7) turbo-rails @@ -675,4 +680,4 @@ RUBY VERSION ruby 3.2.2p53 BUNDLED WITH - 2.5.10 + 2.5.13 diff --git a/app/assets/stylesheets/nla/_nla-custom-bootstrap.scss b/app/assets/stylesheets/nla/_nla-custom-bootstrap.scss index b87ff594..0b23a281 100644 --- a/app/assets/stylesheets/nla/_nla-custom-bootstrap.scss +++ b/app/assets/stylesheets/nla/_nla-custom-bootstrap.scss @@ -130,3 +130,16 @@ $form-check-input-focus-box-shadow: $focus-ring-box-shadow; $nav-link-focus-box-shadow: $focus-ring-box-shadow; $pagination-focus-box-shadow: $focus-ring-box-shadow; $btn-close-focus-shadow: $focus-ring-box-shadow; + +// Tables +$table-variants: ( + "primary": shift-color($primary, $table-bg-scale), + "secondary": shift-color($secondary, $table-bg-scale), + "success": shift-color($success, $table-bg-scale), + "info": shift-color($info, $table-bg-scale), + "warning": shift-color($warning, $table-bg-scale), + "danger": shift-color($danger, $table-bg-scale), + "light": $light, + "dark": $dark, + "purple": $purple +) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 1738ed53..31b095d1 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -324,6 +324,7 @@ class CatalogController < ApplicationController config.add_background_field "biog", label: I18n.t("ead_notes.biog"), helper_method: :render_html_tags, + presenter: SubnotesPresenter, values: ->(__field_config, document, _context) { document.extract_notes_by_header("biog") } config.add_background_field "org_hist", label: I18n.t("ead_notes.org_hist"), @@ -366,6 +367,16 @@ class CatalogController < ApplicationController config.add_background_field "physdesc_dimensions", field: "physdesc_dimensions_ssi", label: I18n.t("ead_notes.dimensions"), helper: :render_html_tags config.add_background_field "materialspec", field: "meterialspec_tesim", label: I18n.t("ead_notes.material_spec"), helper: :render_html_tags config.add_background_field "physdesc", field: "physdesc_facet_ssi", label: I18n.t("ead_notes.phys_desc"), helper: :render_html_tags + config.add_background_field "container_list", + label: I18n.t("ead_notes.container_list"), + helper_method: :render_html_tags, + presenter: SubnotesPresenter, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("container_list") } + config.add_background_field "box_list", + label: I18n.t("ead_notes.box_list"), + helper_method: :render_html_tags, + presenter: SubnotesPresenter, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("box_list") } # Collection Show Page - Related Section config.add_related_field "relatedmaterial", field: "relatedmaterial_html_tesm", helper_method: :render_html_tags diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb index ec256348..ce473891 100644 --- a/app/models/solr_document.rb +++ b/app/models/solr_document.rb @@ -70,29 +70,31 @@ def parse_note_paragraphs(notes) # Sometimes note paragraphs are returned as a simple JSON string, and other times, as an array. # Ensure we always have an array by wrapping the paragraphs in an array, then flatten the array, # so we only return a single dimensional array of paragraphs. - notes.map! { |note| [JSON.parse(note)["p"]] } + notes.map! { |note| Array.wrap(JSON.parse(note)["p"]) } .flatten! end def wrap_paragraphs_in_html(paragraphs) - # Wraps note paragrphs in HTML `

` tags, then scrubs the HTML to remove any unknown or - # unsafe tags. paragraphs.map! do |para| - Loofah.xml_fragment(wrap_in_paragraph(para)) - .scrub!(:strip) - .to_html + if para.is_a?(String) + # Wraps note paragraphs in HTML `

` tags, then scrubs the HTML to remove any unknown or + # unsafe tags. + Loofah.xml_fragment(wrap_in_paragraph(para)) + .scrub!(:strip) + .to_html + elsif para.is_a?(Hash) + # Turn the hash into JSON because it's easier to convert back into an object + # than a string representation of a Hash. + para.to_json + end end end def wrap_in_paragraph(value) - if value.is_a?(String) - if value.start_with?("<") - value - else - ActionController::Base.helpers.content_tag(:p, value) - end - else + if value.start_with?("<") value + else + ActionController::Base.helpers.content_tag(:p, value) end end end diff --git a/app/presenters/rendering/bibref.rb b/app/presenters/rendering/bibref.rb new file mode 100644 index 00000000..4edfcc66 --- /dev/null +++ b/app/presenters/rendering/bibref.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module Rendering + class Bibref < Blacklight::Rendering::AbstractStep + def render + next_step(render_bibref) + end + + private + + def render_bibref + fragment = Nokogiri::HTML::DocumentFragment.parse("") + + Nokogiri::HTML::Builder.with(fragment) do |doc| + doc.h4 { + doc.text I18n.t("ead_notes.bibref") + } + + doc.ul(class: "list-unstyled") { + # Sometimes the value is a single string instead of an array of strings + Array.wrap(values).each do |value| + doc.li do |list_item| + list_item << value + end + end + } + end + + fragment.to_html + end + end +end diff --git a/app/presenters/rendering/chronlist.rb b/app/presenters/rendering/chronlist.rb new file mode 100644 index 00000000..38b0c415 --- /dev/null +++ b/app/presenters/rendering/chronlist.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +module Rendering + class Chronlist < Blacklight::Rendering::AbstractStep + def render + next_step(render_chronlist) + end + + private + + def render_chronlist + header_keys = [] + values["listhead"].each do |header| + header_keys << header[1].downcase + end + + fragment = Nokogiri::HTML::DocumentFragment.parse("") + + Nokogiri::HTML::Builder.with(fragment) do |doc| + doc.table(class: "table table-light table-responsive table-striped table-hover") do + doc.thead(class: "table-purple") { + doc.tr { + header_keys.each do |header| + doc.th { + doc.text header.titleize + } + end + } + } + + doc.tbody(class: "table-group-divider") { + values["chronitem"].map! do |item| + doc.tr { + header_keys.each do |key| + doc.td(class: (key == "date") ? "text-nowrap" : "") { + # sometimes the value contains a calendar element + if item[key].is_a?(Hash) + doc.text item[key]["content"] + else + doc.text item[key] + end + } + end + } + end + } + end + end + + fragment.to_html + end + end +end diff --git a/app/presenters/rendering/table.rb b/app/presenters/rendering/table.rb new file mode 100644 index 00000000..7d435d81 --- /dev/null +++ b/app/presenters/rendering/table.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Rendering + class Table < Blacklight::Rendering::AbstractStep + def render + next_step(render_table) + end + + private + + def render_table + fragment = Nokogiri::HTML::DocumentFragment.parse("") + + Nokogiri::HTML::Builder.with(fragment) do |doc| + doc.table(class: "table table-light table-responsive table-striped table-hover") { + doc.thead(class: "table-purple") { + doc.tr { + values["tgroup"]["thead"]["row"]["entry"].map! do |header| + doc.th { + doc.text header + } + end + } + } + + doc.tbody(class: "table-group-divider") { + values["tgroup"]["tbody"]["row"].map! do |row| + doc.tr { + row["entry"]&.map! do |entry| + doc.td { + doc.text entry + } + end + } + end + } + } + end + + fragment.to_html + end + end +end diff --git a/app/presenters/subnotes_presenter.rb b/app/presenters/subnotes_presenter.rb new file mode 100644 index 00000000..0a027ab6 --- /dev/null +++ b/app/presenters/subnotes_presenter.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +class SubnotesPresenter < Blacklight::FieldPresenter + CHRONLIST_ELEMENT = "chronlist" + BIBREF_ELEMENT = "bibref" + TABLE_ELEMENT = "table" + + SUBNOTE_ELEMENTS = [ + CHRONLIST_ELEMENT, BIBREF_ELEMENT, TABLE_ELEMENT + ] + + def render + values.map! do |value| + # Need to check if the value contains a subnote element (JSON), because in some cases, + # it's embedded amongst paragraphs in the note and we don't need to render those separately. + if valid_json?(value) + render_subnote(value) + else + # Otherwise, render it normally + value + end + end + + Blacklight::Rendering::Pipeline.new(values, field_config, document, view_context, pipeline_steps, options).render + end + + private + + def render_subnote(value) + subnote_value = JSON.parse(value) + + rendered_subnote = [] + + # Order matters here! + # If there are multiple subnotes that can appear in a single metadata section, they should be + # rendered in order, since the generated HTML from each subnote is concatenated together to + # form the whole note. + + if subnote_value.key? TABLE_ELEMENT + rendered_subnote << Blacklight::Rendering::Pipeline.new(subnote_value[TABLE_ELEMENT], field_config, document, view_context, [Rendering::Table], options).render + end + + if subnote_value.key? CHRONLIST_ELEMENT + rendered_subnote << Blacklight::Rendering::Pipeline.new(subnote_value[CHRONLIST_ELEMENT], field_config, document, view_context, [Rendering::Chronlist], options).render + end + + if subnote_value.key? BIBREF_ELEMENT + rendered_subnote << Blacklight::Rendering::Pipeline.new(subnote_value[BIBREF_ELEMENT], field_config, document, view_context, [Rendering::Bibref], options).render + end + + # everything else that's not a known subnote element will not be rendered + + rendered_subnote.compact.join + end + + def valid_json?(value) + JSON.parse(value) + true + rescue JSON::ParserError + false + end +end diff --git a/config/locales/en.yml b/config/locales/en.yml index a76880d8..8186a2d2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -52,4 +52,7 @@ en: dimensions: "Dimensions" material_spec: "Materials Specific Details" phys_desc: "Physical Description" + container_list: "Container List" + box_list: "Box List" + bibref: "Bibliographic Reference(s)" diff --git a/spec/files/notes/chronlist.json b/spec/files/notes/chronlist.json new file mode 100644 index 00000000..88b0af60 --- /dev/null +++ b/spec/files/notes/chronlist.json @@ -0,0 +1,231 @@ +{ + "chronlist": { + "listhead": { + "head01": "Date", + "head02": "Event" + }, + "chronitem": [ + { + "date": 1925, + "event": "Born in Yarram, Victoria, on 26 October" + }, + { + "date": "1942-1943", + "event": "Student teacher, Department of Education, Victoria" + }, + { + "date": "1943-1946", + "event": "Navigator, Royal Australian Air Force" + }, + { + "date": 1948, + "event": "Bachelor of Arts (Honours), University of Melbourne" + }, + { + "date": "1949-1951", + "event": "Tutor in History, University of Melbourne" + }, + { + "date": 1951, + "event": "Master of Arts (Honours), University of Melbourne" + }, + { + "date": "", + "event": "Inaugural Archbishop Mannix Travelling Scholar" + }, + { + "date": "1951-1953", + "event": "Australian National University Research Scholar, University of Cambridge" + }, + { + "date": 1953, + "event": "Bachelor of Arts, University of Cambridge" + }, + { + "date": "1953-1958", + "event": "Lecturer in History, University of Melbourne" + }, + { + "date": "1959-1964", + "event": "Senior Lecturer in History, University of Melbourne" + }, + { + "date": 1960, + "event": "Master of Arts, University of Cambridge" + }, + { + "date": 1961, + "event": "Foundation Member, Australian Institute of Aboriginal Studies" + }, + { + "date": "", + "event": "Nuffield Foundation Dominion Fellow, Institute of Archaeology (London)" + }, + { + "date": 1963, + "event": "Royal Society of Victoria Research Medal" + }, + { + "date": "1964-1980", + "event": "Council Member, Australian Institute of Aboriginal Studies" + }, + { + "date": "1965-1970", + "event": "Senior Fellow in Prehistory, Research School of Pacific Studies, Australian National University" + }, + { + "date": "1965-1976", + "event": "Executive Member, Australian Institute of Aboriginal Studies" + }, + { + "date": 1969, + "event": "Australian Literature Society Dame Mary Gilmore Medal" + }, + { + "date": 1970, + "event": "Doctor of Philosophy, University of Cambridge" + }, + { + "date": "", + "event": "Fellow, Australian Academy of the Humanities" + }, + { + "date": 1971, + "event": "Acting Principal, Australian Institute of Aboriginal Studies" + }, + { + "date": "1971-1985", + "event": "Foundation Professor of Prehistory, Faculty of Arts, Australian National University" + }, + { + "date": "1972-1974", + "event": "Council Member, Australian Academy of the Humanities" + }, + { + "date": "1972-1976", + "event": "Deputy Chairman, Australian Institute of Aboriginal Studies" + }, + { + "date": "1974-1975", + "event": "Member, Committee of Inquiry into Museums and National Collections" + }, + { + "date": 1975, + "event": "Chairman, Planning Committee, Gallery of Aboriginal Australia" + }, + { + "date": "1975-1976", + "event": "Deputy Chairman, Museums Association, Canberra Division" + }, + { + "date": "1976-1977", + "event": "Commonwealth Visiting Professor, University of Cambridge" + }, + { + "date": "1976-1982", + "event": "Australian Heritage Commissioner" + }, + { + "date": 1977, + "event": "Fellow, Society of Antiquaries of London" + }, + { + "date": 1981, + "event": "President, Section 25A (Archaeology), ANZAAS Conference" + }, + { + "date": "1981-1983", + "event": "Member, Interim Council of the Museum of Australia" + }, + { + "date": 1982, + "event": "Companion of the Order of St Michael and St George" + }, + { + "date": "1982-1984", + "event": "Chairman, Australian Institute of Aboriginal Studies" + }, + { + "date": 1983, + "event": "Corresponding Fellow of the British Academy" + }, + { + "date": "1984-1985", + "event": "Visiting Professor in Australian Studies, Harvard University" + }, + { + "date": 1985, + "event": "Whitely Book Award for biography, Royal Zoological Society (NSW)" + }, + { + "date": 1986, + "event": "Emeritus Professor of Prehistory, Australian National University" + }, + { + "date": 1986, + "event": "Honorary Member, Australian Archaeological Association" + }, + { + "date": "", + "event": "Victorian Premier's Literary Award for Australian Studies (with J. H. Calaby)" + }, + { + "date": "1986-1988", + "event": "Chairman, ACT Heritage Committee" + }, + { + "date": "1986-1990", + "event": "Honorary Fellow, Department of History, Research School of Pacific Studies, Australian National University" + }, + { + "date": "1987-1990", + "event": "Honorary Fellow, Museum of Victoria" + }, + { + "date": 1988, + "event": "ANZAAS Medal" + }, + { + "date": "1989-1992", + "event": "Member, Editorial Board, Australian Institute of Aboriginal Studies" + }, + { + "date": "1989-1996", + "event": "Secretary, Australian Academy of the Humanities" + }, + { + "date": 1990, + "event": "Honorary Member, Indo-Pacific Prehistory Association" + }, + { + "date": "", + "event": "Honorary Member, Prehistoric Society (London)" + }, + { + "date": 1991, + "event": "Order of Australia" + }, + { + "date": 1996, + "event": "Honorary Fellow, Royal Anthropological Institute" + }, + { + "date": "1997-1998", + "event": "Ashley Fellow, Trent University (Canada)" + }, + { + "date": 1999, + "event": "Grahame Clark Medal, British Academy" + }, + { + "date": 2001, + "event": "Australian Centenary Medal" + }, + { + "date": 2004, + "event": "Rhys Jones Medal, Australian Archaeological Association" + } + ] + }, + "bibref": "Prehistory to Politics : John Mulvaney, the humanities and the public intellectual, edited by Tim Bonyhady and Tom Griffiths. Carlton South, Victoria : Melbourne University Press, 1996." +} diff --git a/spec/files/notes/chronlist_calendar.json b/spec/files/notes/chronlist_calendar.json new file mode 100644 index 00000000..7992a643 --- /dev/null +++ b/spec/files/notes/chronlist_calendar.json @@ -0,0 +1,242 @@ +{ + "chronlist": { + "listhead": { + "head01": "Date", + "head02": "Event" + }, + "chronitem": [ + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1849 + }, + "event": "Born in Glebe, Sydney, 18 January" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1859-64" + }, + "event": "Attended Sydney Grammar School" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1865-67" + }, + "event": "Attended University of Sydney" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1870 + }, + "event": "Graduated as a Master of Arts" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1871 + }, + "event": "Called to Bar in Sydney" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1879-82" + }, + "event": "Member of Legislative Assembly (University of Sydney seat)" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1882-87" + }, + "event": "Member of Legislative Assembly (seat of East Sydney)" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1883-87" + }, + "event": "Speaker of the Legislative Assembly" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1887-91" + }, + "event": "Member of the Legislative Council" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1887 + }, + "event": "Attorney-General in the Dibbs Protectionist Ministry" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1891 + }, + "event": "New South Wales delegate at the Federal Convention in Sydney" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1891-94" + }, + "event": "Member of the Legislative Assembly (East Sydney)" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1891-92" + }, + "event": "Attorney-General in the Dibbs Protectionist Ministry" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1894 + }, + "event": "Defeated in the general election (seat of Randwick)" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1894-97" + }, + "event": "Led the Federation movement in New South Wales" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1897-98" + }, + "event": "New South Wales delegate at the Australasian Federal Convention and chairman of the drafting and constitutional committees" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1897-98" + }, + "event": "Member of the Legislative Council" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1898 + }, + "event": "Defeated by George Reid in the general election (seat of Sydney (King Division))" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1898-1900" + }, + "event": "Member of the Legislative Assembly (seat of Hastings and Macleay)" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1899 + }, + "event": "Leader of the Australian delegation to London" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1900 + }, + "event": "Appointed first Prime Minister of Australia and Minister for External Affairs, 31 December" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1901 + }, + "event": "Appointed a Privy Councillor, 24 January" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1901-3" + }, + "event": "Member of the House of Representatives (seat of Hunter)" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1902 + }, + "event": "Attended Colonial Conference and Coronation of King Edward VII" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1902 + }, + "event": "Knighted (GCMG)" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1903 + }, + "event": "Resigned as Prime Minister, 23 September" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": "1903-20" + }, + "event": "Senior puisne justice of the High Court of Australia" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1915 + }, + "event": "Visited England" + }, + { + "date": { + "calendar": "gregorian", + "era": "ce", + "content": 1920 + }, + "event": "Died at Medlow Bath, Blue Mountains, 7 January" + } + ] + } +} diff --git a/spec/files/notes/multiple_bibref.json b/spec/files/notes/multiple_bibref.json new file mode 100644 index 00000000..561fb974 --- /dev/null +++ b/spec/files/notes/multiple_bibref.json @@ -0,0 +1,6 @@ +{ + "bibref": [ + "Who's who in Australia, 1977.", + "Melbourne Herald and Weekly Times, 1977." + ] +} diff --git a/spec/files/notes/table.json b/spec/files/notes/table.json new file mode 100644 index 00000000..5b96f948 --- /dev/null +++ b/spec/files/notes/table.json @@ -0,0 +1,261 @@ +{ + "table": { + "tgroup": { + "colspec": { + "colwidth": 33 + }, + "tbody": { + "row": [ + { + "entry": [ + 1, + "1-6", + 1 + ] + }, + { + "entry": [ + 2, + 7, + 1 + ] + }, + { + "entry": [ + 2, + "8-12", + 2 + ] + }, + { + "entry": [ + 2, + "13-15", + 3 + ] + }, + { + "entry": [ + 2, + "16-19", + 4 + ] + }, + { + "entry": [ + 2, + "20-26", + 5 + ] + }, + { + "entry": [ + 2, + "27-34", + 6 + ] + }, + { + "entry": [ + 3, + 35, + 7 + ] + }, + { + "entry": [ + 4, + "36-38", + 7 + ] + }, + { + "entry": [ + 5, + "39-43", + 7 + ] + }, + { + "entry": [ + 6, + "44-47", + 8 + ] + }, + { + "entry": [ + "7A", + "48-50", + 8 + ] + }, + { + "entry": [ + "7B", + 51, + 8 + ] + }, + { + "entry": [ + "7B", + "52-53", + 9 + ] + }, + { + "entry": [ + "7C", + "54-55", + 9 + ] + }, + { + "entry": [ + 8, + "56-57", + 9 + ] + }, + { + "entry": [ + 9, + "59-60", + 9 + ] + }, + { + "entry": [ + 9, + 61, + 10 + ] + }, + { + "entry": [ + 9, + "Folio 1", + "Folio Run" + ] + }, + { + "entry": [ + "10A", + "62-65", + 10 + ] + }, + { + "entry": [ + "10A", + "66-68", + 11 + ] + }, + { + "entry": [ + "10B", + "69-71", + 11 + ] + }, + { + "entry": [ + "10B", + 72, + 12 + ] + }, + { + "entry": [ + "10C", + "73-78", + 12 + ] + }, + { + "entry": [ + "10C", + "Folio 4", + "Folio Run" + ] + }, + { + "entry": [ + 11, + "79-84", + 13 + ] + }, + { + "entry": [ + 11, + "printed material", + 14 + ] + }, + { + "entry": [ + 11, + "printed material", + 15 + ] + }, + { + "entry": [ + 11, + "Folio 2", + "Folio Run" + ] + }, + { + "entry": [ + 12, + "85-88", + 16 + ] + }, + { + "entry": [ + 13, + "89-90", + 16 + ] + }, + { + "entry": [ + 13, + "Folio 3", + "Folio Run" + ] + }, + { + "entry": [ + 14, + 91, + 16 + ] + }, + { + "entry": [ + 8, + 58, + 16 + ] + } + ] + }, + "thead": { + "row": { + "entry": [ + "Series", + "File/Item", + "Box" + ] + } + }, + "cols": 3 + } + } +} diff --git a/spec/models/solr_document_spec.rb b/spec/models/solr_document_spec.rb index 46db930d..6a1f87a2 100644 --- a/spec/models/solr_document_spec.rb +++ b/spec/models/solr_document_spec.rb @@ -209,7 +209,7 @@ end end - context "when note doesn't contain text" do + context "when note doesn't contains a chronlist" do subject(:notes_value) do document.extract_notes_by_header("biog") end @@ -222,8 +222,11 @@ ) } - it "doesn't try to wrap the content" do - expect(notes_value).not_to be_a(String) + it "converts the Hash into JSON" do + expect(notes_value[0]).to be_a(String) + expect(JSON.parse(notes_value[0])["chronlist"]).not_to be_nil + expect(JSON.parse(notes_value[0])["chronlist"]["listhead"]).not_to be_nil + expect(JSON.parse(notes_value[0])["chronlist"]["chronitem"]).not_to be_nil end end end diff --git a/spec/presenters/rendering/bibref_spec.rb b/spec/presenters/rendering/bibref_spec.rb new file mode 100644 index 00000000..68dcf769 --- /dev/null +++ b/spec/presenters/rendering/bibref_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe Rendering::Bibref do + include Capybara::RSpecMatchers + let(:document) { instance_double(SolrDocument) } + let(:context) { double } + let(:options) { {} } + + describe "#render" do + subject(:rendered) { Blacklight::Rendering::Pipeline.new(values, field_config, document, context, [described_class], options).render } + + let(:field_config) { Blacklight::Configuration::NullField.new } + + context "when the note has a single bibref string" do + let(:note) { JSON.parse(IO.read("spec/files/notes/chronlist.json")) } + let(:values) { note["bibref"] } + + it "renders the bibref" do + expect(rendered).to have_css("h4", text: "Bibliographic Reference(s)") + expect(rendered).to have_css("ul.list-unstyled") + expect(rendered).to have_css("li", count: 1) + end + + it "inserts the existing HTML" do + expect(rendered).to include("Prehistory to Politics") + expect(rendered).to have_link(href: "http://nla.gov.au/nla.cat-vn2823420") + end + end + + context "when the note has multiple bibref strings" do + let(:note) { JSON.parse(IO.read("spec/files/notes/multiple_bibref.json")) } + let(:values) { note["bibref"] } + + it "renders the bibref" do + expect(rendered).to have_css("h4", text: "Bibliographic Reference(s)") + expect(rendered).to have_css("ul.list-unstyled") + expect(rendered).to have_css("li", count: 2) + end + + it "inserts the existing HTML" do + expect(rendered).to have_css("em", text: "Who's who in Australia") + end + end + end +end diff --git a/spec/presenters/rendering/chronlist_spec.rb b/spec/presenters/rendering/chronlist_spec.rb new file mode 100644 index 00000000..558f0dc4 --- /dev/null +++ b/spec/presenters/rendering/chronlist_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe Rendering::Chronlist do + include Capybara::RSpecMatchers + let(:document) { instance_double(SolrDocument) } + let(:context) { double } + let(:options) { {} } + + describe "#render" do + subject(:rendered) { Blacklight::Rendering::Pipeline.new(values, field_config, document, context, [described_class], options).render } + + let(:note) { JSON.parse(IO.read("spec/files/notes/chronlist.json")) } + let(:values) { note["chronlist"] } + let(:field_config) { Blacklight::Configuration::NullField.new } + + it "renders a chronlist" do + expect(rendered).to have_table(class: %w[table-light table-responsive table-striped table-hover]) + expect(rendered).to have_css("thead.table-purple") + expect(rendered).to have_css("tbody.table-group-divider") + expect(rendered).to have_css("td.text-nowrap") + + expect(rendered).to have_css("th", text: "Date") + expect(rendered).to have_css("th", text: "Event") + + expect(rendered).to have_css("td", text: "1925") + expect(rendered).to have_css("td", text: "Born in Yarram, Victoria, on 26 October") + + expect(rendered).to have_css("td", text: "1942-1943") + expect(rendered).to have_css("td", text: "Rhys Jones Medal, Australian Archaeological Association") + end + + context "when the date has a calendar structure" do + let(:note) { JSON.parse(IO.read("spec/files/notes/chronlist_calendar.json")) } + + it "renders the chronlist with just the date" do + expect(rendered).to have_table(class: %w[table-light table-responsive table-striped table-hover]) + expect(rendered).to have_css("thead.table-purple") + expect(rendered).to have_css("tbody.table-group-divider") + expect(rendered).to have_css("td.text-nowrap") + + expect(rendered).to have_css("th", text: "Date") + expect(rendered).to have_css("th", text: "Event") + + expect(rendered).to have_css("td", text: "1849") + expect(rendered).to have_css("td", text: "Born in Glebe, Sydney, 18 January") + + expect(rendered).to have_css("td", text: "1891-92") + expect(rendered).to have_css("td", text: "Attorney-General in the Dibbs Protectionist Ministry") + end + end + end +end diff --git a/spec/presenters/rendering/table_spec.rb b/spec/presenters/rendering/table_spec.rb new file mode 100644 index 00000000..ffc10067 --- /dev/null +++ b/spec/presenters/rendering/table_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe Rendering::Table do + include Capybara::RSpecMatchers + let(:document) { instance_double(SolrDocument) } + let(:context) { double } + let(:options) { {} } + + describe "#render" do + subject(:rendered) { Blacklight::Rendering::Pipeline.new(values, field_config, document, context, [described_class], options).render } + + let(:note) { JSON.parse(IO.read("spec/files/notes/table.json")) } + let(:values) { note["table"] } + let(:field_config) { Blacklight::Configuration::NullField.new } + + it "renders a table" do + expect(rendered).to have_table(class: %w[table-light table-responsive table-striped table-hover]) + expect(rendered).to have_css("thead.table-purple") + expect(rendered).to have_css("tbody.table-group-divider") + + expect(rendered).to have_css("thead tr", count: 1) + expect(rendered).to have_css("th", text: "Series") + expect(rendered).to have_css("th", text: "File/Item") + expect(rendered).to have_css("th", text: "Box") + + expect(rendered).to have_css("tbody tr", count: 34) + end + end +end diff --git a/spec/presenters/subnotes_presenter_spec.rb b/spec/presenters/subnotes_presenter_spec.rb new file mode 100644 index 00000000..c6e60bf0 --- /dev/null +++ b/spec/presenters/subnotes_presenter_spec.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe SubnotesPresenter, :presenter do + subject(:presenter) { described_class.new(request_context, document, field_config, options) } + + let(:request_context) { double("View context", params: {x: "1"}, search_state: search_state, should_render_field?: true, blacklight_config: config) } + let(:document) do + SolrDocument.new( + id: 1, + note_json_ssm: [ + "{\"head\":\"Biographical Note\",\"p\":[\"Sir Edmund Barton (1849-1920) was the first Prime Minister of the Commonwealth of Australia, having previously been a leading advocate of Federation and one of the draftsmen of the Australian Constitution. He served as Prime Minister from 1 January 1901 until 23 September 1903, and then resigned to become the senior puisne judge of the newly-established High Court of Australia.\",\"Edmund Barton was the fourth and youngest son of William Barton (1795-1881) and Mary Louisa, née Whydah, who had emigrated from England to New South Wales in 1827. An elder brother was the barrister, journalist and author George B. Barton (1836-1901). On 28 December 1877 Edmund Barton married Jane (Jean) Mason Ross (1851-1938). Their children were Edmund Alfred (b. 1879), Wilfrid Alexander (b. 1880), Jean Alice (b. 1882), Arnold Hubert (b. 1884), Oswald (b. 1888) and Leila Stephanie (b. 1892).\",{\"chronlist\":{\"listhead\":{\"head01\":\"Date\",\"head02\":\"Event\"},\"chronitem\":[{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1849},\"event\":\"Born in Glebe, Sydney, 18 January\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1859-64\"},\"event\":\"Attended Sydney Grammar School\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1865-67\"},\"event\":\"Attended University of Sydney\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1870},\"event\":\"Graduated as a Master of Arts\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1871},\"event\":\"Called to Bar in Sydney\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1879-82\"},\"event\":\"Member of Legislative Assembly (University of Sydney seat)\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1882-87\"},\"event\":\"Member of Legislative Assembly (seat of East Sydney)\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1883-87\"},\"event\":\"Speaker of the Legislative Assembly\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1887-91\"},\"event\":\"Member of the Legislative Council\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1887},\"event\":\"Attorney-General in the Dibbs Protectionist Ministry\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1891},\"event\":\"New South Wales delegate at the Federal Convention in Sydney\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1891-94\"},\"event\":\"Member of the Legislative Assembly (East Sydney)\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1891-92\"},\"event\":\"Attorney-General in the Dibbs Protectionist Ministry\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1894},\"event\":\"Defeated in the general election (seat of Randwick)\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1894-97\"},\"event\":\"Led the Federation movement in New South Wales\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1897-98\"},\"event\":\"New South Wales delegate at the Australasian Federal Convention and chairman of the drafting and constitutional committees\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1897-98\"},\"event\":\"Member of the Legislative Council\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1898},\"event\":\"Defeated by George Reid in the general election (seat of Sydney (King Division))\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1898-1900\"},\"event\":\"Member of the Legislative Assembly (seat of Hastings and Macleay)\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1899},\"event\":\"Leader of the Australian delegation to London\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1900},\"event\":\"Appointed first Prime Minister of Australia and Minister for External Affairs, 31 December\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1901},\"event\":\"Appointed a Privy Councillor, 24 January\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1901-3\"},\"event\":\"Member of the House of Representatives (seat of Hunter)\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1902},\"event\":\"Attended Colonial Conference and Coronation of King Edward VII\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1902},\"event\":\"Knighted (GCMG)\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1903},\"event\":\"Resigned as Prime Minister, 23 September\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":\"1903-20\"},\"event\":\"Senior puisne justice of the High Court of Australia\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1915},\"event\":\"Visited England\"},{\"date\":{\"calendar\":\"gregorian\",\"era\":\"ce\",\"content\":1920},\"event\":\"Died at Medlow Bath, Blue Mountains, 7 January\"}]}}],\"audience\":\"internal\",\"chronlist\":{\"audience\":\"internal\",\"chronitem\":[{\"date\":1849,\"eventgrp\":{\"event\":\"Born in Glebe, Sydney, 18 January\"}},{\"date\":\"1859-64\",\"eventgrp\":{\"event\":\"Attended Sydney Grammar School\"}},{\"date\":\"1865-67\",\"eventgrp\":{\"event\":\"Attended University of Sydney\"}},{\"date\":1870,\"eventgrp\":{\"event\":\"Graduated as a Master of Arts\"}},{\"date\":1871,\"eventgrp\":{\"event\":\"Called to Bar in Sydney\"}},{\"date\":\"1879-82\",\"eventgrp\":{\"event\":\"Member of Legislative Assembly (University of Sydney seat)\"}},{\"date\":\"1882-87\",\"eventgrp\":{\"event\":\"Member of Legislative Assembly (seat of East Sydney)\"}},{\"date\":\"1883-87\",\"eventgrp\":{\"event\":\"Speaker of the Legislative Assembly\"}},{\"date\":\"1887-91\",\"eventgrp\":{\"event\":\"Member of the Legislative Council\"}},{\"date\":1887,\"eventgrp\":{\"event\":\"Attorney-General in the Dibbs Protectionist Ministry\"}},{\"date\":1891,\"eventgrp\":{\"event\":\"New South Wales delegate at the Federal Convention in Sydney\"}},{\"date\":\"1891-94\",\"eventgrp\":{\"event\":\"Member of the Legislative Assembly (East Sydney)\"}},{\"date\":\"1891-92\",\"eventgrp\":{\"event\":\"Attorney-General in the Dibbs Protectionist Ministry\"}},{\"date\":1894,\"eventgrp\":{\"event\":\"Defeated in the general election (seat of Randwick)\"}},{\"date\":\"1894-97\",\"eventgrp\":{\"event\":\"Led the Federation movement in New South Wales\"}},{\"date\":\"1897-98\",\"eventgrp\":{\"event\":\"New South Wales delegate at the Australasian Federal Convention and chairman of the drafting and constitutional committees\"}},{\"date\":\"1897-98\",\"eventgrp\":{\"event\":\"Member of the Legislative Council\"}},{\"date\":1898,\"eventgrp\":{\"event\":\"Defeated by George Reid in the general election (seat of Sydney (King Division))\"}},{\"date\":\"1898-1900\",\"eventgrp\":{\"event\":\"Member of the Legislative Assembly (seat of Hastings and Macleay)\"}},{\"date\":1899,\"eventgrp\":{\"event\":\"Leader of the Australian delegation to London\"}},{\"date\":1900,\"eventgrp\":{\"event\":\"Appointed first Prime Minister of Australia and Minister for External Affairs, 31 December\"}},{\"date\":1901,\"eventgrp\":{\"event\":\"Appointed a Privy Councillor, 24 January\"}},{\"date\":\"1901-3\",\"eventgrp\":{\"event\":\"Member of the House of Representatives (seat of Hunter)\"}},{\"date\":1902,\"eventgrp\":{\"event\":\"Attended Colonial Conference and Coronation of King Edward VII\"}},{\"date\":1902,\"eventgrp\":{\"event\":\"Knighted (GCMG)\"}},{\"date\":1903,\"eventgrp\":{\"event\":\"Resigned as Prime Minister, 23 September\"}},{\"date\":\"1903-20\",\"eventgrp\":{\"event\":\"Senior puisne justice of the High Court of Australia\"}},{\"date\":1915,\"eventgrp\":{\"event\":\"Visited England\"}},{\"date\":1920,\"eventgrp\":{\"event\":\"Died at Medlow Bath, Blue Mountains, 7 January\"}}]}}", + "{\"head\":\"Container List\",\"p\":{\"table\":{\"tgroup\":{\"colspec\":{\"colwidth\":33},\"tbody\":{\"row\":[{\"entry\":[1,\"1-6\",1]},{\"entry\":[2,7,1]},{\"entry\":[2,\"8-12\",2]},{\"entry\":[2,\"13-15\",3]},{\"entry\":[2,\"16-19\",4]},{\"entry\":[2,\"20-26\",5]},{\"entry\":[2,\"27-34\",6]},{\"entry\":[3,35,7]},{\"entry\":[4,\"36-38\",7]},{\"entry\":[5,\"39-43\",7]},{\"entry\":[6,\"44-47\",8]},{\"entry\":[\"7A\",\"48-50\",8]},{\"entry\":[\"7B\",51,8]},{\"entry\":[\"7B\",\"52-53\",9]},{\"entry\":[\"7C\",\"54-55\",9]},{\"entry\":[8,\"56-57\",9]},{\"entry\":[9,\"59-60\",9]},{\"entry\":[9,61,10]},{\"entry\":[9,\"Folio 1\",\"Folio Run\"]},{\"entry\":[\"10A\",\"62-65\",10]},{\"entry\":[\"10A\",\"66-68\",11]},{\"entry\":[\"10B\",\"69-71\",11]},{\"entry\":[\"10B\",72,12]},{\"entry\":[\"10C\",\"73-78\",12]},{\"entry\":[\"10C\",\"Folio 4\",\"Folio Run\"]},{\"entry\":[11,\"79-84\",13]},{\"entry\":[11,\"printed material\",14]},{\"entry\":[11,\"printed material\",15]},{\"entry\":[11,\"Folio 2\",\"Folio Run\"]},{\"entry\":[12,\"85-88\",16]},{\"entry\":[13,\"89-90\",16]},{\"entry\":[13,\"Folio 3\",\"Folio Run\"]},{\"entry\":[14,91,16]},{\"entry\":[8,58,16]}]},\"thead\":{\"row\":{\"entry\":[\"Series\",\"File/Item\",\"Box\"]}},\"cols\":3}}}}" + ] + ) + end + let(:options) { {} } + let(:params) { {} } + let(:controller) { double } + let(:search_state) { Blacklight::SearchState.new(params, config, controller) } + + let(:field_config) { config.background_fields[field_name] } + let(:config) do + Blacklight::Configuration.define_field_access :background_field, Blacklight::Configuration::ShowField + Blacklight::Configuration.new.configure do |config| + config.add_background_field "biog", + label: I18n.t("ead_notes.biog"), + helper_method: :render_html_tags, + presenter: described_class, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("biog") } + config.add_background_field "container_list", + label: I18n.t("ead_notes.container_list"), + helper_method: :render_html_tags, + presenter: described_class, + values: ->(__field_config, document, _context) { document.extract_notes_by_header("container_list") } + end + end + + describe "#render" do + subject(:rendered) { presenter.render } + + before do + allow(request_context).to receive(:render_html_tags) do |params| + ActionController::Base.helpers.render_html_tags(params) + end + end + + context "when it contains paragraphs" do + let(:field_name) { "biog" } + + it "renders the subnote paragraphs" do + expect(rendered).to include("

Sir Edmund Barton (1849-1920) was the first Prime Minister of the Commonwealth of Australia, having previously been a leading advocate of Federation and one of the draftsmen of the Australian Constitution. He served as Prime Minister from 1 January 1901 until 23 September 1903, and then resigned to become the senior puisne judge of the newly-established High Court of Australia.

Edmund Barton was the fourth and youngest son of William Barton (1795-1881) and Mary Louisa, née Whydah, who had emigrated from England to New South Wales in 1827. An elder brother was the barrister, journalist and author George B. Barton (1836-1901). On 28 December 1877 Edmund Barton married Jane (Jean) Mason Ross (1851-1938). Their children were Edmund Alfred (b. 1879), Wilfrid Alexander (b. 1880), Jean Alice (b. 1882), Arnold Hubert (b. 1884), Oswald (b. 1888) and Leila Stephanie (b. 1892).

") + end + end + + context "when it contains a chronlist" do + let(:field_name) { "biog" } + + it "renders the chronlist table" do + expect(rendered).to include('') + end + end + + context "when it contains a bibref" do + let(:field_name) { "biog" } + let(:document) do + SolrDocument.new( + id: 1, + note_json_ssm: [ + "{\"head\":\"Biographical Note\",\"p\":[\"Known as Bill to his colleagues, Thomas William Bearup was closely connected with Australian broadcasting from its beginnings in 1923 until his death in 1980. He was awarded an OBE in recognition of his contribution to this field.\",\"Bearup was born in Hamilton, Victoria on 18 August 1897. In 1916 he joined the marine service of Amalgamated Wireless (Australasia) (AWA) as a wireless operator. After five years at sea, he was appointed to AWA's experimental wireless station at Koo-Wee-Rup in Victoria. When that station closed down in 1922, Bearup acted as AWA's Melbourne inspector. In 1923 he travelled to England where he continued to be involved in radio. Upon his return to Australia, he joined the Australian Broadcasting Company and was appointed Studio Manager of the Melbourne radio station, 3LO. In 1929, Bearup became Victorian Manager, a position he retained when the Australian Broadcasting Commission was established in 1932. Bearup's association with the ABC was to last thirty years. In 1936, he spent nine months overseas investigating the broadcasting scene in the United States and Great Britain. From 1937 to 1945, he served the ABC as Assistant General Manager and he was also Acting General Manager from 1940 to 1943 and in 1945. In 1946, Bearup was posted to London as the ABC's Overseas Representative and he held this position until his retirement from the ABC in 1962. As part of his duties he also visited the United States during this period. Bearup was Chairman of radio station 5DN (Adelaide) and a director of the Macquarie Broadcasting Services from 1964 to 1976.\",\"Bearup was also a Freeman and Liveryman of the Worshipful Company of Musicians of the City of London, a life member of the Radio Institute of Radio Engineers (U.S.) and, for 47 years, he was a member of Rotary clubs in Melbourne, Sydney, London and Adelaide. This long service was recognised when he was awarded the Paul Harris Fellowship just before his death. In 1925, he married Dorothy Watson and they had two daughters, Judith and Cecilie. Bearup's wife died in 1979 and he died a year later, at his home in the Adelaide suburb of Belair, on 15 June 1980, aged 82.\",{\"bibref\":[\"Who's who in Australia, 1977.\",\"Melbourne Herald and Weekly Times, 1977.\"]}]}" + ] + ) + end + + it "renders the bibref" do + expect(rendered).to include("
  • Melbourne Herald and Weekly Times, 1977.
  • ") + end + end + + context "when it contains a table" do + let(:field_name) { "container_list" } + + it "renders the table" do + expect(rendered).to include('
    ') + end + end + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 896a93a4..731e490f 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -111,6 +111,7 @@ config.include ViewComponent::TestHelpers, type: :component config.include Capybara::RSpecMatchers, type: :component + config.include PresenterTestHelpers, type: :presenter end Shoulda::Matchers.configure do |config| diff --git a/spec/support/presenter_test_helpers.rb b/spec/support/presenter_test_helpers.rb new file mode 100644 index 00000000..7f8ec07b --- /dev/null +++ b/spec/support/presenter_test_helpers.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module PresenterTestHelpers + def controller + @controller ||= ViewComponent::Base.test_controller.constantize.new.tap { |c| c.request = request }.extend(Rails.application.routes.url_helpers) + end + + def request + @request ||= ActionDispatch::TestRequest.create + end +end