Skip to content

Conversation

@Zafouche
Copy link
Collaborator

@Zafouche Zafouche commented Oct 30, 2024

Description

It was noted in the MS1 grading that there was an issue with device orientation: When the device is rotated in the Explore page, the app is redirected to the Home Screen.
The same bug is present when we switch from light to dark mode, and vice-versa.

Testing this shows that the bug is present in all screens. The bug cannot only be in the Explore screen as it does not define the behavior of our NavHost.
The addition of the auth state listener to is the problem. It is done each time the UnioApp composable is recomputed.

Changes

Edit 1:

Extracting the logic from the MainActivity and putting it into WelcomeScreen with the rest of the login logic fixes the bug.
I am still having issues with writing tests for this logic, but the bug is gone!
⚠️ This modification also fixes the dark mode activation bug, which also caused the app to take us back to the Home Screen. It is expected that it fixes all bugs of this type, e.g. due to the refresh.

Edit 2:

The changes from Edit 1 were not compatible with new updates that were made in the main branch during the development of this bug fix.
This is what I ended up doing:

  • Created an the view model AuthViewModel, that handles the logic of the Auth State listener and its state
  • Integrated the view model in the MainActivity in a manner that fixes the bug, e.g. it remembers the state of the login and which screen it was on.
    This solution works and the view model has been tested.

Testing

The login logic in AuthViewModel has been tested to ensure the state transitioning is correct.

- Used factory instantiation for the view model that have it a disposal
- Made HomeScreen use the global event view model instead of initializing a new one
- Removed a code block that shouldn't be there (from a merge error perhaps)
- Moved login logic from MainActivity to WelcomeScreen
- Added a UserRepositoryFirestore parameter to WelcomeScreen for the login logic
- Adapted the existing tests to the addition of the parameter
@Zafouche Zafouche marked this pull request as ready for review October 30, 2024 20:58
@Zafouche
Copy link
Collaborator Author

Zafouche commented Oct 30, 2024

All I have left is to test this logic in the Welcome test file.

Added tests that check that the logic in the Auth state listener (that was moved to the Welcome screen) is well implemented. This includes:
- Test that checks the behavior when the user returned is null
- Test that checks the behavior when the user is authenticated and has verified his email
- Test that checks the behavior when the user is authenticated and has verified his email, but does not have his name profile
- Test that checks the behavior when the user is authenticated but hasn't verified his email
- Test that checks the behavior when the user is not authenticated
This test corresponds to a slightly different login logic which was changed in the previous commit, hence this test deletion.
This was originally for a new test to test Toast displays, however it is not possible without Kaspresso.
@Zafouche Zafouche requested a review from Redd87 October 31, 2024 16:45
@Zafouche
Copy link
Collaborator Author

Ready to be reviewed and merged.

Copy link
Collaborator

@Redd87 Redd87 left a comment

Choose a reason for hiding this comment

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

A solid pull request, good work overall! When you merge you'll have conflict in the Main as I reordered the initialization of the repos and viewmodels, so be aware of that.

@Zafouche
Copy link
Collaborator Author

A solid pull request, good work overall! When you merge you'll have conflict in the Main as I reordered the initialization of the repos and viewmodels, so be aware of that.

Thanks, will resolve the conflicts and merge.

@Zafouche
Copy link
Collaborator Author

Zafouche commented Oct 31, 2024

Fix does not work after updating the branch with main. Can't quite figure out why.
No merging for now, we'll have to look into it after the meeting.

@Zafouche
Copy link
Collaborator Author

Zafouche commented Nov 3, 2024

A solution to the bug was found through the usage of an authentication view model. Please see Edit 2 of the main description of the PR quoted below:

Edit 2:

The changes from Edit 1 were not compatible with new updates that were made in the main branch during the development of this bug fix. This is what I ended up doing:

  • Created an the view model AuthViewModel, that handles the logic of the Auth State listener and its state
  • Integrated the view model in the MainActivity in a manner that fixes the bug, e.g. it remembers the state of the login and which screen it was on.
    This solution works and the view model has been tested.

This effectively fixes the bug that redirects the user to the Home Screen whenever the app composable was refreshed, caused by, for example, a switch between light and dark mode or a rotation of the screen.

@Zafouche Zafouche requested a review from Redd87 November 3, 2024 21:58
@Zafouche Zafouche requested a review from oskar-codes November 3, 2024 21:58
Copy link
Collaborator

@oskar-codes oskar-codes left a comment

Choose a reason for hiding this comment

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

Incredible work on this 🎉
This is a much needed fix for an issue that could have caused us some real trouble. I pointed out a few minor changes you could address, but I gladly approve this pull request.

- Modified the if statement in navigateTo(screen: String)
- Added edge case to navigateTo(tld: TopLevelDestination)
This should already be taken care of by the launchSingleTop property.
@Zafouche
Copy link
Collaborator Author

Zafouche commented Nov 3, 2024

Incredible work on this 🎉 This is a much needed fix for an issue that could have caused us some real trouble. I pointed out a few minor changes you could address, but I gladly approve this pull request.

Thank you! Your points have been taken into account and I have made the necessary changes.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 3, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
67.39% Line Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@Zafouche Zafouche merged commit 15f119a into main Nov 3, 2024
1 of 2 checks passed
@Zafouche Zafouche deleted the fix/navigation-reset-on-rotation branch November 3, 2024 23:55
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.

Fix bug that keeps triggering the auth state listener destined for the login logic

4 participants