Repository navigation
test(ui): make ui tests fail when the behaviour they cover breaks - #1051
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
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. 📝 WalkthroughWalkthroughThis 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. ChangesUI test coverage
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Other Suggested reviewers: Merge Risk: ⚪ Minimal · up to 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
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.
91ed575 to
f46f056
Compare
What
The
source/uihalf of #985, re-applied on currentmain. #985 couldn't be rebased. #1038 moved the prebuilt UI onto theClerk.authfacade, so itsAuthStartViewModeltests were written againstSignIn.create/SignUp.createmocks that no longer exist. This PR ports the auth tests that were worth keeping ontoClerk.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.ktformatting 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 toClerk.authstartAuthWithSignInOrUpModeSurfacesNonFallbackSignInErrorsWithoutSignUpreplaces a test that stopped atLoadingwithcancelAndIgnoreRemainingEvents(). It now asserts theError("Invalid email")state, the identifier sent toauth.signIn, and thatauth.signUpis never called. It fails if sign-in-or-up falls back to sign-up on any error, not justform_identifier_not_found.startAuthWithSignUpChoosesEmailOrUsernameParamsFromIdentifierFormatsends seven identifiers throughauth.signUp {}and checks which ones becomeemailand which becomeusername. It fails if theisEmailAddressbranch is inverted.socialOAuthCanStartWithSignUpnow also asserts the finalOAuthState.SignUpSuccess. It fails if the redirect path drops the sign-up result.authModeEnumShouldHaveCorrectValuesandoauthProviderShouldHaveExpectedValues. They only checked enum.namestrings, so they couldn't fail on a behaviour change.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 reachesonErrorCallback. One of them setreceivedError = errorResponseinside the callback and then compared it with itself. All 7 failure tests fail if the handler stops passingerrorMessage.SignInFactorCodeViewModelTest:Loadingemission, which other tests already assert together with the outcome. RemovingLoadingfrompreparestill fails 5 tests, and removing it fromattemptstill fails 4.Idle, matching its first-factor twin. Both fail ifLoadingis set before the reuse check.SignInPrepareHandlerTest: the null-ID tests from main are kept. Main already verifiessendPhoneCode/sendEmailCodethere, so test: audit the unit test suite for tests that don't test anything #985's removal no longer applies.Other auth tests
AuthStateEffectsTestmoves 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.AuthStateForceMfaTestadds a test that the created session wins over the fallback.AuthStartViewHelperTestcompares autofill hints instead of asserting what the content type isn't.SignInFactorOneViewTestadds a test thatresolveFirstFactorswitches to the prepared factor when the fallback is no longer supported.Profile and organization view models
UserProfileChangePasswordViewModelTestverifies the exactUpdatePasswordParams. It fails ifsignOutOfOtherSessionsis ignored.UpdateProfileViewModelTestverifies theupdate/setProfileImage/deleteProfileImageparams and theuser.get()refresh. It fails if the refresh is skipped.OrganizationVerifiedDomainsViewModelTestadds thedomainsEnabled = falsecase. It fails ifcanLoadDomainsignoresdomainsEnabled.EmailViewModelTestverifies theprimaryEmailAddressIdupdate.UserProfileVerifyViewModelTestverifies the code sent toattemptVerification/attemptTotpVerificationand that backup codes reach theVerifiedstate. Before, they were stubbed asnull.UserProfilePasskeyViewModelTestverifiescreatePasskey()actually ran. Before, its "no events" check passed even if nothing happened.AddEmailViewModelTestverifies that the immutable-email path never callscreateEmailAddress.DeleteAccountViewModelTestverifies that local biometric credentials are kept when deletion fails.OrganizationProfileActionConfirmationViewModelTestcounts client refreshes on success and failure.UserProfileAccountViewModelTestusesMainDispatcherRule, soDispatchers.Mainno longer leaks into other classes.PhoneInputUtilsTestchecks real flags for upper- and lower-case region codes instead of a made-upabregion.Removed because they couldn't fail
CountryInfoTest: tested data-classequals/toString.CustomRouteNavKeyTest: duplicated the serialization round-trip.LastUsedAuthTest: an exact duplicate ofbiometricCredentialCountsTowardVisibleMethodCount.CustomRowGatingTest: a redundantall { BuiltIn }check.Left out
organizationVerifiedDomainsErrorState=…AddDomain,organizationActionDeleteError=…DeleteReady), so the error message isn't actually rendered../gradlew :source:ui:verifyPaparazziDebugdoesn'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 theClerkTopAppBar/passwordSection_Lightsnapshot fixes, which need re-recording against a passing baseline.Results
:source:ui:testDebugUnitTest: 505 run, 0 failed.spotlessApply,:source:api:detektand:source:ui:detektare clean.The API test half is in #1049.
🤖 Generated with Claude Code
Summary by CodeRabbit