Skip to content

Commit

Permalink
Add show_finder_link? method to SpecialistPublisherPresenter
Browse files Browse the repository at this point in the history
  • Loading branch information
leenagupte committed Jan 17, 2025
1 parent 5f00ccf commit fa1dd42
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/specialist_document.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class SpecialistDocument < ContentItem
attr_reader :continuation_link, :headers, :will_continue_on
attr_reader :continuation_link, :finder, :headers, :will_continue_on

def initialize(content_store_response)
super(content_store_response)

@continuation_link = content_store_hash.dig("details", "metadata", "continuation_link")
@finder = content_store_hash.dig("links", "finder", 0)
@will_continue_on = content_store_hash.dig("details", "metadata", "will_continue_on")

@headers = headers_list(content_store_hash.dig("details", "headers"))
Expand Down
8 changes: 8 additions & 0 deletions app/presenters/specialist_document_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ def show_contents_list?
content_item.headers.present? && level_two_headings?
end

def show_finder_link?
content_item.finder.present? && statutory_instrument?
end

private

def level_two_headings?
content_item.headers.any? { |header| header[:level] == 2 }
end

def statutory_instrument?
content_item.document_type == "statutory_instrument"
end
end
16 changes: 16 additions & 0 deletions spec/presenter/specialist_document_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,20 @@
expect(described_class.new(content_item).show_contents_list?).to be true
end
end

describe "#show_finder_link?" do
it "returns true when document type is statutory instrument" do
content_store_response = GovukSchemas::Example.find("specialist_document", example_name: "eu-withdrawal-act-2018-statutory-instruments")
content_item = SpecialistDocument.new(content_store_response)

expect(described_class.new(content_item).show_finder_link?).to be true
end

it "returns false when document type is not a statutory instrument" do
content_store_response = GovukSchemas::Example.find("specialist_document", example_name: "aaib-reports")
content_item = SpecialistDocument.new(content_store_response)

expect(described_class.new(content_item).show_finder_link?).to be false
end
end
end

0 comments on commit fa1dd42

Please sign in to comment.