Skip to content

Commit

Permalink
EL-1878: govuk-frontend 5.7.1 bump (#1669)
Browse files Browse the repository at this point in the history
- update CCQ `govuk-frontend` to 5.7.1
- don't initialise radio component if already initialised
- update the numbering on the `data-add-another-dynamic-elements` so that `aria-controls` increments and decrements as expected.
- add a test for being able to interact with conditional reveal after removing 'add another'
  • Loading branch information
MazOneTwoOne authored Nov 26, 2024
1 parent 3d2d59f commit 8773634
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
14 changes: 11 additions & 3 deletions app/javascript/add-another.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,23 @@ const setNumbering = (section, counter) => {
}
section.querySelectorAll('[data-add-another-dynamic-elements]').forEach((element) => {
element.dataset.addAnotherDynamicElements.split(",").forEach((pairString) => {
const parts = pairString.split(":");
element.setAttribute(parts[0], parts[1].replace("ID", counter + 1))
const [attribute, valueTemplate] = pairString.split(":");
const newValue = valueTemplate.replace("ID", counter + 1);
element.setAttribute(attribute, newValue);

// Handle aria-controls specifically if the attribute is `data-aria-controls`
if (attribute === "data-aria-controls") {
element.setAttribute("aria-controls", newValue);
}
});
})
}

const setUpRadios = (section) => {
if (section.querySelector('input[type="radio"]')) {
const radioContainer = section.querySelector('[data-module="govuk-radios"]');
if (radioContainer && !radioContainer.dataset.radiosInitialized) {
const radios = new Radios(section);
radioContainer.dataset.radiosInitialized = true; // This is to handle `govuk-frontend` 5.7.0, not allowing us to initialising components twice
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@rails/ujs": "^7.1.402",
"@sentry/browser": "8.37.1",
"esbuild": "^0.24.0",
"govuk-frontend": "^5.6.0",
"govuk-frontend": "^5.7.1",
"jquery": "^3.7.1",
"puppeteer": "23.6.0",
"rails_admin": "3.2.1",
Expand Down
37 changes: 37 additions & 0 deletions spec/system/add_another_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,43 @@
click_on "remove-2"
expect(page).to have_content "Enter the estimated value of vehicle 2"
end

it "lets me remove a vehicle and I can still interact with conditional reveals", :slow do
fill_in "1-vehicle-value", with: "123"
choose "No", name: "vehicle_model[items][1][vehicle_pcp]"
choose "No", name: "vehicle_model[items][1][vehicle_over_3_years_ago]"
choose "No", name: "vehicle_model[items][1][vehicle_in_regular_use]"
click_on "Add another vehicle"

fill_in "2-vehicle-value", with: "456"
choose "No", name: "vehicle_model[items][2][vehicle_pcp]"
choose "No", name: "vehicle_model[items][2][vehicle_over_3_years_ago]"
choose "No", name: "vehicle_model[items][2][vehicle_in_regular_use]"
click_on "Add another vehicle"

fill_in "3-vehicle-value", with: "789"
choose "No", name: "vehicle_model[items][3][vehicle_pcp]"
choose "No", name: "vehicle_model[items][3][vehicle_over_3_years_ago]"
choose "No", name: "vehicle_model[items][3][vehicle_in_regular_use]"

click_on "Save and continue"

click_on "Back"

click_on "remove-2"

fill_in "2-vehicle-value", with: "456"
choose "Yes", name: "vehicle_model[items][2][vehicle_pcp]"
fill_in "2-vehicle-finance", with: "123"
choose "No", name: "vehicle_model[items][2][vehicle_over_3_years_ago]"
choose "No", name: "vehicle_model[items][2][vehicle_in_regular_use]"
click_on "Save and continue"

click_on "Back"

expect(find(id: "1-vehicle-value").value).to eq "123"
expect(find(id: "2-vehicle-value").value).to eq "456"
end
end

describe "additional properties" do
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,16 @@ get-uri@^6.0.1:
debug "^4.3.4"
fs-extra "^8.1.0"

govuk-frontend@^5.0.0, govuk-frontend@^5.6.0:
govuk-frontend@^5.0.0:
version "5.6.0"
resolved "https://registry.yarnpkg.com/govuk-frontend/-/govuk-frontend-5.6.0.tgz#8c0975f0d825ec7192bcfe64e3e97ef3dfa7dea1"
integrity sha512-yNA4bL7i7mNrg36wPNZ3RctHo9mjl82Phs8MWs1lwovxJuQ4ogEo/XWn2uB1HxkXNqgMlW4wnd0iiKgRMfxYfw==

govuk-frontend@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/govuk-frontend/-/govuk-frontend-5.7.1.tgz#d4c561ebf8c0b76130f31df8c2e4d70d340cd63f"
integrity sha512-jF1cq5rn57kxZmJRprUZhTQ31zaBBK4b5AyeJaPX3Yhg22lk90Mx/dQLvOk/ycV3wM7e0y+s4IPvb2fFaPlCGg==

graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
Expand Down

0 comments on commit 8773634

Please sign in to comment.