Skip to content

Conversation

@h-m-m
Copy link
Contributor

@h-m-m h-m-m commented Jun 5, 2025

Relevant Ticket or Conversation:

[identity-dev-docs] direct links to accordions should auto-expand — on GitLab

(Previously https://cm-jira.usa.gov/browse/LG-14871 )

Description of Changes:

  • Add Capybara to the test suite
  • Add JS that will, based on the URL, auto-expand the accordion components that have an ID in any page they might appear

@h-m-m h-m-m force-pushed the hmm/partner-portal#58/auto-accordion-js branch 2 times, most recently from ebe8ff3 to cd42a87 Compare June 5, 2025 21:40
@h-m-m h-m-m force-pushed the hmm/partner-portal#58/auto-accordion-js branch from cd42a87 to 993473c Compare June 6, 2025 20:03
(() => {
const onChange = (_event) => {
const urlHash = new URL(document.URL).hash;
const idFromHash = urlHash.match(/^(#[A-Za-z0-9_-]+)$/);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this came up before I put the code up for review: I deliberately want to keep some input sanitization here. The format I've picked is in line with the general format we use for class and id attributes, so it feels appropriate to me.

require 'capybara_helper'
require 'pry-byebug'

RSpec.describe 'accordions on /oidc/authorization/', :js, type: :feature do
Copy link
Contributor Author

@h-m-m h-m-m Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still prefer actual JS tests instead of or in addition to these Capybara tests. That said, I agree with Jack Cody that this was likely the easiest testing to set up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure actual JS tests are beneficial when the only output is DOM manipulation. If you had a function like getSanitizedHash, you could test that, but as-is this tests everything you can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree that the coverage here is good.

Compared to some JS testing I've done in the past, doing it this way does feels to me like wearing thick, knitted gloves on my fingers when I'm not used to wearing them.

My main concern is that it feels too easy to accidentally break something here in a way that would generate a JS error that this test won't notice. Detecting a JS error like that in a headless browser with Capybara is tricky and fragile. I'm particularly concerned with breaking unrelated behavior on a page where this JS is included but the page doesn't have an accordion (or doesn't have one anymore).

@h-m-m h-m-m marked this pull request as ready for review June 6, 2025 20:11
Copy link
Contributor

@ajfarkas ajfarkas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@h-m-m h-m-m merged commit 6290497 into main Jun 9, 2025
4 checks passed
@h-m-m h-m-m deleted the hmm/partner-portal#58/auto-accordion-js branch June 9, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants