-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move UI State Management variables from ClockPageViewModel to ClockPa…
…geViewModelState object (#24) * Create ClockPageViewModelState class, move mutable state variables and function declarations into there. Some small cleanup. * Remove ClockPage component's dependency on ClockPageViewModel. Display ClockPage composable preview again! * Add doc comments for ClockPageViewModelState * Create default ClockPage component test * Move clockButtonEnabled and task dropdown logic to ClockPageViewModelState class. Create unit tests. * Move countdown text change components and functions to ClockPageViewModelState. Write unit tests for text changes. * Remove currCountDownSeconds and countDownEndTime from ClockPageViewModelState object * Add testTags to components, wrote some ClockPage automated compose tests. * Add default strings to EditTimerTextField, reenable compose layout test, write instrumented test for count down * Add count down instrumented tests * Add divider to EditTimerTextField and string resources
- Loading branch information
1 parent
3b3833b
commit 61679ad
Showing
14 changed files
with
753 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
app/src/androidTest/java/com/nickspatties/timeclock/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
126 changes: 126 additions & 0 deletions
126
app/src/androidTest/java/com/nickspatties/timeclock/ui/pages/ClockPageTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package com.nickspatties.timeclock.ui.pages | ||
|
||
import androidx.compose.ui.test.* | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.nickspatties.timeclock.R | ||
import com.nickspatties.timeclock.ui.theme.TimeClockTheme | ||
import com.nickspatties.timeclock.ui.viewmodel.ClockPageViewModelState | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class ClockPageTest { | ||
|
||
private val context = InstrumentationRegistry.getInstrumentation().targetContext | ||
|
||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun countUp_defaultConfiguration() { | ||
composeTestRule.setContent { | ||
TimeClockTheme { | ||
val fakeViewModelState = ClockPageViewModelState() | ||
ClockPage(viewModelState = fakeViewModelState) | ||
} | ||
} | ||
composeTestRule.onNodeWithTag("TaskTextField").assertIsEnabled() | ||
composeTestRule.onNodeWithTag("StartTimerButton") | ||
.assertIsNotEnabled() | ||
.assertTextEquals(context.getString(R.string.start)) | ||
} | ||
|
||
@Test | ||
fun countUp_StartTimerButtonEnabledWhenTextIsInTaskTextField() { | ||
val testString = context.getString(R.string.start) | ||
composeTestRule.setContent { | ||
TimeClockTheme { | ||
val fakeViewModelState = ClockPageViewModelState() | ||
ClockPage(viewModelState = fakeViewModelState) | ||
} | ||
} | ||
composeTestRule.onNodeWithTag("TaskTextField").assertIsEnabled() | ||
composeTestRule.onNodeWithTag("TaskTextField").performTextInput("programming") | ||
composeTestRule.onNodeWithTag("StartTimerButton") | ||
.assertIsEnabled() | ||
.assertTextEquals(testString) | ||
} | ||
|
||
@Test | ||
fun taskNameDropdown_dropdownAppearsAndTaskFillsInWhenLabelIsClicked() { | ||
composeTestRule.setContent { | ||
TimeClockTheme { | ||
ClockPage(viewModelState = | ||
ClockPageViewModelState( | ||
autofillTaskNames = setOf( | ||
"programming", | ||
"reading" | ||
) | ||
) | ||
) | ||
} | ||
} | ||
composeTestRule.onNodeWithTag("TaskTextField").performTextInput("pro") | ||
composeTestRule.onNodeWithTag("DropdownMenuItem_programming").performClick() | ||
composeTestRule.onNodeWithTag("TaskTextField", useUnmergedTree = true) | ||
.assertTextEquals("programming") | ||
} | ||
|
||
@Test | ||
fun countDown_defaultConfiguration() { | ||
composeTestRule.setContent { | ||
TimeClockTheme { | ||
ClockPage(viewModelState = ClockPageViewModelState( | ||
countDownTimerEnabled = true | ||
)) | ||
} | ||
} | ||
composeTestRule.onNodeWithTag("TaskTextField").assertIsEnabled() | ||
composeTestRule.onNodeWithTag("TimerTextField_Hours").assertIsEnabled() | ||
composeTestRule.onNodeWithTag("TimerTextField_Minutes").assertIsEnabled() | ||
composeTestRule.onNodeWithTag("TimerTextField_Seconds").assertIsEnabled() | ||
composeTestRule.onNodeWithTag("StartTimerButton") | ||
.assertIsNotEnabled() | ||
.assertTextEquals(context.getString(R.string.start)) | ||
} | ||
|
||
@Test | ||
fun countDown_StartTimerButtonStillDisabledIfTaskNameIsNotEmptyAndTimeIsZero() { | ||
composeTestRule.setContent { | ||
TimeClockTheme { | ||
ClockPage(viewModelState = ClockPageViewModelState( | ||
countDownTimerEnabled = true | ||
)) | ||
} | ||
} | ||
composeTestRule.onNodeWithTag("TaskTextField").performTextInput("programming") | ||
composeTestRule.onNodeWithTag("StartTimerButton").assertIsNotEnabled() | ||
} | ||
|
||
@Test | ||
fun countDown_StartTimerButtonStillDisabledIfTaskNameIsEmptyTimeIsNotZero() { | ||
composeTestRule.setContent { | ||
TimeClockTheme { | ||
ClockPage(viewModelState = ClockPageViewModelState( | ||
countDownTimerEnabled = true | ||
)) | ||
} | ||
} | ||
composeTestRule.onNodeWithTag("TimerTextField_Minutes").performTextInput("1") | ||
composeTestRule.onNodeWithTag("StartTimerButton").assertIsNotEnabled() | ||
} | ||
|
||
@Test | ||
fun countDown_StartTimerButtonEnabledIfTaskNameIsNotEmptyAndTimeIsNonZero() { | ||
composeTestRule.setContent { | ||
TimeClockTheme { | ||
ClockPage(viewModelState = ClockPageViewModelState( | ||
countDownTimerEnabled = true | ||
)) | ||
} | ||
} | ||
composeTestRule.onNodeWithTag("TaskTextField").performTextInput("programming") | ||
composeTestRule.onNodeWithTag("TimerTextField_Minutes").performTextInput("1") | ||
composeTestRule.onNodeWithTag("StartTimerButton").assertIsEnabled() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.