geoblacklight 6.0.0.pre.alpha.1 → 6.0.0.pre.alpha.2

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -0
  3. data/app/components/geoblacklight/document/relations_container_component.html.erb +1 -0
  4. data/app/components/geoblacklight/document/relations_container_component.rb +12 -0
  5. data/app/components/geoblacklight/document/sidebar_component.html.erb +2 -3
  6. data/app/components/geoblacklight/download_links_component.rb +1 -1
  7. data/app/components/geoblacklight/index_map_legend_component.html.erb +6 -6
  8. data/app/components/geoblacklight/login_link_component.rb +1 -1
  9. data/app/components/geoblacklight/static_map_component.html.erb +1 -1
  10. data/app/controllers/relation_controller.rb +1 -1
  11. data/app/helpers/geoblacklight_helper.rb +1 -1
  12. data/app/javascript/geoblacklight/core.js +0 -2
  13. data/app/views/relation/index.html.erb +4 -2
  14. data/lib/generators/geoblacklight/templates/settings.yml +118 -114
  15. data/lib/geoblacklight/configuration/case_insensitive_settings.rb +59 -0
  16. data/lib/geoblacklight/configuration/fields_config.rb +33 -33
  17. data/lib/geoblacklight/configuration/layer_config.rb +28 -0
  18. data/lib/geoblacklight/configuration/leaflet_config.rb +8 -12
  19. data/lib/geoblacklight/configuration/leaflet_layers_config.rb +15 -3
  20. data/lib/geoblacklight/configuration/relationship_config.rb +15 -0
  21. data/lib/geoblacklight/configuration/relationships_config.rb +123 -0
  22. data/lib/geoblacklight/configuration/settings_builder.rb +118 -0
  23. data/lib/geoblacklight/configuration.rb +7 -2
  24. data/lib/geoblacklight/deprecation.rb +7 -0
  25. data/lib/geoblacklight/version.rb +1 -1
  26. data/lib/geoblacklight.rb +1 -1
  27. data/spec/components/geoblacklight/document/sidebar_component_spec.rb +48 -0
  28. data/spec/components/geoblacklight/login_link_component_spec.rb +1 -1
  29. data/spec/lib/geoblacklight/configuration/layer_config_spec.rb +71 -0
  30. data/spec/lib/geoblacklight/configuration/leaflet_layers_config_spec.rb +63 -0
  31. data/spec/lib/geoblacklight/configuration/settings_builder_spec.rb +177 -0
  32. data/spec/lib/geoblacklight/configuration_spec.rb +35 -0
  33. data/spec/lib/geoblacklight/relation/relation_response_spec.rb +4 -4
  34. data/spec/spec_helper.rb +5 -0
  35. metadata +14 -6
  36. data/app/javascript/geoblacklight/initializers/relations.js +0 -40
  37. data/app/views/catalog/_relations_container.html.erb +0 -1
  38. data/lib/geoblacklight/configuration/legacy_settings_builder.rb +0 -94
  39. data/spec/features/show_page_sidebar_static_map_spec.rb +0 -21
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Geoblacklight
4
+ class Configuration
5
+ # Configuration for Leaflet map layer styles.
6
+ class LayerConfig
7
+ include ActiveModel::Model
8
+ include ActiveModel::Attributes
9
+
10
+ attribute :color, :string
11
+ attribute :weight, :integer, default: 1
12
+ attribute :radius, :integer, default: 4
13
+ attribute :sr_color_name, :string
14
+
15
+ # Supports Hash-like access for backward compatibility
16
+ # @param [Symbol, String] key
17
+ def [](key)
18
+ respond_to?(key) ? send(key) : nil
19
+ end
20
+
21
+ # Returns the attributes as a symbolized hash
22
+ # @return [Hash]
23
+ def to_h
24
+ attributes.symbolize_keys
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Geoblacklight
2
4
  class Configuration
3
5
  class LeafletConfig
@@ -13,24 +15,18 @@ module Geoblacklight
13
15
 
14
16
  DEFAULT_LAYERS_CONFIG = {
15
17
  index: {
16
- DEFAULT: {
18
+ DEFAULT: LayerConfig.new(
17
19
  color: "#7FCDBB",
18
- weight: 1,
19
- radius: 4,
20
20
  sr_color_name: "Green"
21
- },
22
- UNAVAILABLE: {
23
- weight: 1,
24
- radius: 4,
21
+ ),
22
+ UNAVAILABLE: LayerConfig.new(
25
23
  color: "#EDF8B1",
26
24
  sr_color_name: "Yellow"
27
- },
28
- SELECTED: {
29
- weight: 1,
30
- radius: 4,
25
+ ),
26
+ SELECTED: LayerConfig.new(
31
27
  color: "#2C7FB8",
32
28
  sr_color_name: "Blue"
33
- }
29
+ )
34
30
  }
35
31
  }.freeze
36
32
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Geoblacklight
2
4
  class Configuration
3
5
  class LeafletLayersConfig
@@ -6,15 +8,25 @@ module Geoblacklight
6
8
 
7
9
  attribute :detect_retina, :boolean, default: true
8
10
 
9
- attr_accessor :index
11
+ attr_reader :index
10
12
 
11
13
  def initialize(attributes = {})
12
14
  super
13
- @index = attributes[:index]
15
+ self.index = attributes[:index]
16
+ end
17
+
18
+ def index=(values)
19
+ @index = (values || {}).transform_values do |val|
20
+ if val.is_a?(LayerConfig)
21
+ val
22
+ else
23
+ LayerConfig.new(val)
24
+ end
25
+ end
14
26
  end
15
27
 
16
28
  def to_h
17
- attributes.merge({"index" => index})
29
+ attributes.merge({"index" => index.transform_values(&:to_h)})
18
30
  end
19
31
  end
20
32
  end
@@ -0,0 +1,15 @@
1
+ module Geoblacklight
2
+ class Configuration
3
+ # Configuration for an individual relationship displayed on a document's show page.
4
+ class RelationshipConfig
5
+ include ActiveModel::Model
6
+ include ActiveModel::Attributes
7
+
8
+ attribute :field, :string
9
+ attribute :icon, :string
10
+ attribute :inverse, :string
11
+ attribute :label, :string
12
+ attribute :query_type, :string
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,123 @@
1
+ module Geoblacklight
2
+ class Configuration
3
+ # Hash-like configuration for the relationships displayed on a document's
4
+ # show page. By default it carries all of the relationships defined in the
5
+ # RELATIONSHIPS_SHOWN section of settings.yml, using lowercase keys.
6
+ class RelationshipsConfig
7
+ include Enumerable
8
+
9
+ DEFAULT_RELATIONSHIPS = {
10
+ member_of_ancestors: {
11
+ field: "pcdm_memberOf_sm",
12
+ icon: "parent-item",
13
+ inverse: :member_of_descendants,
14
+ label: "geoblacklight.relations.member_of_ancestors",
15
+ query_type: "ancestors"
16
+ },
17
+ member_of_descendants: {
18
+ field: "pcdm_memberOf_sm",
19
+ icon: "child-item",
20
+ inverse: :member_of_ancestors,
21
+ label: "geoblacklight.relations.member_of_descendants",
22
+ query_type: "descendants"
23
+ },
24
+ part_of_ancestors: {
25
+ field: "dct_isPartOf_sm",
26
+ icon: "parent-item",
27
+ inverse: :part_of_descendants,
28
+ label: "geoblacklight.relations.part_of_ancestors",
29
+ query_type: "ancestors"
30
+ },
31
+ part_of_descendants: {
32
+ field: "dct_isPartOf_sm",
33
+ icon: "child-item",
34
+ inverse: :part_of_ancestors,
35
+ label: "geoblacklight.relations.part_of_descendants",
36
+ query_type: "descendants"
37
+ },
38
+ relation_ancestors: {
39
+ field: "dct_relation_sm",
40
+ icon: nil,
41
+ inverse: :relation_descendants,
42
+ label: "geoblacklight.relations.relation_ancestors",
43
+ query_type: "ancestors"
44
+ },
45
+ relation_descendants: {
46
+ field: "dct_relation_sm",
47
+ icon: nil,
48
+ inverse: :relation_ancestors,
49
+ label: "geoblacklight.relations.relation_descendants",
50
+ query_type: "descendants"
51
+ },
52
+ replaces_ancestors: {
53
+ field: "dct_replaces_sm",
54
+ icon: nil,
55
+ inverse: :replaces_descendants,
56
+ label: "geoblacklight.relations.replaces_ancestors",
57
+ query_type: "ancestors"
58
+ },
59
+ replaces_descendants: {
60
+ field: "dct_replaces_sm",
61
+ icon: nil,
62
+ inverse: :replaces_ancestors,
63
+ label: "geoblacklight.relations.replaces_descendants",
64
+ query_type: "descendants"
65
+ },
66
+ source_ancestors: {
67
+ field: "dct_source_sm",
68
+ icon: "parent-item",
69
+ inverse: :source_descendants,
70
+ label: "geoblacklight.relations.source_ancestors",
71
+ query_type: "ancestors"
72
+ },
73
+ source_descendants: {
74
+ field: "dct_source_sm",
75
+ icon: "child-item",
76
+ inverse: :source_ancestors,
77
+ label: "geoblacklight.relations.source_descendants",
78
+ query_type: "descendants"
79
+ },
80
+ version_of_ancestors: {
81
+ field: "dct_isVersionOf_sm",
82
+ icon: "parent-item",
83
+ inverse: :version_of_descendants,
84
+ label: "geoblacklight.relations.version_of_ancestors",
85
+ query_type: "ancestors"
86
+ },
87
+ version_of_descendants: {
88
+ field: "dct_isVersionOf_sm",
89
+ icon: "child-item",
90
+ inverse: :version_of_ancestors,
91
+ label: "geoblacklight.relations.version_of_descendants",
92
+ query_type: "descendants"
93
+ }
94
+ }.freeze
95
+
96
+ def initialize(relationships = DEFAULT_RELATIONSHIPS)
97
+ @relationships = relationships.to_h.transform_values do |attrs|
98
+ attrs.is_a?(RelationshipConfig) ? attrs : RelationshipConfig.new(attrs)
99
+ end
100
+ end
101
+
102
+ def each(&block)
103
+ @relationships.each(&block)
104
+ end
105
+
106
+ def each_key(&block)
107
+ @relationships.each_key(&block)
108
+ end
109
+
110
+ def key?(key)
111
+ @relationships.key?(key)
112
+ end
113
+
114
+ def [](key)
115
+ @relationships[key]
116
+ end
117
+
118
+ def method_missing(name, *args, **kwargs, &block) # rubocop:disable Style/MissingRespondToMissing
119
+ @relationships.key?(name) ? @relationships[name] : super
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,118 @@
1
+ module Geoblacklight
2
+ class Configuration
3
+ # Builds a configuration from legacy (uppercase) settings
4
+ class SettingsBuilder
5
+ def self.build
6
+ new.build
7
+ end
8
+
9
+ def initialize(settings: Settings)
10
+ @configuration = Configuration.new
11
+ @settings = CaseInsensitiveSettings.new(settings, deprecation: Geoblacklight::Deprecation)
12
+ end
13
+
14
+ def build
15
+ @configuration.tap do |config|
16
+ assign(config, :arcgis_base_url, settings.ARCGIS_BASE_URL)
17
+ assign(config, :bbox_within_boost, settings.BBOX_WITHIN_BOOST)
18
+ assign(config, :overlap_ratio_boost, settings.OVERLAP_RATIO_BOOST)
19
+ assign(config, :display_notes_shown, build_display_notes)
20
+ assign(config, :institution, settings.INSTITUTION)
21
+ assign(config, :help_text, settings.HELP_TEXT&.to_h)
22
+ assign(config, :sidebar_static_map, settings.SIDEBAR_STATIC_MAP)
23
+ assign(config, :iiif_drag_drop_link, settings.IIIF_DRAG_DROP_LINK)
24
+ assign(config, :homepage_map_geom, settings.HOMEPAGE_MAP_GEOM)
25
+ assign(config, :vector_download_formats, settings.DOWNLOAD_FORMATS&.VECTOR)
26
+ assign(config, :metadata_shown, settings.METADATA_SHOWN)
27
+ assign(config, :webservices_shown, settings.WEBSERVICES_SHOWN)
28
+ assign(config, :relationships_shown, build_relationships)
29
+ assign(config, :timeout_download, settings.TIMEOUT_DOWNLOAD)
30
+ assign(config, :download_path, settings.DOWNLOAD_PATH)
31
+ assign(config, :gbl_params, settings.GBL_PARAMS)
32
+ assign(config, :wms_params, settings.WMS_PARAMS&.to_h)
33
+ assign(config, :timeout_wms, settings.TIMEOUT_WMS)
34
+
35
+ build_fields(config)
36
+ build_leaflet_options(config)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :settings
43
+
44
+ # Assigns the value to the target's attribute unless it is nil, so that
45
+ # missing settings do not overwrite the defaults provided by Configuration.
46
+ def assign(target, attribute, value)
47
+ target.public_send("#{attribute}=", value) unless value.nil?
48
+ end
49
+
50
+ def build_display_notes
51
+ settings.DISPLAY_NOTES_SHOWN&.to_h&.transform_values do |value|
52
+ DisplayNoteShownConfig.new(value.to_h)
53
+ end
54
+ end
55
+
56
+ def build_relationships
57
+ RelationshipsConfig.new(settings.RELATIONSHIPS_SHOWN.to_h) if settings.RELATIONSHIPS_SHOWN
58
+ end
59
+
60
+ def build_leaflet_options(config)
61
+ return unless settings.LEAFLET
62
+
63
+ assign(config.leaflet_options, :bounds_overlay, settings.LEAFLET.BOUNDSOVERLAY&.to_h)
64
+ assign(config.leaflet_options, :selected_color, settings.LEAFLET.SELECTED_COLOR)
65
+ assign(config.leaflet_options, :sleep, settings.LEAFLET.SLEEP&.to_h&.transform_keys(&:downcase))
66
+ assign(config.leaflet_options, :sidebar, settings.LEAFLET.SIDEBAR)
67
+ assign(config.leaflet_options, :layers, settings.LEAFLET.LAYERS&.to_h&.transform_keys(&:downcase))
68
+ end
69
+
70
+ def build_fields(config)
71
+ return unless settings.FIELDS
72
+
73
+ assign(config.fields, :access_rights, settings.FIELDS.ACCESS_RIGHTS)
74
+ assign(config.fields, :alternative_title, settings.FIELDS.ALTERNATIVE_TITLE)
75
+ assign(config.fields, :centroid, settings.FIELDS.CENTROID)
76
+ assign(config.fields, :creator, settings.FIELDS.CREATOR)
77
+ assign(config.fields, :date_issued, settings.FIELDS.DATE_ISSUED)
78
+ assign(config.fields, :date_range, settings.FIELDS.DATE_RANGE)
79
+ assign(config.fields, :description, settings.FIELDS.DESCRIPTION)
80
+ assign(config.fields, :display_note, settings.FIELDS.DISPLAY_NOTE)
81
+ assign(config.fields, :format, settings.FIELDS.FORMAT)
82
+ assign(config.fields, :file_size, settings.FIELDS.FILE_SIZE)
83
+ assign(config.fields, :georeferenced, settings.FIELDS.GEOREFERENCED)
84
+ assign(config.fields, :id, settings.FIELDS.ID)
85
+ assign(config.fields, :identifier, settings.FIELDS.IDENTIFIER)
86
+ assign(config.fields, :index_year, settings.FIELDS.INDEX_YEAR)
87
+ assign(config.fields, :is_part_of, settings.FIELDS.IS_PART_OF)
88
+ assign(config.fields, :is_replaced_by, settings.FIELDS.IS_REPLACED_BY)
89
+ assign(config.fields, :theme, settings.FIELDS.THEME)
90
+ assign(config.fields, :keyword, settings.FIELDS.KEYWORD)
91
+ assign(config.fields, :language, settings.FIELDS.LANGUAGE)
92
+ assign(config.fields, :license, settings.FIELDS.LICENSE)
93
+ assign(config.fields, :member_of, settings.FIELDS.MEMBER_OF)
94
+ assign(config.fields, :metadata_version, settings.FIELDS.METADATA_VERSION)
95
+ assign(config.fields, :modified, settings.FIELDS.MODIFIED)
96
+ assign(config.fields, :overlap_field, settings.FIELDS.OVERLAP_FIELD)
97
+ assign(config.fields, :publisher, settings.FIELDS.PUBLISHER)
98
+ assign(config.fields, :provider, settings.FIELDS.PROVIDER)
99
+ assign(config.fields, :references, settings.FIELDS.REFERENCES)
100
+ assign(config.fields, :relation, settings.FIELDS.RELATION)
101
+ assign(config.fields, :replaces, settings.FIELDS.REPLACES)
102
+ assign(config.fields, :resource_class, settings.FIELDS.RESOURCE_CLASS)
103
+ assign(config.fields, :resource_type, settings.FIELDS.RESOURCE_TYPE)
104
+ assign(config.fields, :rights, settings.FIELDS.RIGHTS)
105
+ assign(config.fields, :rights_holder, settings.FIELDS.RIGHTS_HOLDER)
106
+ assign(config.fields, :source, settings.FIELDS.SOURCE)
107
+ assign(config.fields, :spatial_coverage, settings.FIELDS.SPATIAL_COVERAGE)
108
+ assign(config.fields, :geometry, settings.FIELDS.GEOMETRY)
109
+ assign(config.fields, :subject, settings.FIELDS.SUBJECT)
110
+ assign(config.fields, :suppressed, settings.FIELDS.SUPPRESSED)
111
+ assign(config.fields, :temporal_coverage, settings.FIELDS.TEMPORAL_COVERAGE)
112
+ assign(config.fields, :title, settings.FIELDS.TITLE)
113
+ assign(config.fields, :version, settings.FIELDS.VERSION)
114
+ assign(config.fields, :wxs_identifier, settings.FIELDS.WXS_IDENTIFIER)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -54,13 +54,14 @@ module Geoblacklight
54
54
  attr_accessor :webservices_shown # typed as Array
55
55
 
56
56
  # Relationships to display
57
- attr_accessor :relationships_shown # typed as Hash
57
+ attr_accessor :relationships_shown # typed as RelationshipsConfig
58
58
 
59
59
  attribute :download_path, :string
60
60
 
61
61
  def initialize
62
62
  super
63
63
  self.download_path ||= Rails.root.join("tmp", "cache", "downloads")
64
+ @relationships_shown = RelationshipsConfig.new
64
65
  @gbl_params = [
65
66
  :bbox, :email, :file, :format, :id, :logo, :provider, :type,
66
67
  :BBOX, :HEIGHT, :LAYERS, :QUERY_LAYERS, :URL, :WIDTH, :X, :Y
@@ -94,6 +95,8 @@ module Geoblacklight
94
95
  ]
95
96
  }
96
97
 
98
+ @vector_download_formats = ["Shapefile", "KMZ", "GeoJSON", "CSV"]
99
+ @metadata_shown = ["mods", "fgdc", "iso19139", "html"]
97
100
  @webservices_shown = %w[
98
101
  wms
99
102
  tms
@@ -107,7 +110,7 @@ module Geoblacklight
107
110
  dynamic_map_layer
108
111
  image_map_layer
109
112
  cog
110
- pmtile
113
+ pmtiles
111
114
  ]
112
115
 
113
116
  @display_notes_shown = {
@@ -132,6 +135,8 @@ module Geoblacklight
132
135
  note_prefix: "Warning: "
133
136
  )
134
137
  }
138
+
139
+ @sidebar_static_map = ["iiif", "iiif_manifest"]
135
140
  end
136
141
 
137
142
  def fields
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/deprecation"
4
+
5
+ module Geoblacklight
6
+ Deprecation = ActiveSupport::Deprecation.new("7.0", "GeoBlacklight")
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Geoblacklight
4
- VERSION = "6.0.0-alpha.1"
4
+ VERSION = "6.0.0-alpha.2"
5
5
  end
data/lib/geoblacklight.rb CHANGED
@@ -14,7 +14,7 @@ module Geoblacklight
14
14
  ::Rails.logger
15
15
  end
16
16
 
17
- mattr_accessor :configuration_builder, default: Geoblacklight::Configuration::LegacySettingsBuilder
17
+ mattr_accessor :configuration_builder, default: Geoblacklight::Configuration::SettingsBuilder
18
18
 
19
19
  def self.configuration
20
20
  @configuration ||= configuration_builder.build
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Geoblacklight::Document::SidebarComponent, type: :component do
6
+ subject(:component) { described_class.new(presenter: presenter) }
7
+
8
+ let(:view_context) { vc_test_controller.view_context }
9
+ let(:presenter) { view_context.document_presenter(document) }
10
+ let(:document) { SolrDocument.new(JSON.parse(read_fixture(fixture))) }
11
+
12
+ before do
13
+ allow_any_instance_of(Geoblacklight::DownloadLinksComponent).to receive(:render?).and_return(false)
14
+ allow_any_instance_of(Geoblacklight::LoginLinkComponent).to receive(:render?).and_return(false)
15
+
16
+ allow(document).to receive(:more_like_this).and_return([])
17
+ allow_any_instance_of(Blacklight::DocumentHelperBehavior).to receive(:current_bookmarks).and_return([])
18
+
19
+ with_controller_class(CatalogController) do
20
+ allow(vc_test_controller).to receive_messages(current_or_guest_user: User.new)
21
+ render_inline(component)
22
+ end
23
+ end
24
+
25
+ context "when the document viewer protocol is IIIF" do
26
+ let(:fixture) { "solr_documents/public_iiif_princeton.json" }
27
+
28
+ it "renders the static map" do
29
+ expect(page).to have_css("#static-map")
30
+ end
31
+
32
+ it "renders the Location label" do
33
+ expect(page).to have_content("Location")
34
+ end
35
+ end
36
+
37
+ context "when the document viewer protocol is WMS" do
38
+ let(:fixture) { "solr_documents/restricted-line.json" }
39
+
40
+ it "does not render the static map" do
41
+ expect(page).to have_no_css("#static-map")
42
+ end
43
+
44
+ it "does not render the Location label" do
45
+ expect(page).to have_no_content("Location")
46
+ end
47
+ end
48
+ end
@@ -7,7 +7,7 @@ RSpec.describe Geoblacklight::LoginLinkComponent, type: :component do
7
7
 
8
8
  context "when rendering is required" do
9
9
  before do
10
- allow_any_instance_of(GeoblacklightHelper).to receive(:document_available?).and_return(false)
10
+ allow(vc_test_controller).to receive(:user_signed_in?).and_return(false)
11
11
  allow(document).to receive(:restricted?).and_return(true)
12
12
  allow(document).to receive(:same_institution?).and_return(true)
13
13
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Geoblacklight::Configuration::LayerConfig do
6
+ subject(:config) { described_class.new(attributes) }
7
+
8
+ let(:attributes) { {} }
9
+
10
+ describe "defaults" do
11
+ it "has weight defaulting to 1" do
12
+ expect(config.weight).to eq(1)
13
+ end
14
+
15
+ it "has radius defaulting to 4" do
16
+ expect(config.radius).to eq(4)
17
+ end
18
+
19
+ it "has color defaulting to nil" do
20
+ expect(config.color).to be_nil
21
+ end
22
+
23
+ it "has sr_color_name defaulting to nil" do
24
+ expect(config.sr_color_name).to be_nil
25
+ end
26
+ end
27
+
28
+ describe "with attributes" do
29
+ let(:attributes) { {color: "#FF0000", sr_color_name: "Red", weight: 2, radius: 5} }
30
+
31
+ it "sets the passed-in attributes" do
32
+ expect(config.color).to eq("#FF0000")
33
+ expect(config.sr_color_name).to eq("Red")
34
+ expect(config.weight).to eq(2)
35
+ expect(config.radius).to eq(5)
36
+ end
37
+ end
38
+
39
+ describe "hash-like access []" do
40
+ let(:attributes) { {color: "#00FF00", sr_color_name: "Green"} }
41
+
42
+ it "supports key lookup with symbols" do
43
+ expect(config[:color]).to eq("#00FF00")
44
+ expect(config[:weight]).to eq(1)
45
+ expect(config[:sr_color_name]).to eq("Green")
46
+ end
47
+
48
+ it "supports key lookup with strings" do
49
+ expect(config["color"]).to eq("#00FF00")
50
+ expect(config["weight"]).to eq(1)
51
+ expect(config["sr_color_name"]).to eq("Green")
52
+ end
53
+
54
+ it "returns nil for non-existent attributes" do
55
+ expect(config[:foo]).to be_nil
56
+ end
57
+ end
58
+
59
+ describe "#to_h" do
60
+ let(:attributes) { {color: "#FFFF00", sr_color_name: "Yellow"} }
61
+
62
+ it "returns symbolized attributes hash" do
63
+ expect(config.to_h).to eq(
64
+ color: "#FFFF00",
65
+ weight: 1,
66
+ radius: 4,
67
+ sr_color_name: "Yellow"
68
+ )
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Geoblacklight::Configuration::LeafletLayersConfig do
6
+ subject(:config) { described_class.new(attributes) }
7
+
8
+ let(:attributes) do
9
+ {
10
+ detect_retina: true,
11
+ index: {
12
+ DEFAULT: {
13
+ color: "#7FCDBB",
14
+ sr_color_name: "Green"
15
+ },
16
+ UNAVAILABLE: Geoblacklight::Configuration::LayerConfig.new(
17
+ color: "#EDF8B1",
18
+ sr_color_name: "Yellow"
19
+ )
20
+ }
21
+ }
22
+ end
23
+
24
+ describe "initialization" do
25
+ it "sets detect_retina attribute" do
26
+ expect(config.detect_retina).to be(true)
27
+ end
28
+
29
+ it "converts hash elements under index to LayerConfig instances" do
30
+ expect(config.index[:DEFAULT]).to be_a(Geoblacklight::Configuration::LayerConfig)
31
+ expect(config.index[:DEFAULT].color).to eq("#7FCDBB")
32
+ expect(config.index[:DEFAULT].weight).to eq(1) # Uses default weight from LayerConfig
33
+ end
34
+
35
+ it "keeps existing LayerConfig instances under index" do
36
+ expect(config.index[:UNAVAILABLE]).to be_a(Geoblacklight::Configuration::LayerConfig)
37
+ expect(config.index[:UNAVAILABLE].color).to eq("#EDF8B1")
38
+ expect(config.index[:UNAVAILABLE].weight).to eq(1) # Uses default weight from LayerConfig
39
+ end
40
+ end
41
+
42
+ describe "#to_h" do
43
+ it "serializes index to a hash of hashes" do
44
+ expect(config.to_h).to eq(
45
+ "detect_retina" => true,
46
+ "index" => {
47
+ DEFAULT: {
48
+ color: "#7FCDBB",
49
+ weight: 1,
50
+ radius: 4,
51
+ sr_color_name: "Green"
52
+ },
53
+ UNAVAILABLE: {
54
+ color: "#EDF8B1",
55
+ weight: 1,
56
+ radius: 4,
57
+ sr_color_name: "Yellow"
58
+ }
59
+ }
60
+ )
61
+ end
62
+ end
63
+ end