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

Move UI State Management variables from ClockPageViewModel to ClockPageViewModelState object #24

Merged
merged 11 commits into from
Aug 9, 2022

Conversation

NicksPatties
Copy link
Owner

Purpose

Quickly testing functionality of elements in the ClockPage is a hassle. Creating a test version of a ClockPageViewModel was annoying for a few reasons.

  • Intents declared as properties in ClockPageViewModel would cause compose previews to break, rendering those previews useless.
  • Testing the state of components after certain interactions was dependent on the DAO and UserPreferences, even though they had nothing to do with what was being tested (for instance, the relationship between `
  • Creating fake UserPreferencesRepository, a dependency of ClockPageViewModel, is a pain. No easy way to create one that returns specific preferences. This was almost remedied by lifting the repository out of the ClockPageViewModel, and only passed the repo's flow property into the ClockPageViewModel, but it still wasn't the solution I wanted.

To that end, I created the ClockPageViewModelState class, which serves as a layer between the ClockPageViewModel's event data and user preferences, and the UI components. Some benefits:

  • This class can be constructed and configured very easily, allowing different test cases to be quickly represented.
  • Made it easier to find state properties that were dependent on other properties. Properly implementing them mean they're less likely to break when changes to state occur.
  • Instrumented tests that act upon the whole ClockPage component are possible! Much easier to automate those tests on different emulated devices to catch errors in different SDK versions and devices! (Still hasn't been automated via builds yet, but that may or may not happen)
  • Unit tests that are automated can simulate UI interactions now by calling some property methods!

Changes

Lots... but the big ones are:

  • Creation of ClockPageViewModelState class, and migrating some properties from ClockPageViewModel to there.
  • Adding testTags to components in the ClockPage component. Some import and code cleanup.
  • Adding unit tests and instrumented tests for ClockPage behavior

Related issue

None. This was just some code cleanliness stuff that was nagging me.

Testing

  • Unit tests pass
  • Ran integration tests on emulator running API 30

app/build.gradle Show resolved Hide resolved
modifier = Modifier.testTag("DropdownMenuItem_${label}"),
onClick = {
if (viewModelState.countDownTimerEnabled) {
focusManager.moveFocus(FocusDirection.Next)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Something for later, but can this logic be moved into the ClockPageViewModelState class, or at least the currently focused object.

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