test(cypress): require visible homepage language-bar links in multi-language sanity test#2459
Conversation
…ti-language sanity homepage switch test Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/106b6d42-c9e4-4522-884f-6b31b77b6043 Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
🏷️ Automatic Labeling SummaryThis PR has been automatically labeled based on the files changed and PR metadata. Applied Labels: javascript,testing,size-s Label Categories
For more information, see |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
There was a problem hiding this comment.
Pull request overview
Updates the Cypress multi-language sanity spec to avoid clicking hidden language-switcher links by ensuring the <details.rm-lang-switcher> dropdown is opened and preferring a :visible language link before navigating.
Changes:
- Open
details.rm-lang-switcherelements before attempting language-switcher clicks. - Prefer a visible match for the target language link and add a fallback forced click when none are visible.
- Keep the existing loop-based approach to validate switching to a small set of representative languages.
| // Prefer a visible occurrence of the language link (header | ||
| // switcher when expanded, footer language list, or in-page | ||
| // anchor). Fall back to a forced click only if every match | ||
| // remains hidden, which keeps the assertion meaningful while | ||
| // tolerating layout differences across breakpoints. | ||
| cy.get(`a[href*="index_${langCode}.html"]`).then(($links) => { | ||
| const $visible = $links.filter(':visible'); | ||
| if ($visible.length > 0) { | ||
| cy.wrap($visible.first()).click(); | ||
| } else { | ||
| cy.wrap($links.first()).click({ force: true }); | ||
| } | ||
| }); |
| // so the language anchors become interactive before clicking. | ||
| if ($body.find('details.rm-lang-switcher').length > 0) { | ||
| cy.get('details.rm-lang-switcher').each(($el) => { | ||
| cy.wrap($el).invoke('attr', 'open', 'open'); | ||
| }); | ||
| } | ||
|
|
||
| // Prefer a visible occurrence of the language link (header | ||
| // switcher when expanded, footer language list, or in-page | ||
| // anchor). Fall back to a forced click only if every match | ||
| // remains hidden, which keeps the assertion meaningful while | ||
| // tolerating layout differences across breakpoints. | ||
| cy.get(`a[href*="index_${langCode}.html"]`).then(($links) => { | ||
| const $visible = $links.filter(':visible'); | ||
| if ($visible.length > 0) { | ||
| cy.wrap($visible.first()).click(); | ||
| } else { | ||
| cy.wrap($links.first()).click({ force: true }); | ||
| } | ||
| }); |
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/a15d3b51-8f56-4629-9657-9098d60312bf Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/a15d3b51-8f56-4629-9657-9098d60312bf Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Applied the review changes in |
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
Summary
Fixes the single failing Cypress test reported in the problem statement:
Root Cause
The homepage contains both a collapsed header language switcher and an always-visible language bar. The test used a broad selector and clicked the first matching
index_<lang>.htmllink, which could resolve to a hidden anchor inside the collapsed header dropdown.Fix
In
cypress/e2e/multi-language-sanity.cy.js(Language Switcher Functionality > should allow switching between languages on homepage):nav.rm-lang-bar) instead of the collapsed header dropdown.href*="index_${langCode}.html"to tolerate path variations.Test-only change, scoped to a single Cypress spec; no production code, dependencies, build, or CI configuration is modified.
Validation
npm run build✅cypress/e2e/multi-language-sanity.cy.js— 161 passing ✅cypress/e2e/multi-language-sanity.cy.js✅parallel_validation: Code Review ✅, CodeQL ✅ (skipped as trivial test-only change)