Skip to content

Commit 366f5f4

Browse files
committed
Support locale for snippets
1 parent 0c724fb commit 366f5f4

4 files changed

Lines changed: 9 additions & 8 deletions

File tree

engines/block_preview/app/controllers/block_preview/preview_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def show
1717
host_content_id,
1818
state: params[:state].presence || "published",
1919
block: @block,
20+
locale: params[:locale],
2021
)
2122

2223
if @current_tab == "preview"

engines/block_preview/app/model/block_preview/snippet.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class BlockPreview::Snippet
22
class << self
3-
def for_content_id(content_id, state:, block:)
3+
def for_content_id(content_id, state:, block:, locale:)
44
diff = BlockPreview::ContentDiff.new(
5-
html_snippet(content_id, state),
5+
html_snippet(content_id, state, locale),
66
block,
77
)
88
from_html(diff.to_s, block)
@@ -30,8 +30,8 @@ def from_html(html, block)
3030

3131
private
3232

33-
def html_snippet(content_id, state)
34-
publishing_api_response = Public::Services.publishing_api.get_content(content_id)
33+
def html_snippet(content_id, state, locale)
34+
publishing_api_response = Public::Services.publishing_api.get_content(content_id, locale:)
3535
content_store = state == "published" ? Public::Services.content_store : Public::Services.draft_content_store
3636
content_store_response = content_store.content_item(publishing_api_response["base_path"])
3737
html = if %w[guide travel_advice].include?(content_store_response["document_type"])

engines/block_preview/spec/unit/app/controllers/preview_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
end
9595

9696
it "extracts snippets from the preview html" do
97-
expect(BlockPreview::Snippet).to have_received(:for_content_id).with(host_content_id, state: state, block: mock_block)
97+
expect(BlockPreview::Snippet).to have_received(:for_content_id).with(host_content_id, state: state, block: mock_block, locale: locale)
9898
end
9999

100100
it "assigns the current tab" do

engines/block_preview/spec/unit/app/models/snippet_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
before do
1313
allow(Public::Services.publishing_api).to receive(:get_content)
14-
.with(content_id)
14+
.with(content_id, locale: "en")
1515
.and_return(publishing_api_response)
1616
allow(described_class).to receive(:from_html).with(diff_output, block).and_return(snippets)
1717
allow(BlockPreview::ContentDiff).to receive(:new).and_return(diff)
@@ -32,7 +32,7 @@
3232
expect(received_block).to be(block)
3333
}.and_return(diff)
3434

35-
expect(described_class.for_content_id(content_id, state: "published", block:)).to eq(snippets)
35+
expect(described_class.for_content_id(content_id, state: "published", block:, locale: "en")).to eq(snippets)
3636
end
3737

3838
it "fetches draft content from the draft store and joins guide parts into a single fragment" do
@@ -55,7 +55,7 @@
5555
expect(html_fragment.to_html).to include("<p>Part two</p>")
5656
}.and_return(diff)
5757

58-
described_class.for_content_id(content_id, state: "draft", block:)
58+
described_class.for_content_id(content_id, state: "draft", block:, locale: "en")
5959
end
6060
end
6161

0 commit comments

Comments
 (0)