Skip to content

test(ui): make ui tests fail when the behaviour they cover breaks - #1051

Merged
swolfand merged 2 commits into
mainfrom
sam/test-audit-ui
Oct 6, 2026
Merged

swolfand merged 2 commits into
mainfrom
sam/test-audit-ui

Conversation

@swolfand

@swolfand swolfand commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

What

The source/ui half of #985, re-applied on current main. #985 couldn't be rebased. #1038 moved the prebuilt UI onto the Clerk.auth facade, so its AuthStartViewModel tests were written against SignIn.create/SignUp.create mocks that no longer exist. This PR ports the auth tests that were worth keeping onto Clerk.auth (auth.signIn {}, auth.signUp {}, auth.signInWithOAuth/signUpWithOAuth) and carries over the profile and organization changes, which still apply cleanly.

Only test files change. The AuthStartView.kt formatting change from #985 is dropped.

Why each change now fails on a regression

Every behaviour listed below was mutation-checked: the production line was broken, the test was confirmed to fail, and the line was restored.

AuthViewModelTest, ported to Clerk.auth

  • startAuthWithSignInOrUpModeSurfacesNonFallbackSignInErrorsWithoutSignUp replaces a test that stopped at Loading with cancelAndIgnoreRemainingEvents(). It now asserts the Error("Invalid email") state, the identifier sent to auth.signIn, and that auth.signUp is never called. It fails if sign-in-or-up falls back to sign-up on any error, not just form_identifier_not_found.
  • startAuthWithSignUpChoosesEmailOrUsernameParamsFromIdentifierFormat sends seven identifiers through auth.signUp {} and checks which ones become email and which become username. It fails if the isEmailAddress branch is inverted.
  • socialOAuthCanStartWithSignUp now also asserts the final OAuthState.SignUpSuccess. It fails if the redirect path drops the sign-up result.
  • Removed authModeEnumShouldHaveCorrectValues and oauthProviderShouldHaveExpectedValues. They only checked enum .name strings, so they couldn't fail on a behaviour change.
  • The phone-identifier test (startAuthUsesPhoneNumberAsIdentifierOnlyWhenPhoneFieldIsActive) was already ported by refactor(ui): move the prebuilt UI onto the Clerk.auth facade #1038 and checks the resolved identifier, so it's unchanged.

Sign-in factor code

  • SignInAttemptHandlerTest: the failure tests now assert that the "boom" error message reaches onErrorCallback. One of them set receivedError = errorResponse inside the callback and then compared it with itself. All 7 failure tests fail if the handler stops passing errorMessage.
  • SignInFactorCodeViewModelTest:
    • Removed the two Turbine Idle→Loading tests. They asserted only the Loading emission, which other tests already assert together with the outcome. Removing Loading from prepare still fails 5 tests, and removing it from attempt still fails 4.
    • "reuse active second-factor verification" now asserts the state stays Idle, matching its first-factor twin. Both fail if Loading is set before the reuse check.
    • The "should throw" names are fixed to "should set NotStarted".
  • SignInPrepareHandlerTest: the null-ID tests from main are kept. Main already verifies sendPhoneCode/sendEmailCode there, so test: audit the unit test suite for tests that don't test anything #985's removal no longer applies.

Other auth tests

  • AuthStateEffectsTest moves from Paparazzi to the compose test rule. It now asserts that the snackbar shows the error message and that the back stack isn't cleared.
  • AuthStateForceMfaTest adds a test that the created session wins over the fallback.
  • AuthStartViewHelperTest compares autofill hints instead of asserting what the content type isn't.
  • SignInFactorOneViewTest adds a test that resolveFirstFactor switches to the prepared factor when the fallback is no longer supported.

Profile and organization view models

  • UserProfileChangePasswordViewModelTest verifies the exact UpdatePasswordParams. It fails if signOutOfOtherSessions is ignored.
  • UpdateProfileViewModelTest verifies the update/setProfileImage/deleteProfileImage params and the user.get() refresh. It fails if the refresh is skipped.
  • OrganizationVerifiedDomainsViewModelTest adds the domainsEnabled = false case. It fails if canLoadDomains ignores domainsEnabled.
  • EmailViewModelTest verifies the primaryEmailAddressId update.
  • UserProfileVerifyViewModelTest verifies the code sent to attemptVerification/attemptTotpVerification and that backup codes reach the Verified state. Before, they were stubbed as null.
  • UserProfilePasskeyViewModelTest verifies createPasskey() actually ran. Before, its "no events" check passed even if nothing happened.
  • AddEmailViewModelTest verifies that the immutable-email path never calls createEmailAddress.
  • DeleteAccountViewModelTest verifies that local biometric credentials are kept when deletion fails.
  • OrganizationProfileActionConfirmationViewModelTest counts client refreshes on success and failure.
  • UserProfileAccountViewModelTest uses MainDispatcherRule, so Dispatchers.Main no longer leaks into other classes.
  • PhoneInputUtilsTest checks real flags for upper- and lower-case region codes instead of a made-up ab region.

Removed because they couldn't fail

  • CountryInfoTest: tested data-class equals/toString.
  • CustomRouteNavKeyTest: duplicated the serialization round-trip.
  • LastUsedAuthTest: an exact duplicate of biometricCredentialCountsTowardVisibleMethodCount.
  • CustomRowGatingTest: a redundant all { BuiltIn } check.

Left out

  • Snapshot goldens. test: audit the unit test suite for tests that don't test anything #985 removed two OrganizationProfile error-state snapshot tests whose goldens are byte-identical to the non-error states (organizationVerifiedDomainsErrorState = …AddDomain, organizationActionDeleteError = …DeleteReady), so the error message isn't actually rendered. ./gradlew :source:ui:verifyPaparazziDebug doesn't pass on this branch with that change applied: 21 failures, all in other tests (sub-0.1% rendering diffs, stale OrganizationProfile goldens, and tests with no golden). So it's not included here. The same goes for test: audit the unit test suite for tests that don't test anything #985's re-recorded goldens and the ClerkTopAppBar/passwordSection_Light snapshot fixes, which need re-recording against a passing baseline.

Results

  • :source:ui:testDebugUnitTest: 505 run, 0 failed.
  • spotlessApply, :source:api:detekt and :source:ui:detekt are clean.

The API test half is in #1049.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded authentication and sign-in coverage for error messages, factor selection, session resolution, signup identifier handling, and state transitions.
    • Added checks for account and profile actions, including organization deletion, email updates, passkey creation, password changes, verification, and credential retention after deletion failures.
    • Clarified checks for phone-country handling, custom profile rows, and behavior when domain loading is unavailable.
    • Updated UI tests to verify snackbar behavior and email-and-username autofill hints.

@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: clerk/clerk-android/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 5b9b068c-3a1b-407c-91f7-118c757655a8
📥 Commits

Reviewing files that changed from the base of the PR and between 91ed575 and f46f056.

📒 Files selected for processing (3)
  • source/ui/src/test/java/com/clerk/ui/userprofile/account/UserProfileAccountViewModelTest.kt
  • source/ui/src/test/java/com/clerk/ui/userprofile/security/delete/DeleteAccountViewModelTest.kt
  • source/ui/src/test/java/com/clerk/ui/userprofile/security/passkey/UserProfilePasskeyViewModelTest.kt

Limit details: You’ve used all 6 included reviews currently available. Your 48 included PR review attempts over the past 7 days set your current allowance at 6 reviews per hour.


📝 Walkthrough

Walkthrough

This pull request updates UI tests across authentication, sign-in, organization and user profiles, input utilities, and custom rows. The changes revise assertions, add call-count checks, adjust test setup, and remove selected tests.

Changes

UI test coverage

Layer / File(s) Summary
Authentication behavior tests
source/ui/src/test/java/com/clerk/ui/auth/*
Tests check combined autofill hints, snackbar and reset behavior, MFA session selection, authentication parameters, and OAuth signup state. Some enum-value and biometric-credential assertions were removed.
Sign-in factor and code tests
source/ui/src/test/java/com/clerk/ui/signin/*
Tests check prepared-factor resolution and error callback messages. View-state test names and assertions were updated, and two state-transition tests were removed.
Organization profile tests
source/ui/src/test/java/com/clerk/ui/organizationprofile/*
Tests check client refresh counts after organization deletion and the state when verified domains are disabled.
User profile operation tests
source/ui/src/test/java/com/clerk/ui/userprofile/*
Tests add API call-count and argument checks for email, deletion, passkey, password, profile-update, and verification operations. Account tests use a main-dispatcher rule.
Input and custom-row tests
source/ui/src/test/java/com/clerk/ui/input/*, source/ui/src/test/java/com/clerk/ui/userprofile/custom/*
Input tests revise flag and country expectations and remove equality and string-format checks. Custom-row tests assert an exact ordered result; a route-key deserialization test was removed.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Suggested reviewers: mikepitre

Merge Risk: ⚪ Minimal · up to f46f0

The reported UI unit tests and static checks are clean, and the snapshot failures are reported in other tests. No actionable merge-blocking risk is established; normal CI checks remain appropriate.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.28% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 78 functions across 19 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: strengthening UI tests so they detect behavior regressions.
Description check ✅ Passed The description explains what changed, why the changes were made, which tests to review, and the reported test results. It also covers excluded snapshot changes. The template’s separate “What & why” a…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Carries over the source/ui test changes from #985 that still apply to main,
and ports the auth tests onto the Clerk.auth facade the prebuilt UI now uses.

AuthStartViewModel: the sign-in-or-up test now checks that a non-fallback
sign-in error is surfaced without starting a sign-up, sign-up chooses email or
username params from the identifier format, and OAuth sign-up ends in
SignUpSuccess. SignInAttemptHandlerTest checks the error message passed to the
callback. Profile and organization view model tests verify the params sent to
the API and the refresh after success.

Removes tests that couldn't fail: enum name checks, data-class
equality/toString, exact duplicates, and Idle->Loading checks already covered
by tests that also assert the final state.
@swolfand
swolfand merged commit 80b919d into main Oct 6, 2026
9 checks passed
@swolfand
swolfand deleted the sam/test-audit-ui branch October 6, 2026 22:50
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.

1 participant