-
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.
- Loading branch information
Showing
8 changed files
with
423 additions
and
5 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
.../androidTest/java/com/app/whakaara/onboarding/DisableBatteryOptimizationOnboardingTest.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,30 @@ | ||
package com.app.whakaara.onboarding | ||
|
||
import androidx.compose.ui.test.assertHasClickAction | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import com.app.whakaara.ui.onboarding.DisableBatteryOptimizationOnboarding | ||
import com.app.whakaara.ui.theme.WhakaaraTheme | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class DisableBatteryOptimizationOnboardingTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun shouldDisplayCorrectData(): Unit = with(composeTestRule) { | ||
// Given + When | ||
setContent { | ||
WhakaaraTheme { | ||
DisableBatteryOptimizationOnboarding() | ||
} | ||
} | ||
|
||
// Then | ||
onNodeWithText("Battery").assertIsDisplayed() | ||
onNodeWithText("This app requires unrestricted battery settings, otherwise certain functionality may not work as expected!").assertIsDisplayed() | ||
onNodeWithText("Disable battery optimization").assertIsDisplayed().assertHasClickAction() | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/androidTest/java/com/app/whakaara/onboarding/NotificationsOnboardingTest.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,33 @@ | ||
package com.app.whakaara.onboarding | ||
|
||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.ui.test.assertHasClickAction | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import com.app.whakaara.ui.onboarding.NotificationsOnboarding | ||
import com.app.whakaara.ui.theme.WhakaaraTheme | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class NotificationsOnboardingTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun shouldDisplayCorrectData(): Unit = with(composeTestRule) { | ||
// Given + When | ||
setContent { | ||
WhakaaraTheme { | ||
NotificationsOnboarding( | ||
snackbarHostState = SnackbarHostState() | ||
) | ||
} | ||
} | ||
|
||
// Then | ||
onNodeWithText("Notifications").assertIsDisplayed() | ||
onNodeWithText("This app requires permission to send you notifications!").assertIsDisplayed() | ||
onNodeWithText("Enable notifications").assertIsDisplayed().assertHasClickAction() | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/androidTest/java/com/app/whakaara/onboarding/WelcomeOnboardingTest.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,30 @@ | ||
package com.app.whakaara.onboarding | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithContentDescription | ||
import androidx.compose.ui.test.onNodeWithText | ||
import com.app.whakaara.ui.onboarding.WelcomeOnboarding | ||
import com.app.whakaara.ui.theme.WhakaaraTheme | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class WelcomeOnboardingTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun shouldDisplayCorrectData(): Unit = with(composeTestRule) { | ||
// Given + When | ||
setContent { | ||
WhakaaraTheme { | ||
WelcomeOnboarding() | ||
} | ||
} | ||
|
||
// Then | ||
onNodeWithText("Widget").assertIsDisplayed() | ||
onNodeWithText("This screen will guide you through the most important setup steps").assertIsDisplayed() | ||
onNodeWithContentDescription("whakaara app icon").assertIsDisplayed() | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/androidTest/java/com/app/whakaara/onboarding/WidgetOnboardingTest.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,31 @@ | ||
package com.app.whakaara.onboarding | ||
|
||
import androidx.compose.ui.test.assertHasClickAction | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import com.app.whakaara.ui.onboarding.WidgetOnboarding | ||
import com.app.whakaara.ui.theme.WhakaaraTheme | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class WidgetOnboardingTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun shouldDisplayCorrectData(): Unit = with(composeTestRule) { | ||
// Given + When | ||
setContent { | ||
WhakaaraTheme { | ||
WidgetOnboarding() | ||
} | ||
} | ||
|
||
// Then | ||
onNodeWithText("Widget").assertIsDisplayed() | ||
onNodeWithText("This app supports displaying your next scheduled alarm in a widget").assertIsDisplayed() | ||
onNodeWithText("Try adding it to the home screen and using it!").assertIsDisplayed() | ||
onNodeWithText("Create widget").assertIsDisplayed().assertHasClickAction() | ||
} | ||
} |
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
217 changes: 217 additions & 0 deletions
217
app/src/test/java/com/app/whakaara/logic/StopwatchManagerTest.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,217 @@ | ||
package com.app.whakaara.logic | ||
|
||
import android.app.Application | ||
import android.app.NotificationManager | ||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule | ||
import androidx.core.app.NotificationCompat | ||
import app.cash.turbine.test | ||
import com.app.whakaara.data.datastore.PreferencesDataStore | ||
import com.app.whakaara.state.Lap | ||
import com.app.whakaara.state.StopwatchState | ||
import io.mockk.Runs | ||
import io.mockk.coEvery | ||
import io.mockk.just | ||
import io.mockk.mockk | ||
import io.mockk.slot | ||
import io.mockk.verify | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.StandardTestDispatcher | ||
import kotlinx.coroutines.test.TestScope | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.coroutines.test.setMain | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TestRule | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class StopwatchManagerTest { | ||
@Rule | ||
@JvmField | ||
var rule: TestRule = InstantTaskExecutorRule() | ||
|
||
private val testDispatcher = StandardTestDispatcher() | ||
|
||
private lateinit var stopwatchManagerWrapper: StopwatchManagerWrapper | ||
private lateinit var app: Application | ||
private lateinit var notificationManager: NotificationManager | ||
private lateinit var stopwatchNotificationBuilder: NotificationCompat.Builder | ||
private lateinit var coroutineScope: CoroutineScope | ||
private lateinit var preferencesDatastore: PreferencesDataStore | ||
private val managedCoroutineScope = TestScope(testDispatcher) | ||
private val id = 400 | ||
|
||
@Before | ||
fun setUp() { | ||
Dispatchers.setMain(testDispatcher) | ||
app = mockk() | ||
notificationManager = mockk() | ||
stopwatchNotificationBuilder = mockk() | ||
coroutineScope = mockk() | ||
preferencesDatastore = mockk() | ||
stopwatchManagerWrapper = StopwatchManagerWrapper(app, notificationManager, stopwatchNotificationBuilder, managedCoroutineScope, preferencesDatastore) | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
Dispatchers.resetMain() | ||
} | ||
|
||
@Test | ||
fun `pause stopwatch`() = runTest { | ||
// Given | ||
val notificationId = slot<Int>() | ||
coEvery { notificationManager.cancel(any()) } just Runs | ||
|
||
// When | ||
stopwatchManagerWrapper.pauseStopwatch() | ||
|
||
// Then | ||
verify(exactly = 1) { notificationManager.cancel(capture(notificationId)) } | ||
assertEquals(id, notificationId.captured) | ||
stopwatchManagerWrapper.stopwatchState.test { | ||
val state = awaitItem() | ||
with(state) { | ||
assertEquals(false, isActive) | ||
assertEquals(true, isPaused) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `reset stopwatch`() = runTest { | ||
// Given | ||
val notificationId = slot<Int>() | ||
coEvery { notificationManager.cancel(any()) } just Runs | ||
|
||
// When | ||
stopwatchManagerWrapper.resetStopwatch() | ||
|
||
// Then | ||
verify(exactly = 1) { notificationManager.cancel(capture(notificationId)) } | ||
assertEquals(id, notificationId.captured) | ||
stopwatchManagerWrapper.stopwatchState.test { | ||
val state = awaitItem() | ||
with(state) { | ||
assertEquals(0L, timeMillis) | ||
assertEquals(0L, lastTimeStamp) | ||
assertEquals("00:00:00:000", formattedTime) | ||
assertEquals(false, isActive) | ||
assertEquals(true, isStart) | ||
assertEquals(false, isPaused) | ||
assert(lapList.isEmpty()) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `lap stopwatch empty list`() = runTest { | ||
// Given | ||
val current = 123123L | ||
stopwatchManagerWrapper.stopwatchState.value = StopwatchState( | ||
timeMillis = current | ||
) | ||
|
||
// When | ||
stopwatchManagerWrapper.lapStopwatch() | ||
|
||
// Then | ||
stopwatchManagerWrapper.stopwatchState.test { | ||
val state = awaitItem() | ||
with(state) { | ||
assert(lapList.isNotEmpty()) | ||
assertEquals(1, lapList.size) | ||
assertEquals(current, lapList.first().diff) | ||
assertEquals(current, lapList.first().time) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `lap stopwatch not empty list`() = runTest { | ||
// Given | ||
val current = 123123L | ||
stopwatchManagerWrapper.stopwatchState.value = StopwatchState( | ||
timeMillis = current, | ||
lapList = mutableListOf( | ||
Lap( | ||
time = 123L, | ||
diff = 123L | ||
), | ||
Lap( | ||
time = 456L, | ||
diff = 456L | ||
) | ||
) | ||
) | ||
|
||
// When | ||
stopwatchManagerWrapper.lapStopwatch() | ||
|
||
// Then | ||
stopwatchManagerWrapper.stopwatchState.test { | ||
val state = awaitItem() | ||
with(state) { | ||
assert(lapList.isNotEmpty()) | ||
assertEquals(3, lapList.size) | ||
assertEquals(123123, lapList.last().time) | ||
assertEquals(122667, lapList.last().diff) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `recreate stopwatch paused`() = runTest { | ||
// Given | ||
val pausedState = StopwatchState( | ||
isPaused = true, | ||
isActive = false, | ||
isStart = false, | ||
timeMillis = 112233L, | ||
formattedTime = "11:22:33:444", | ||
lapList = mutableListOf( | ||
Lap( | ||
time = 420L, | ||
diff = 420L | ||
) | ||
) | ||
) | ||
|
||
// When | ||
stopwatchManagerWrapper.recreateStopwatchPaused(state = pausedState) | ||
|
||
// Then | ||
stopwatchManagerWrapper.stopwatchState.test { | ||
val state = awaitItem() | ||
with(state) { | ||
assertEquals(true, isPaused) | ||
assertEquals(false, isActive) | ||
assertEquals(false, isStart) | ||
assertEquals(112233L, timeMillis) | ||
assertEquals("11:22:33:444", formattedTime) | ||
assertEquals(1, lapList.size) | ||
assertEquals(420L, lapList.first().time) | ||
assertEquals(420L, lapList.first().diff) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `cancel notification`() = runTest { | ||
// Given | ||
val notificationId = slot<Int>() | ||
coEvery { notificationManager.cancel(any()) } just Runs | ||
|
||
// When | ||
stopwatchManagerWrapper.cancelNotification() | ||
|
||
// Then | ||
verify(exactly = 1) { notificationManager.cancel(capture(notificationId)) } | ||
assertEquals(id, notificationId.captured) | ||
} | ||
} |
Oops, something went wrong.