From cb4001cf2e946cb1e5b1f445f4dc623aa3e7b9fa Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Wed, 26 Feb 2025 10:34:50 +0200 Subject: [PATCH] Add page IDs to summary list rows for page summary component We already have IDs for each summary list row for a condition, this commit adds IDs for each summary list row for a page. This will be useful for automation tools such as our end to end tests. --- app/components/page_list_component/view.html.erb | 2 +- app/components/page_list_component/view.rb | 4 ++++ spec/components/page_list_component/view_spec.rb | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/components/page_list_component/view.html.erb b/app/components/page_list_component/view.html.erb index 9d65b3631..3bff51665 100644 --- a/app/components/page_list_component/view.html.erb +++ b/app/components/page_list_component/view.html.erb @@ -4,7 +4,7 @@ <%= form_with url: move_page_url(@form_id), method: :post, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<% @pages.each_with_index do |page, index| %> -
+
<%= page.position %> diff --git a/app/components/page_list_component/view.rb b/app/components/page_list_component/view.rb index ede5bd66c..a1d62447d 100644 --- a/app/components/page_list_component/view.rb +++ b/app/components/page_list_component/view.rb @@ -16,6 +16,10 @@ def show_down_button(index) index != @pages.length - 1 end + def page_row_id(record) + "page_#{record.id}" + end + def condition_description(condition) if condition.secondary_skip? I18n.t("page_conditions.secondary_skip_description", check_page_text: skip_condition_route_page_text(condition), goto_page_text: goto_page_text_for_condition(condition)) diff --git a/spec/components/page_list_component/view_spec.rb b/spec/components/page_list_component/view_spec.rb index c4345b0bb..fc96d9804 100644 --- a/spec/components/page_list_component/view_spec.rb +++ b/spec/components/page_list_component/view_spec.rb @@ -35,6 +35,10 @@ expect(page).not_to have_button("Move up") expect(page).not_to have_button("Move down") end + + it "includes the page id in the id for the row" do + expect(page).to have_css "#page_1.govuk-summary-list__row" + end end context "when the form has multiple pages" do @@ -53,6 +57,11 @@ expect(page).to have_button("Move down") end + it "includes the page id in the id for each row" do + expect(page).to have_css "#page_1.govuk-summary-list__row" + expect(page).to have_css "#page_2.govuk-summary-list__row" + end + context "when the form has conditions" do let(:pages) do [(build :page, id: 1, position: 1, question_text: "What country do you live in?", routing_conditions:), @@ -175,6 +184,12 @@ end end + describe "#page_row_id" do + it "returns the corrrect id text for a given page" do + expect(page_list_component.page_row_id(pages.second)).to eq "page_2" + end + end + describe "error_id" do it "returns the corrrect id text for a given condition number" do expect(PageListComponent::ErrorSummary::View.error_id(1)).to eq "condition_1"