Skip to content

Commit

Permalink
Add data attributes to summary cards
Browse files Browse the repository at this point in the history
Also adds cucumber tests
  • Loading branch information
pezholio committed Nov 6, 2024
1 parent afe1120 commit 50a32f9
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render "components/summary_card", {
<%= render "govuk_publishing_components/components/summary_card", {
title:,
rows:,
summary_card_actions:,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def rows
{
key: item[:field],
value: item[:value],
data: item[:data],
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def embed_code_item
{
field: "Embed code",
value: content_block_document.embed_code,
data: {
module: "copy-embed-code",
"embed-code": content_block_document.embed_code,
},
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Feature: Search for a content object
| title | ministry address |
| email_address | ministry@example.com |
| organisation | Ministry of Example |

Scenario: GDS Editor can filter by organisation
When I visit the Content Block Manager home page
Then my organisation is already selected as a filter
And I should see the details for all documents from my organisation
Expand All @@ -28,23 +30,36 @@ Feature: Search for a content object
Then "3" content blocks are returned

Scenario: GDS Editor searches for a content object by keyword in title
When I enter the keyword "example search"
When I visit the Content Block Manager home page
And I enter the keyword "example search"
And I click to view results
Then I should see the content block with title "example search title" returned
And "1" content blocks are returned

Scenario: GDS Editor searches for a content object by keyword in details
When I enter the keyword "ABC123"
When I visit the Content Block Manager home page
And I enter the keyword "ABC123"
And I click to view results
Then I should see the content block with title "an address" returned
And "1" content blocks are returned

Scenario: GDS Editor searches for a content object by block type
When I check the block type "Email address"
When I visit the Content Block Manager home page
And I select the lead organisation "All organisations"
And I check the block type "Email address"
And I click to view results
And "2" content blocks are returned

Scenario: GDS Editor searches for a content object by lead organisation
When I select the lead organisation "Ministry of Example"
When I visit the Content Block Manager home page
And I select the lead organisation "Ministry of Example"
And I click to view results
And "1" content blocks are returned

@javascript
Scenario: GDS Editor can copy embed code
When I visit the Content Block Manager home page
And I select the lead organisation "Ministry of Example"
And I click to view results
And I click to copy the embed code for the content block "ministry address"
Then the embed code should be copied to my clipboard
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,24 @@ def click_save_and_continue
Then("I should see the content block manager home page") do
expect(page).to have_content("All content blocks")
end

When("I click to copy the embed code") do
find("a", text: "Copy code").click
has_text?("Code copied")
@embed_code = @content_block.document.embed_code
end

When("I click to copy the embed code for the content block {string}") do |content_block_name|
within(".govuk-summary-card", text: content_block_name) do
find("a", text: "Copy code").click
has_text?("Code copied")
document = ContentBlockManager::ContentBlock::Document.find_by(title: content_block_name)
@embed_code = document.embed_code
end
end

Then("the embed code should be copied to my clipboard") do
page.driver.browser.execute_cdp("Browser.grantPermissions", origin: page.server_url, permissions: %w[clipboardReadWrite])
clip_text = page.evaluate_async_script("navigator.clipboard.readText().then(arguments[0])")
expect(clip_text).to eq(@embed_code)
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ Feature: View a content object
And I click to view the document
Then I should see the dependent content listed

@javascript
Scenario: GDS Editor can copy embed code
When I visit the Content Block Manager home page
Then I should see the details for all documents
When I click to view the document
And I click to copy the embed code
Then the embed code should be copied to my clipboard

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class ContentBlockManager::ContentBlock::Document::Index::SummaryCardComponentTe
assert_selector ".govuk-summary-list__key", text: "Creator"
assert_selector ".govuk-summary-list__value", text: content_block_edition.creator.name

assert_selector ".govuk-summary-list__row[data-module='copy-embed-code']", text: "Embed code"
assert_selector ".govuk-summary-list__row[data-embed-code='#{content_block_document.embed_code}']", text: "Embed code"
assert_selector ".govuk-summary-list__key", text: "Embed code"
assert_selector ".govuk-summary-list__value", text: content_block_document.embed_code

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ContentBlockManager::ContentBlock::Document::Show::SummaryListComponentTes
assert_selector ".govuk-summary-list__key", text: "Creator"
assert_selector ".govuk-summary-list__value", text: content_block_edition.creator.name

assert_selector ".govuk-summary-list__row[data-module='copy-embed-code']", text: "Embed code"
assert_selector ".govuk-summary-list__row[data-embed-code='#{content_block_document.embed_code}']", text: "Embed code"
assert_selector ".govuk-summary-list__key", text: "Embed code"
assert_selector ".govuk-summary-list__value", text: content_block_document.embed_code

Expand Down

0 comments on commit 50a32f9

Please sign in to comment.