Skip to content

Commit

Permalink
Update integration test for JS scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtrussler committed Jan 9, 2025
1 parent 4e7e002 commit 61b158b
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/integration/edition_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,81 @@ class EditionEditTest < IntegrationTest
end
end

with_javascript do
context "Related external links tab (with JavaScript)" do
setup do
visit_draft_edition
click_link "Related external links"
end

should "render an empty 'Add another' form when the page loads" do
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?("button", text: "Add another link")
end

should "render a pre-populated 'Add another' form when the user adds values to the form and saves" do
fill_in "Title", with: "Link one"
fill_in "URL", with: "https://one.com"
click_button("Save")

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 "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")
end

should "display 'Delete' buttons and a second set of inputs when 'Add another link' is clicked" do
click_button("Add another 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: "Delete")
end
end

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

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

assert page.has_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
end
end
end

private

def visit_draft_edition
Expand Down

0 comments on commit 61b158b

Please sign in to comment.