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

497 use updated add another component #2520

Merged
merged 1 commit into from
Jan 29, 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 @@ -256,7 +256,7 @@ GEM
govuk_personalisation (1.1.0)
plek (>= 1.9.0)
rails (>= 6, < 9)
govuk_publishing_components (50.0.1)
govuk_publishing_components (51.0.0)
govuk_app_config
govuk_personalisation (>= 0.7.0)
kramdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
<%= form_for @edition.artefact, url: update_related_external_links_edition_path(@resource) do %>
<%
if @edition.artefact.external_links.count == 0
items = [{
fields: render(partial: "secondary_nav_tabs/related_external_links/add-another_fieldset", locals: { index: 0, id: nil }),
destroy_checkbox: render(partial: "secondary_nav_tabs/related_external_links/add-another_checkbox", locals: {index: 0}),
}]
empty = render(partial: "secondary_nav_tabs/related_external_links/add-another_fieldset", locals: { index: 1, id: nil })
items = []
empty = render(partial: "secondary_nav_tabs/related_external_links/add-another_fieldset", locals: { index: 0, id: nil })
else
items = @edition.artefact.external_links.each_with_index.map do | external_link, index |
{
Expand All @@ -23,7 +20,8 @@

<%= render "govuk_publishing_components/components/add_another", {
fieldset_legend: "Link",
add_button_text: "Add another link",
add_button_text: "Add related external link",
empty_fields: true,
items: items,
empty: empty,
} %>
Expand Down
20 changes: 1 addition & 19 deletions test/integration/edition_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -604,20 +604,11 @@ class EditionEditTest < IntegrationTest
end

should "render an empty 'Add another' form" do
# Link 1
assert page.has_css?("legend", text: "Link 1")
assert page.has_css?("input[name='artefact[external_links_attributes][0][_destroy]']")
assert_equal "Title", page.find("label[for='artefact_external_links_attributes_0_title']").text
assert_equal "URL", page.find("label[for='artefact_external_links_attributes_0_url']").text
assert_equal "", page.find("input[name='artefact[external_links_attributes][0][title]']").value
assert_equal "", page.find("input[name='artefact[external_links_attributes][0][url]']").value

# Link 2 (empty fields)
assert page.has_css?("legend", text: "Link 2")
assert_equal "Title", page.find("label[for='artefact_external_links_attributes_1_title']").text
assert_equal "URL", page.find("label[for='artefact_external_links_attributes_1_url']").text
assert_equal "", page.find("input[name='artefact[external_links_attributes][1][title]']").value
assert_equal "", page.find("input[name='artefact[external_links_attributes][1][url]']").value
end
end

Expand Down Expand Up @@ -653,7 +644,7 @@ class EditionEditTest < IntegrationTest
end

should "render a pre-populated 'Add another' form" do
within :css, ".gem-c-add-another .js-add-another__fieldset:first-of-type" do
within :css, ".gem-c-add-another .js-add-another__empty" do
fill_in "Title", with: "A new external link"
fill_in "URL", with: "https://foo.com"
end
Expand Down Expand Up @@ -691,20 +682,11 @@ class EditionEditTest < IntegrationTest

click_button("Save")

# Link 1
assert page.has_css?("legend", text: "Link 1")
assert page.has_css?("input[name='artefact[external_links_attributes][0][_destroy]']")
assert_equal "Title", page.find("label[for='artefact_external_links_attributes_0_title']").text
assert_equal "URL", page.find("label[for='artefact_external_links_attributes_0_url']").text
assert_equal "", page.find("input[name='artefact[external_links_attributes][0][title]']").value
assert_equal "", page.find("input[name='artefact[external_links_attributes][0][url]']").value

# Link 2
assert page.has_css?("legend", text: "Link 2")
assert_equal "Title", page.find("label[for='artefact_external_links_attributes_1_title']").text
assert_equal "URL", page.find("label[for='artefact_external_links_attributes_1_url']").text
assert_equal "", page.find("input[name='artefact[external_links_attributes][1][title]']").value
assert_equal "", page.find("input[name='artefact[external_links_attributes][1][url]']").value
end
end
end
Expand Down
50 changes: 19 additions & 31 deletions test/integration/edition_external_links_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class EditionExternalLinksTest < JavascriptIntegrationTest
end

context "Edition does not already have related external links" do
should "render an empty 'Add another' form when the page loads" do
assert page.has_css?("legend", text: "Link 1")
should "render the form containing just the 'Add related external link' button when the page loads" do
assert page.has_no_css?("legend", text: "Link 1")
assert page.has_no_css?("input[name='artefact[external_links_attributes][0][_destroy]']")
assert_equal "Title", page.find("label[for='artefact_external_links_attributes_0_title']").text
assert_equal "URL", page.find("label[for='artefact_external_links_attributes_0_url']").text
assert_equal "", page.find("input[name='artefact[external_links_attributes][0][title]']").value
assert_equal "", page.find("input[name='artefact[external_links_attributes][0][url]']").value
assert page.has_css?("button", text: "Add another link")
assert page.has_no_css?("label[for='artefact_external_links_attributes_0_title']")
assert page.has_no_css?("label[for='artefact_external_links_attributes_0_url']")
assert page.has_no_css?("input[name='artefact[external_links_attributes][0][title]']")
assert page.has_no_css?("input[name='artefact[external_links_attributes][0][url]']")
assert page.has_css?("button", text: "Add related external link")
end
end

Expand All @@ -46,50 +46,38 @@ class EditionExternalLinksTest < JavascriptIntegrationTest
assert_equal "URL", page.find("label[for='artefact_external_links_attributes_0_url']").text
assert_equal "Link one", page.find("input[name='artefact[external_links_attributes][0][title]']").value
assert_equal "https://one.com", page.find("input[name='artefact[external_links_attributes][0][url]']").value
assert page.has_css?("button", text: "Add another link")
assert page.has_css?("button", text: "Add related external link")
end
end

should "display 'Delete' buttons and a second set of inputs when 'Add another link' is clicked" do
click_button("Add another link")
should "display a 'Delete' button and a set of inputs when the Add button is clicked" do
click_button("Add related external link")

assert page.has_css?("legend", text: "Link 1")
assert page.has_no_css?("input[name='artefact[external_links_attributes][0][_destroy]']")
assert_equal "Title", page.find("label[for='artefact_external_links_attributes_0_title']").text
assert_equal "URL", page.find("label[for='artefact_external_links_attributes_0_url']").text
assert_equal "", page.find("input[name='artefact[external_links_attributes][0][title]']").value
assert_equal "", page.find("input[name='artefact[external_links_attributes][0][url]']").value
assert page.has_css?("legend", text: "Link 2")
assert page.has_no_css?("input[name='artefact[external_links_attributes][1][_destroy]']")
assert_equal "Title", page.find("label[for='artefact_external_links_attributes_1_title']").text
assert_equal "URL", page.find("label[for='artefact_external_links_attributes_1_url']").text
assert_equal "", page.find("input[name='artefact[external_links_attributes][1][title]']").value
assert_equal "", page.find("input[name='artefact[external_links_attributes][1][url]']").value
assert page.has_css?("button", text: "Add another link")
within :css, ".gem-c-add-another .js-add-another__fieldset:nth-of-type(1)" do
assert page.has_css?("button", text: "Delete")
end
within :css, ".gem-c-add-another .js-add-another__fieldset:nth-of-type(2)" do
assert page.has_css?("button", text: "Add related external link")
within :css, ".gem-c-add-another .js-add-another__fieldset" do
assert page.has_css?("button", text: "Delete")
end
end

should "delete the first set of fields when the user clicks the first “Delete button" do
click_button("Add another link")
should "delete the set of fields when the user clicks the 'Delete' button" do
click_button("Add related external link")

within :css, ".gem-c-add-another .js-add-another__fieldset:nth-of-type(1)" do
within :css, ".gem-c-add-another .js-add-another__fieldset" do
click_button("Delete")
end

assert page.has_css?("legend", text: "Link 1")
assert page.has_no_css?("legend", text: "Link 1")
assert page.has_no_css?("label[for='artefact_external_links_attributes_0_title']")
assert page.has_no_css?("label[for='artefact_external_links_attributes_0_url']")
assert_equal "Title", page.find("label[for='artefact_external_links_attributes_1_title']").text
assert_equal "URL", page.find("label[for='artefact_external_links_attributes_1_url']").text
assert page.has_css?("button", text: "Add another link")
within :css, ".gem-c-add-another .js-add-another__fieldset:nth-of-type(2)" do
assert page.has_css?("button", text: "Delete")
end
assert page.has_no_css?("label[for='artefact_external_links_attributes_1_title']")
assert page.has_no_css?("label[for='artefact_external_links_attributes_1_url']")
assert page.has_css?("button", text: "Add related external link")
end
end

Expand Down