Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FTUE - Stage selection and Registration action testing #6091

Merged
merged 5 commits into from
Jun 16, 2022

Conversation

ouchadam
Copy link
Contributor

@ouchadam ouchadam commented May 18, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Adds unit tests around the registration stages

  • Lifts the next stage logic out of the UI layer and into a dedicated class RegistrationActionHandler
  • Extracts all the RegistrationAction -> Stage logic out of the ViewModel and adds unit tests

Motivation and context

To add missing coverage to the FTUE area

Screenshots / GIFs

No UI changes

Tests

  • Sign up for a new account

Tested devices

  • Physical
  • Emulator
  • OS version(s): 28

import javax.inject.Inject

class RegistrationActionHandler @Inject constructor() {
class RegistrationActionHandler @Inject constructor(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the original implementation in RegistrationActionHandler has been extracted and renamed to RegistrationWizardActionDelegate

@github-actions
Copy link

github-actions bot commented May 18, 2022

Unit Test Results

150 files  +  4  150 suites  +4   2m 34s ⏱️ +2s
245 tests +  9  245 ✔️ +  9  0 💤 ±0  0 ±0 
824 runs  +36  824 ✔️ +36  0 💤 ±0  0 ±0 

Results for commit 680b9a0. ± Comparison against base commit e6beb73.

This pull request removes 5 and adds 14 tests. Note that renamed tests count towards both.
im.vector.app.features.onboarding.OnboardingViewModelTest ‑ given personalisation enabled and registration has started and has dummy step to do, when handling action, then ignores other steps and does dummy
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given adding an email ThreePid fails with 401, when handling register action, then infer EmailSuccess
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given email verification errors with 401 and succeeds, when checking email validation, then continues to poll until success
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given email verification errors with 401 then fatal error, when checking email validation, then continues to poll until non 401 error
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ when handling register action then delegates to wizard
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given flow result contains unsupported stages, when handling action, then returns UnsupportedStage
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given flow result with mandatory and optional stages, when handling action, then returns mandatory stage
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given flow result with missing stages, when handling action, then returns MissingNextStage
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given flow result with only optional dummy stage, when handling action, then returns MissingNextStage
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given flow result with only optional stages, when handling action, then returns optional stage
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given matrix org homeserver and flow result with missing mandatory stages, when handling action, then returns email item first
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given non matrix org homeserver and flow result with missing mandatory stages, when handling action, then returns first item
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given password already sent and missing mandatory dummy stage, when handling action, then fast tracks the dummy stage
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ given wizard delegate returns success, when handling action, then returns success
im.vector.app.features.onboarding.RegistrationActionHandlerTest ‑ when processing SendAgainThreePid, then ignores result
…

♻️ This comment has been updated with latest results.

@ouchadam ouchadam changed the base branch from feature/adm/matrix-org-ordering to base/adm/email-veriifcation-and-ordering May 19, 2022 11:12
@ouchadam ouchadam force-pushed the feature/adm/ftue-register-test-cases branch from fb6a5b2 to 0a13e9a Compare May 19, 2022 11:12
@ouchadam ouchadam mentioned this pull request May 20, 2022
6 tasks
@ouchadam ouchadam changed the base branch from base/adm/email-veriifcation-and-ordering to develop May 23, 2022 20:25
@ouchadam ouchadam force-pushed the feature/adm/ftue-register-test-cases branch from 0a13e9a to 171056e Compare May 24, 2022 15:29
@ouchadam ouchadam marked this pull request as ready for review May 24, 2022 16:27
@ouchadam ouchadam requested review from a team, Florian14 and ariskotsomitopoulos and removed request for a team May 24, 2022 16:27
@ouchadam ouchadam force-pushed the feature/adm/ftue-register-test-cases branch from 171056e to 680b9a0 Compare June 1, 2022 09:37
@ouchadam ouchadam requested review from a team, Claire1817, Florian14 and fedrunov and removed request for ariskotsomitopoulos, a team and Florian14 June 1, 2022 12:49
is Success -> RegistrationResult.Complete(session)
}

sealed interface RegistrationResult {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what is the role of this interface ?
Which difference with: RegistrationWizardAction.Result ?
And why did you put Result in the Delegate class ?

Copy link
Contributor Author

@ouchadam ouchadam Jun 8, 2022

Choose a reason for hiding this comment

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

there's two layers/domains, the main difference is the split between generic SDK logic and Element specific things.

  • RegistrationWizardActionDelegate which handles the SDK flows (eg a 401 when sending the verification email is not actually an error), could argue this should be inside the SDK itself but wanted to avoid too much scope creep

  • RegistrationActionHandler which is Element's integration with the onboarding stages, technically it only needs to process the NextStep, the other result types are passed through. Element reorders the onboarding steps for Matrix.org, ignores certain results from the wizard and simplifies the flow so that clients of RegistrationActionHandler only know about the next Stage

The Results are needed because both layers have multiple different outcomes

Element's integration layer provides additional cases around the handling of the next registration step

StartRegistration 
NextStage
MissingNextStage 
UnsupportedStage 
RegistrationComplete
SendEmailSuccess
Error
Ignored 

SDK

Error
Complete
NextStep
SendEmailSuccess

Hopefully the tests help show the difference 🤞 SDK Delegate | Element intergration

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for the explanation :)

@ouchadam ouchadam force-pushed the feature/adm/ftue-register-test-cases branch from 0fd67ba to 6d281ff Compare June 8, 2022 09:37
@ouchadam ouchadam force-pushed the feature/adm/ftue-register-test-cases branch from 6d281ff to befcfe8 Compare June 9, 2022 07:52
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 9, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@fedrunov fedrunov left a comment

Choose a reason for hiding this comment

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

LGTM

data class AddThreePid(val threePid: RegisterThreePid) : RegisterAction
object SendAgainThreePid : RegisterAction
private fun findNextStage(state: SelectedHomeserverState, flowResult: FlowResult): Result {
val orderedResult = when {
Copy link
Contributor

@fedrunov fedrunov Jun 14, 2022

Choose a reason for hiding this comment

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

I think if would be much more readable here. when doesn't look good with complex conditions. But I won't insist

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've been using when specifically for those types of cases 🙈

@ouchadam ouchadam requested a review from Claire1817 June 14, 2022 15:25
@ouchadam ouchadam merged commit b78fb53 into develop Jun 16, 2022
@ouchadam ouchadam deleted the feature/adm/ftue-register-test-cases branch June 16, 2022 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants