Skip to content

Fixing tt02 login for Cypress tests#4246

Merged
olemartinorg merged 23 commits into
mainfrom
chore/fixing-cypress-tt02
Jun 4, 2026
Merged

Fixing tt02 login for Cypress tests#4246
olemartinorg merged 23 commits into
mainfrom
chore/fixing-cypress-tt02

Conversation

@olemartinorg
Copy link
Copy Markdown
Contributor

@olemartinorg olemartinorg commented Jun 2, 2026

Description

  • Replaced the removed Altinn 2 tt02 password-login flow with Tenor/ID-porten login for Cypress tests, including cross-origin Cypress handling via login.html files in apps so tests can establish the app origin before redirecting through login (this fixes lots of small problems that crept up after switching to Tenor login).
  • Added shared Tenor test users/orgs and made tt02 assertions use Tenor names/parties, because local test users and tt02 Tenor users now differ in most tests.
  • Removed the old evaluateBefore pre-app JavaScript shortcut and rewrote cy.goto() to navigate through the app UI/process flow, because the previous shortcut no longer worked reliably with the new login/origin setup.
  • Added cy.preventPartySelection() and updated party-selection tests to explicitly opt in/out of party prompting, avoiding accidental prompts in tests that assume direct app entry.
  • Updated signing tests to use working Tenor users and organizations, including explicit party selection for tt02 signing flows instead of intercepts to filter all but the intended party.
  • Fixed PDF test navigation to visit through login.html before loading PDF URLs, avoiding app-frontend treating PDF navigation as only a hash change (this lead to flakiness in several pdf tests).
  • Adjusted assertions affected by tt02 data/login changes, including user display names, party names, receipt/stateless user names, autosave request counts, and a narrower layout intercept in a PDF test.
  • Skipped self-identified-user Cypress tests for now, because that login path still depends on the removed Altinn 2 tt02 flow. We'll have to figure out a solution to this later.
  • Removed the print-button Cypress test because stubbing window.print() no longer works reliably with the current Cypress/origin behavior, and the test only covered the browser print call (so it was not all that useful).
  • Tightened party mock behavior by failing when an expected org is missing instead of silently falling back, making tt02/local test-data problems easier to diagnose.
  • Updated test docs/page-object links for subform-test to the current Altinn Studio URL (one app mistakenly pointed to dev.altinn.studio when it was on altinn.studio).

Related Issue(s)

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • Tests

    • Updated E2E test suites across multiple scenarios including auto-save behavior, party selection, form validation, and stateless app functionality.
    • Enhanced test fixtures and user context handling across integration tests.
  • Chores

    • Refactored test infrastructure and authentication flow for improved test reliability.
    • Updated test configuration and support utilities for E2E testing.

Ole Martin Handeland added 2 commits June 2, 2026 10:32
…ing evaluateBefore functionality and replacing it with simpler goto functions
@olemartinorg olemartinorg added ignore-for-release Pull requests to be ignored in release notes backport-ignore This PR is a new feature and should not be cherry-picked onto release branches labels Jun 2, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors the e2e test infrastructure to centralize test fixture data, remove JavaScript injection-based navigation, and update authentication flows for improved cross-origin handling. A new Tenor fixture module provides shared user/organization test data; supporting infrastructure (auth, navigation, app instance defaults) is updated accordingly; and individual test files migrate to use the new patterns.

Changes

Tenor Fixture Centralization and Infrastructure Refactoring

Layer / File(s) Summary
Tenor Fixture Module and Type Definitions
test/e2e/support/users.ts
New module exporting TenorOrg, TenorUser, TenorLoginParams, and TenorRole types; provides a centralized Tenor fixture with user and organization constants, replacing scattered local test data.
Authentication Infrastructure Refactoring
test/e2e/support/auth.ts
Refactors auth support to import Tenor types from the new users module, introduces shared emptyPageHtml template, reworks tenorTt02Login with cy.origin blocks for cross-origin IdP login, removes cyUserTt02Login and waitForLogin helpers, and updates assertUser command to accept and validate Tenor user parameters.
Navigation Simplification: Remove Injected JS, Add UI-Driven Flow
test/e2e/support/navigation.ts
Removes the evaluateBefore JS-injection pattern (taskMapping, generateEvalString) and replaces it with initAndGoto helper that navigates via UI interactions; simplifies gotoHiddenPage to type form fields and check boxes instead of manipulating instance state.
Global Cypress Types and Commands
test/e2e/support/global.ts
Removes 'confirm' task from FrontendTestTask, removes evaluateBefore from StartAppInstanceOptions, simplifies goto signature to accept only task parameter, updates assertUser to accept tenorUser parameter, and adds new preventPartySelection command.
App Instance Startup Defaults and Options
test/e2e/support/start-app-instance.ts
Defaults tenorUser to Tenor.users.saligBlomsterplante instead of null, removes evaluateBefore option handling and related HTML rewriting, and adds conditional login branching logic when both tenorUser and cyUser are provided on localtest.
Custom Cypress Commands: PDF Navigation and Party Selection
test/e2e/support/custom.ts
Adds preventPartySelection command to intercept application metadata and force promptForParty = 'never'; updates PDF navigation to use /login.html placeholder with multi-step visits instead of hash-based navigation.
Signing Test Helper Refactoring
test/e2e/support/apps/signing-test/signing-login.ts
Changes function parameter from CyUser to User union, adds internal tenorUserMapping to derive TenorUser from user role, adds conditional organization selection UI, and updates user assertion to pass both user and tenorUser parameters.
Party Mocks Utility Enhancement
test/e2e/pageobjects/party-mocks.ts
Updates removeAllButKeepOrg to throw an error when target organization is not found instead of falling back to removeAllButOneOrg, making test failures explicit.

Test Suite Updates to Use Tenor Fixtures

Layer / File(s) Summary
Anonymous Stateless App Tests: tenorUser Parameter Addition
test/e2e/integration/anonymous-stateless-app/*
Anonymous stateless app tests now explicitly pass tenorUser: null alongside cyUser: null to cy.startAppInstance in all affected test hooks and cases.
Frontend Test Updates: Core Test Logic and Assertions
test/e2e/integration/frontend-test/{accordion,auto-save-behavior,instantiation,pdf}.ts
Accordion test switches assertion from "not exist" to "not visible"; auto-save behavior test expectations updated for new request timing; instantiation tests add tenorUser: Tenor.users.snaalDugnad; PDF test narrows intercept pattern to specific layout endpoint.
Party Selection Test Refactoring
test/e2e/integration/frontend-test/party-selection.ts
Extensively refactored with new clickValidParty(cyUser) helper for environment-aware party selection, environment-specific org filtering for allowed parties, new test case for multiple-party prompt scenario, name-based party lookup instead of first-party selection, and tenorUser parameters added to all app instance starts.
Stateless App Tests: Tenor User Integration
test/e2e/integration/stateless-app/{party-selection,receipt,stateless}.ts
Tests now conditionally derive user names based on Cypress.env('type'), using local defaults for localtest and uppercased Tenor user names for other environments; stateless party-selection adds tenorUser parameter.
Specialized Test Updates: Signing, Prefill, Self-Identified User
test/e2e/integration/{signering-brukerstyrt/signing,frontend-test/{prefill,self-identified-user}}.ts
Signing test replaces local test data with Tenor fixture references, refactors table row selectors to use dynamic RegExp patterns with Tenor names and reverseName variations, adds saved-state synchronization; prefill computes fullName conditionally; self-identified user tests skipped with TODO comments; all pass tenorUser parameters.
Test Removal and Configuration Updates
test/README.md, test/e2e/config/tt02.json, test/e2e/pageobjects/app-frontend.ts
Print-button e2e test suite removed entirely; selfIdentifiedUserPwd updated in tt02.json; test documentation reference updated.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes


Possibly related PRs

  • Altinn/app-frontend-react#4235: Both PRs modify the Cypress party-selection flow to deterministically pin/select specific organizations using removeAllButKeepOrg and related test/e2e/pageobjects/party-mocks.ts behavior.

Suggested labels

kind/other


Suggested reviewers

  • adamhaeger
  • phlipsterit
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'Fixing tt02 login for Cypress tests' directly addresses the main objective of the changeset—updating Cypress test authentication and login flows for tt02 environments.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description covers all key required sections from the template including description, related issues, and verification/QA checklist with appropriate selections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/fixing-cypress-tt02

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Ole Martin Handeland added 21 commits June 2, 2026 11:43
… we waited a bit longer, as it would probably pass before the app was completely loaded.
… tests that don't do that. Overriding this in goto() so that frontend-test does not prompt for party most of the time.
…r works. I suspect it's because the cypress runner no longer trusts the origin or something, but it's easier to just delete this test. I don't think this is something that will break at any point, as the test is simple enough and just asserts that clicking a button calls window.print().
@olemartinorg olemartinorg marked this pull request as ready for review June 4, 2026 09:48
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/e2e/pageobjects/party-mocks.ts (1)

185-191: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update the function comment to match the new strict behavior.

removeAllButKeepOrg now throws when the org is missing, but the inline comment still says it falls back to the first org. This is now misleading.

Suggested update
 export function removeAllButKeepOrg(parties: IParty[], orgNumber: string): IParty[] {
-  // Keep one specific organisation (by org number) plus all persons. Pinning a specific org by
-  // number, instead of just taking the first one. This avoids depending on the order of the tt02
-  // party list, which is not stable. Falls back to the first org when this specific org is not
-  // present, e.g. in docker/podman/localtest environments that have entirely different test data.
+  // Keep one specific organisation (by org number) plus all persons. Pinning a specific org by
+  // number, instead of just taking the first one, avoids depending on unstable party ordering.
+  // Throws if the target organisation is not present.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/pageobjects/party-mocks.ts` around lines 185 - 191, Update the
inline comment above the org selection in removeAllButKeepOrg to reflect the
current strict behavior: explain that the function pins a specific organisation
by orgNumber and will throw an error if that org is not found (no longer falling
back to the first organisation), and mention it still keeps all persons;
reference the use of parties.find((party) => party.partyTypeName ===
PartyType.Organisation && party.orgNumber === orgNumber) and the subsequent
throw when org is undefined so readers understand the behavior change.
🧹 Nitpick comments (1)
test/e2e/integration/signering-brukerstyrt/signing.ts (1)

30-30: ⚡ Quick win

Use lastName from Tenor fixtures instead of splitting name.

Parsing name.split(' ')[1] is fragile if fixture names ever include middle names. TenorUser.lastName is already available and safer.

Suggested change
-      cy.findByRole('textbox', { name: /navn/i }).type(Tenor.users.humanAndrefiolin.name.split(' ')[1]);
+      cy.findByRole('textbox', { name: /navn/i }).type(Tenor.users.humanAndrefiolin.lastName);

-      cy.findByRole('textbox', { name: /navn/i }).type(Tenor.users.standhaftigBjornunge.name.split(' ')[1]);
+      cy.findByRole('textbox', { name: /navn/i }).type(Tenor.users.standhaftigBjornunge.lastName);

-      cy.findByRole('textbox', { name: /etternavn/i }).type(Tenor.users.varsomDiameter.name.split(' ')[1]);
+      cy.findByRole('textbox', { name: /etternavn/i }).type(Tenor.users.varsomDiameter.lastName);

Also applies to: 46-46, 79-79

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/integration/signering-brukerstyrt/signing.ts` at line 30, Replace
fragile name splitting with the fixture's lastName field: wherever the test uses
Tenor.users.humanAndrefiolin.name.split(' ')[1] (and the other similar
occurrences in this file), use Tenor.users.humanAndrefiolin.lastName instead;
update the cy.findByRole('textbox', { name: /navn/i }).type(...) calls to pass
the lastName value so tests don't break if a fixture has middle names.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@test/e2e/pageobjects/party-mocks.ts`:
- Around line 185-191: Update the inline comment above the org selection in
removeAllButKeepOrg to reflect the current strict behavior: explain that the
function pins a specific organisation by orgNumber and will throw an error if
that org is not found (no longer falling back to the first organisation), and
mention it still keeps all persons; reference the use of parties.find((party) =>
party.partyTypeName === PartyType.Organisation && party.orgNumber === orgNumber)
and the subsequent throw when org is undefined so readers understand the
behavior change.

---

Nitpick comments:
In `@test/e2e/integration/signering-brukerstyrt/signing.ts`:
- Line 30: Replace fragile name splitting with the fixture's lastName field:
wherever the test uses Tenor.users.humanAndrefiolin.name.split(' ')[1] (and the
other similar occurrences in this file), use
Tenor.users.humanAndrefiolin.lastName instead; update the
cy.findByRole('textbox', { name: /navn/i }).type(...) calls to pass the lastName
value so tests don't break if a fixture has middle names.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a51c9046-2a4d-40ad-b17c-a9269e914bb2

📥 Commits

Reviewing files that changed from the base of the PR and between 4497bf0 and 33c200d.

📒 Files selected for processing (27)
  • test/README.md
  • test/e2e/config/tt02.json
  • test/e2e/integration/anonymous-stateless-app/anonymous.ts
  • test/e2e/integration/anonymous-stateless-app/auto-save-behavior.ts
  • test/e2e/integration/anonymous-stateless-app/options.ts
  • test/e2e/integration/anonymous-stateless-app/validation.ts
  • test/e2e/integration/frontend-test/accordion.ts
  • test/e2e/integration/frontend-test/auto-save-behavior.ts
  • test/e2e/integration/frontend-test/instantiation.ts
  • test/e2e/integration/frontend-test/party-selection.ts
  • test/e2e/integration/frontend-test/pdf.ts
  • test/e2e/integration/frontend-test/prefill.ts
  • test/e2e/integration/frontend-test/print-button.ts
  • test/e2e/integration/frontend-test/self-identified-user.ts
  • test/e2e/integration/signering-brukerstyrt/signing.ts
  • test/e2e/integration/stateless-app/party-selection.ts
  • test/e2e/integration/stateless-app/receipt.ts
  • test/e2e/integration/stateless-app/stateless.ts
  • test/e2e/pageobjects/app-frontend.ts
  • test/e2e/pageobjects/party-mocks.ts
  • test/e2e/support/apps/signing-test/signing-login.ts
  • test/e2e/support/auth.ts
  • test/e2e/support/custom.ts
  • test/e2e/support/global.ts
  • test/e2e/support/navigation.ts
  • test/e2e/support/start-app-instance.ts
  • test/e2e/support/users.ts
💤 Files with no reviewable changes (1)
  • test/e2e/integration/frontend-test/print-button.ts

@olemartinorg olemartinorg merged commit 9f7669c into main Jun 4, 2026
20 of 21 checks passed
@olemartinorg olemartinorg deleted the chore/fixing-cypress-tt02 branch June 4, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-ignore This PR is a new feature and should not be cherry-picked onto release branches ignore-for-release Pull requests to be ignored in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cypress tests are failing after A2 sunset

2 participants