Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump Content Block Tools 0.4.2 #9910

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
content_block_tools (0.3.1)
content_block_tools (0.4.2)
actionview (>= 6)
crack (1.0.0)
bigdecimal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ def update_document_reference_to_latest_edition!
document.update!(latest_edition_id: id)
end

def render
def render(embed_code)
ContentBlockTools::ContentBlock.new(
document_type: "content_block_#{block_type}",
content_id: document.content_id,
title:,
details:,
embed_code:,
).render
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def call
content_block = content_blocks.find { |c| c.document.content_id == reference.content_id }
next if content_block.nil?

html.gsub!(reference.embed_code, content_block.render)
html.gsub!(reference.embed_code, content_block.render(reference.embed_code))
end

html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def replace_existing_content_blocks(nokogiri_html)

def replace_blocks(nokogiri_html)
content_block_spans(nokogiri_html).each do |span|
span.replace content_block_edition.render
embed_code = span["data-embed-code"]
span.replace content_block_edition.render(embed_code)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
When("I click on the first host document") do
@current_host_document = @dependent_content.first
embed_code = "{{embed:#{@current_host_document['block_type']}:#{@current_host_document['content_id']}}}"

stub_request(
:get,
"#{Plek.find('publishing-api')}/v2/content/#{@current_host_document['host_content_id']}",
Expand All @@ -21,15 +23,15 @@
Plek.website_root + @current_host_document["base_path"],
).to_return(
status: 200,
body: "<body><h1>#{@current_host_document['title']}</h1><p>iframe preview <a href=\"/other-page\">Link to other page</a></p>#{@content_block.render}</body>",
body: "<body><h1>#{@current_host_document['title']}</h1><p>iframe preview <a href=\"/other-page\">Link to other page</a></p>#{@content_block.render(embed_code)}</body>",
)

stub_request(
:get,
"#{Plek.website_root}/other-page",
).to_return(
status: 200,
body: "<body><h1>#{@current_host_document['title']}</h1><p>other page</p>#{@content_block.render}</body>",
body: "<body><h1>#{@current_host_document['title']}</h1><p>other page</p>#{@content_block.render(embed_code)}</body>",
)

click_on @current_host_document["title"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class ContentBlockManager::ContentBlockEditionTest < ActiveSupport::TestCase
let(:rendered_response) { "RENDERED" }
let(:stub_block) { stub("ContentBlockTools::ContentBlock", render: rendered_response) }
let(:document) { content_block_edition.document }
let(:embed_code) { "embed_code" }

it "initializes and renders a content block" do
ContentBlockTools::ContentBlock.expects(:new)
Expand All @@ -186,9 +187,10 @@ class ContentBlockManager::ContentBlockEditionTest < ActiveSupport::TestCase
content_id: document.content_id,
title:,
details:,
embed_code:,
).returns(stub_block)

assert_equal content_block_edition.render, rendered_response
assert_equal content_block_edition.render(embed_code), rendered_response
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ContentBlockManager::FindAndReplaceEmbedCodesServiceTest < ActiveSupport::

expected = "
<p>Hello there</p>
<p>#{edition_2.render}</p>
<p>#{edition_1.render}</p>
<p>#{edition_2.render(edition_2.document.embed_code)}</p>
<p>#{edition_1.render(edition_1.document.embed_code)}</p>
"

result = ContentBlockManager::FindAndReplaceEmbedCodesService.call(html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class ContentBlockManager::GeneratePreviewHtmlTest < ActiveSupport::TestCase
let(:host_base_path) { "/test" }
let(:uri_mock) { mock }
let(:fake_frontend_response) do
"<body class=\"govuk-body\"><p>test</p><span class=\"content-embed content-embed__content_block_email_address\" data-content-block=\"\" data-document-type=\"content_block_email_address\" data-content-id=\"#{preview_content_id}\">[email protected]</span></body>"
"<body class=\"govuk-body\"><p>test</p><span class=\"content-embed content-embed__content_block_email_address\" data-content-block=\"\" data-document-type=\"content_block_email_address\" data-embed-code=\"embed-code\" data-content-id=\"#{preview_content_id}\">[email protected]</span></body>"
end
let(:block_render) do
"<span class=\"content-embed content-embed__content_block_email_address\" data-content-block=\"\" data-document-type=\"content_block_email_address\" data-content-id=\"#{preview_content_id}\">[email protected]</span>"
"<span class=\"content-embed content-embed__content_block_email_address\" data-content-block=\"\" data-document-type=\"content_block_email_address\" data-embed-code=\"embed-code\" data-content-id=\"#{preview_content_id}\">[email protected]</span>"
end
let(:block_render_with_style) do
"<span class=\"content-embed content-embed__content_block_email_address\" data-content-block=\"\" data-document-type=\"content_block_email_address\" data-content-id=\"#{preview_content_id}\" style=\"background-color: yellow;\">[email protected]</span>"
"<span class=\"content-embed content-embed__content_block_email_address\" data-content-block=\"\" data-document-type=\"content_block_email_address\" data-content-id=\"#{preview_content_id}\" data-embed-code=\"embed-code\" style=\"background-color: yellow;\">[email protected]</span>"
end
let(:expected_html) do
"<body class=\"govuk-body draft\"><p>test</p>#{block_render_with_style}</body>"
Expand Down
Loading