Skip to content

Commit

Permalink
Revert "✅ Allow some test class to be flaky (#318)"
Browse files Browse the repository at this point in the history
This reverts commit 4b9454f
  • Loading branch information
igorescodro committed Oct 12, 2022
1 parent 89f0684 commit 7f4bc66
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 102 deletions.
14 changes: 11 additions & 3 deletions app/src/androidTest/java/com/escodro/alkaa/CategoryFlowTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
Expand All @@ -15,18 +16,25 @@ import com.escodro.alkaa.navigation.NavGraph
import com.escodro.category.presentation.semantics.ColorKey
import com.escodro.designsystem.AlkaaTheme
import com.escodro.local.provider.DaoProvider
import com.escodro.test.FlakyTest
import com.escodro.test.DisableAnimationsRule
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.koin.test.KoinTest
import org.koin.test.inject
import com.escodro.category.R as CategoryR

internal class CategoryFlowTest : FlakyTest(), KoinTest {
internal class CategoryFlowTest : KoinTest {

private val daoProvider: DaoProvider by inject()

@get:Rule
val composeTestRule = createComposeRule()

@get:Rule
val disableAnimationsRule = DisableAnimationsRule()

private val context = InstrumentationRegistry.getInstrumentation().targetContext

@Before
Expand All @@ -36,7 +44,7 @@ internal class CategoryFlowTest : FlakyTest(), KoinTest {
daoProvider.getCategoryDao().cleanTable()
}

setContent {
composeTestRule.setContent {
AlkaaTheme {
NavGraph()
}
Expand Down
14 changes: 11 additions & 3 deletions app/src/androidTest/java/com/escodro/alkaa/HomeScreenTest.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
package com.escodro.alkaa

import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.platform.app.InstrumentationRegistry
import com.escodro.alkaa.model.HomeSection
import com.escodro.alkaa.navigation.NavGraph
import com.escodro.designsystem.AlkaaTheme
import com.escodro.test.FlakyTest
import com.escodro.test.DisableAnimationsRule
import org.junit.Before
import org.junit.Rule
import org.junit.Test

internal class HomeScreenTest : FlakyTest() {
internal class HomeScreenTest {

@get:Rule
val composeTestRule = createComposeRule()

@get:Rule
val disableAnimationsRule = DisableAnimationsRule()

private val context = InstrumentationRegistry.getInstrumentation().targetContext

@Before
fun setup() {
setContent {
composeTestRule.setContent {
AlkaaTheme {
NavGraph()
}
Expand Down
14 changes: 11 additions & 3 deletions app/src/androidTest/java/com/escodro/alkaa/NotificationFlowTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.escodro.alkaa
import android.app.Notification
import androidx.annotation.StringRes
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 androidx.test.platform.app.InstrumentationRegistry
Expand All @@ -14,10 +15,11 @@ import com.escodro.local.model.AlarmInterval
import com.escodro.local.model.Task
import com.escodro.local.provider.DaoProvider
import com.escodro.task.R
import com.escodro.test.FlakyTest
import com.escodro.test.DisableAnimationsRule
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.koin.test.KoinTest
import org.koin.test.inject
Expand All @@ -26,12 +28,18 @@ import kotlin.test.assertEquals
import kotlin.test.assertTrue
import com.escodro.alarm.R as AlarmR

internal class NotificationFlowTest : FlakyTest(), KoinTest {
internal class NotificationFlowTest : KoinTest {

private val daoProvider: DaoProvider by inject()

private val scheduleAlarm: ScheduleAlarm by inject()

@get:Rule
val composeTestRule = createComposeRule()

@get:Rule
val disableAnimationsRule = DisableAnimationsRule()

private val context = InstrumentationRegistry.getInstrumentation().targetContext

@Before
Expand All @@ -40,7 +48,7 @@ internal class NotificationFlowTest : FlakyTest(), KoinTest {
runBlocking {
daoProvider.getTaskDao().cleanTable()
}
setContent {
composeTestRule.setContent {
AlkaaTheme {
NavGraph()
}
Expand Down
14 changes: 11 additions & 3 deletions app/src/androidTest/java/com/escodro/alkaa/PreferenceFlowTest.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
package com.escodro.alkaa

import androidx.annotation.StringRes
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.platform.app.InstrumentationRegistry
import com.escodro.alkaa.navigation.NavGraph
import com.escodro.core.extension.getVersionName
import com.escodro.test.FlakyTest
import com.escodro.test.DisableAnimationsRule
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import com.escodro.core.R as CoreR
import com.escodro.preference.R as PrefR

internal class PreferenceFlowTest : FlakyTest() {
internal class PreferenceFlowTest {

@get:Rule
val composeTestRule = createComposeRule()

@get:Rule
val disableAnimationsRule = DisableAnimationsRule()

private val context = InstrumentationRegistry.getInstrumentation().targetContext

@Before
fun setup() {
setContent {
composeTestRule.setContent {
NavGraph()
}
navigateToPreferences()
Expand Down
14 changes: 11 additions & 3 deletions app/src/androidTest/java/com/escodro/alkaa/SearchFlowTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.escodro.alkaa

import androidx.annotation.StringRes
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
Expand All @@ -12,18 +13,25 @@ import com.escodro.alkaa.fake.FAKE_TASKS
import com.escodro.alkaa.navigation.NavGraph
import com.escodro.designsystem.AlkaaTheme
import com.escodro.local.provider.DaoProvider
import com.escodro.test.FlakyTest
import com.escodro.test.DisableAnimationsRule
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.koin.test.KoinTest
import org.koin.test.inject
import com.escodro.search.R as SearchR

internal class SearchFlowTest : FlakyTest(), KoinTest {
internal class SearchFlowTest : KoinTest {

private val daoProvider: DaoProvider by inject()

@get:Rule
val composeTestRule = createComposeRule()

@get:Rule
val disableAnimationsRule = DisableAnimationsRule()

private val context = InstrumentationRegistry.getInstrumentation().targetContext

@Before
Expand All @@ -36,7 +44,7 @@ internal class SearchFlowTest : FlakyTest(), KoinTest {
FAKE_TASKS.forEach { task -> daoProvider.getTaskDao().insertTask(task) }
}

setContent {
composeTestRule.setContent {
AlkaaTheme {
NavGraph()
}
Expand Down
14 changes: 11 additions & 3 deletions app/src/androidTest/java/com/escodro/alkaa/TaskFlowTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.escodro.alkaa
import androidx.annotation.StringRes
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
Expand All @@ -15,22 +16,29 @@ import com.escodro.core.coroutines.CoroutineDebouncer
import com.escodro.designsystem.AlkaaTheme
import com.escodro.local.model.Category
import com.escodro.local.provider.DaoProvider
import com.escodro.test.DisableAnimationsRule
import com.escodro.test.Events
import com.escodro.test.FlakyTest
import com.escodro.test.onChip
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.koin.test.KoinTest
import org.koin.test.inject
import org.koin.test.mock.declare
import java.util.Calendar
import com.escodro.task.R as TaskR

internal class TaskFlowTest : FlakyTest(), KoinTest {
internal class TaskFlowTest : KoinTest {

private val daoProvider: DaoProvider by inject()

@get:Rule
val composeTestRule = createComposeRule()

@get:Rule
val disableAnimationsRule = DisableAnimationsRule()

private val context = InstrumentationRegistry.getInstrumentation().targetContext

@Before
Expand All @@ -50,7 +58,7 @@ internal class TaskFlowTest : FlakyTest(), KoinTest {
// Replace Debouncer with a Immediate Executor
declare<CoroutineDebouncer> { CoroutinesDebouncerFake() }

setContent {
composeTestRule.setContent {
AlkaaTheme {
NavGraph()
}
Expand Down
14 changes: 11 additions & 3 deletions app/src/androidTest/java/com/escodro/alkaa/TaskListFlowTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.annotation.StringRes
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.hasSetTextAction
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
Expand All @@ -15,18 +16,25 @@ import com.escodro.designsystem.AlkaaTheme
import com.escodro.local.model.Category
import com.escodro.local.provider.DaoProvider
import com.escodro.task.presentation.list.CheckboxNameKey
import com.escodro.test.FlakyTest
import com.escodro.test.DisableAnimationsRule
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.koin.test.KoinTest
import org.koin.test.inject
import com.escodro.task.R as TaskR

internal class TaskListFlowTest : FlakyTest(), KoinTest {
internal class TaskListFlowTest : KoinTest {

private val daoProvider: DaoProvider by inject()

@get:Rule
val composeTestRule = createComposeRule()

@get:Rule
val disableAnimationsRule = DisableAnimationsRule()

private val context = InstrumentationRegistry.getInstrumentation().targetContext

@Before
Expand All @@ -42,7 +50,7 @@ internal class TaskListFlowTest : FlakyTest(), KoinTest {
getCategoryDao().insertCategory(Category(name = "Work", color = "#519872"))
}
}
setContent {
composeTestRule.setContent {
AlkaaTheme {
NavGraph()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
package com.escodro.task

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.junit4.createEmptyComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.core.app.ActivityScenario
import androidx.test.platform.app.InstrumentationRegistry
import com.escodro.designsystem.AlkaaTheme
import com.escodro.task.fake.PermissionStateFake
import com.escodro.task.presentation.detail.alarm.AlarmSelectionContent
import com.escodro.task.presentation.detail.alarm.AlarmSelectionState
import com.escodro.test.FlakyTest
import com.escodro.test.DisableAnimationsRule
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.PermissionState
import com.google.accompanist.permissions.PermissionStatus
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@OptIn(ExperimentalPermissionsApi::class)
internal class AlarmPermissionFlowTest : FlakyTest() {
internal class AlarmPermissionFlowTest {

@get:Rule
val composeTestRule = createEmptyComposeRule()

@get:Rule
val disableAnimationsRule = DisableAnimationsRule()

private val context = InstrumentationRegistry.getInstrumentation().targetContext

private lateinit var scenario: ActivityScenario<ComponentActivity>

@Before
fun setup() {
scenario = ActivityScenario.launch(ComponentActivity::class.java)
}

@After
fun tearDown() {
scenario.close()
}

@Test
fun test_notificationPermissionGrantedDoesNotShowDialog() {
val state = AlarmSelectionState(calendar = null, alarmInterval = null)
Expand Down Expand Up @@ -123,16 +148,18 @@ internal class AlarmPermissionFlowTest : FlakyTest() {
permissionState: PermissionState,
hasAlarmPermission: Boolean
) {
setContent {
AlkaaTheme {
AlarmSelectionContent(
context = LocalContext.current,
state = state,
permissionState = permissionState,
hasAlarmPermission = { hasAlarmPermission },
onAlarmUpdate = {},
onIntervalSelect = {}
)
scenario.onActivity { activity ->
activity.setContent {
AlkaaTheme {
AlarmSelectionContent(
context = LocalContext.current,
state = state,
permissionState = permissionState,
hasAlarmPermission = { hasAlarmPermission },
onAlarmUpdate = {},
onIntervalSelect = {}
)
}
}
}
}
Expand Down
Loading

0 comments on commit 7f4bc66

Please sign in to comment.