Skip to content

Commit

Permalink
Add page IDs to summary list rows for page summary component
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lfdebrux committed Feb 26, 2025
1 parent c703095 commit cb4001c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/components/page_list_component/view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%= form_with url: move_page_url(@form_id), method: :post, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<dl class="govuk-summary-list">
<% @pages.each_with_index do |page, index| %>
<div class="govuk-summary-list__row">
<div id="<%= page_row_id(page) %>" class="govuk-summary-list__row">

<dt class="govuk-summary-list__key app-page-list__key">
<%= page.position %>
Expand Down
4 changes: 4 additions & 0 deletions app/components/page_list_component/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 15 additions & 0 deletions spec/components/page_list_component/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:),
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit cb4001c

Please sign in to comment.