Skip to content

Commit

Permalink
Serving configs: Add Finder Frontend preview
Browse files Browse the repository at this point in the history
This allows users to preview the results from a serving config on Finder
Frontend using the `debug_serving_config` parameter.
  • Loading branch information
csutter committed Feb 12, 2025
1 parent e57333e commit 2717204
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/serving_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ class ServingConfig < ApplicationRecord

validates :display_name, presence: true
validates :remote_resource_id, presence: true, uniqueness: true

# A URL to preview this serving config on Finder Frontend
def preview_url
FinderFrontendSearch.new(
keywords: "example search",
debug_serving_config: remote_resource_id,
).url
end
end
10 changes: 10 additions & 0 deletions app/views/serving_configs/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
title: @serving_config.display_name,
} %>

<div class="actions">
<%= render "govuk_publishing_components/components/button", {
text: t(".buttons.preview"),
href: @serving_config.preview_url,
target: "_blank",
secondary_quiet: true,
inline_layout: true
} %>
</div>

<%= render "govuk_publishing_components/components/summary_list", {
items: [
{
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,6 @@ en:
serving_configs:
index:
page_title: Serving configs
show:
buttons:
preview: Preview on GOV.UK
18 changes: 18 additions & 0 deletions spec/models/serving_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,22 @@
)
end
end

describe "#preview_url" do
subject(:serving_config) { create(:serving_config, remote_resource_id: "hello") }

let(:finder_frontend_search) do
instance_double(FinderFrontendSearch, url: "https://example.org")
end

before do
allow(FinderFrontendSearch).to receive(:new)
.with(keywords: "example search", debug_serving_config: "hello")
.and_return(finder_frontend_search)
end

it "returns the preview URL" do
expect(serving_config.preview_url).to eq("https://example.org")
end
end
end

0 comments on commit 2717204

Please sign in to comment.