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

Test register screen composable #3062

Merged
merged 53 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
11e00d1
Testing Register Screen
Raynafs Feb 12, 2024
da935ba
Testing Register Screen
Raynafs Feb 12, 2024
0df184a
Testing Register Screen
Raynafs Feb 12, 2024
fe8e3a4
Testing Register Screen
Raynafs Feb 12, 2024
61a0435
Testing Register Screen
Raynafs Feb 12, 2024
319557e
Merge branch 'main' into test-register-screen-composable
SebaMutuku Feb 13, 2024
f8e63cf
Add resource type files
Raynafs Feb 14, 2024
e36d913
Register Screen Test
Raynafs Feb 15, 2024
dc7056b
Register Screen Test
Raynafs Feb 15, 2024
0b5fe60
Merge branch 'main' into test-register-screen-composable
Raynafs Feb 16, 2024
6b6a726
Clean code
Raynafs Feb 16, 2024
f8e352a
Change testTag name
Raynafs Feb 16, 2024
526fb19
Merge branch 'main' into test-register-screen-composable
SebaMutuku Feb 20, 2024
09a16b3
Add fab test
Raynafs Feb 22, 2024
68452c9
Merge remote-tracking branch 'origin/test-register-screen-composable'…
Raynafs Feb 22, 2024
7c7f980
Merge branch 'main' into test-register-screen-composable
Raynafs Feb 23, 2024
d08ea33
Merge branch 'main' into test-register-screen-composable
Raynafs Feb 26, 2024
d50a199
Merge branch 'main' into test-register-screen-composable
SebaMutuku Feb 26, 2024
98f436a
Merge branch 'main' into test-register-screen-composable
Raynafs Feb 26, 2024
ee764d9
Merge branch 'main' into test-register-screen-composable
Raynafs Feb 27, 2024
71a2fa7
Merge branch 'main' into test-register-screen-composable
Raynafs Feb 27, 2024
d389427
Add test to BooleanExtensionTest
Raynafs Feb 29, 2024
cfa5204
run spotless
Raynafs Mar 1, 2024
bc49a61
Merge branch 'main' into test-register-screen-composable
Raynafs Mar 4, 2024
545e136
Merge branch 'main' into test-register-screen-composable
Raynafs Mar 5, 2024
9ecc63e
Add pagination to list resource
Raynafs Mar 7, 2024
23771df
refactor test tags in register view model
Raynafs Mar 7, 2024
096ff74
change from onAllNodesWithTag to onNodeWithTag
Raynafs Mar 7, 2024
4c565e3
change from onAllNodesWithTag to onNodeWithTag
Raynafs Mar 7, 2024
13bedf6
add assert exist and is displayed
Raynafs Mar 7, 2024
3838ac4
Merge branch 'main' into test-register-screen-composable
Raynafs Mar 7, 2024
d4e5d41
Merge branch 'main' into test-register-screen-composable
Raynafs Mar 11, 2024
627e70a
edit register screen test
Raynafs Mar 11, 2024
9f800c8
refactor test tags
Raynafs Mar 12, 2024
29415ec
run spotless
Raynafs Mar 12, 2024
aeea87f
Merge branch 'main' into test-register-screen-composable
Raynafs Mar 12, 2024
f7f024f
Merge branch 'main' into test-register-screen-composable
Raynafs Mar 15, 2024
854dc7a
Merge branch 'main' into test-register-screen-composable
Raynafs Mar 15, 2024
035c32b
change modifier text
Raynafs Mar 15, 2024
5cb8641
change modifier text
Raynafs Mar 15, 2024
f09bcbc
update RegisterScreen
Raynafs Mar 15, 2024
25ef9b8
add modifier to called functions
Raynafs Mar 15, 2024
92925ce
add modifier to called functions
Raynafs Mar 15, 2024
7c4a133
add modifier to called functions
Raynafs Mar 16, 2024
813db61
add modifier to called functions
Raynafs Mar 17, 2024
dcd0c69
add modifier to called functions
Raynafs Mar 17, 2024
27563dc
add modifier to called functions
Raynafs Mar 17, 2024
1552b65
edit tests
Raynafs Mar 17, 2024
8ecca6f
edit tests
Raynafs Mar 17, 2024
f62a5f1
edit failing test
Raynafs Mar 17, 2024
293bf6b
editing tests
Raynafs Mar 17, 2024
d4c7e7a
Empty-Commit
Raynafs Mar 18, 2024
145a962
Merge branch 'main' into test-register-screen-composable
Raynafs Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fun LoaderDialog(
onDismissRequest = { openDialog.value = true },
properties = DialogProperties(dismissOnBackPress = true),
) {
Box(Modifier.size(240.dp, 180.dp)) {
Box(modifier.size(240.dp, 180.dp)) {
Column(
modifier = modifier.padding(8.dp),
verticalArrangement = Arrangement.Center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,208 @@

package org.smartregister.fhircore.quest.integration.ui.register

import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onChildAt
import androidx.compose.ui.test.onNodeWithTag
import androidx.navigation.compose.rememberNavController
import androidx.paging.PagingData
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.collectAsLazyPagingItems
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import io.mockk.mockk
import kotlinx.coroutines.flow.flowOf
import org.hl7.fhir.r4.model.ResourceType
import org.junit.Rule
import org.junit.Test
import org.smartregister.fhircore.engine.configuration.ConfigType
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.register.NoResultsConfig
import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.quest.integration.Faker
import org.smartregister.fhircore.quest.ui.register.FAB_BUTTON_REGISTER_TEST_TAG
import org.smartregister.fhircore.quest.ui.register.FIRST_TIME_SYNC_DIALOG
import org.smartregister.fhircore.quest.ui.register.NO_REGISTER_VIEW_COLUMN_TEST_TAG
import org.smartregister.fhircore.quest.ui.register.NoRegisterDataView
import org.smartregister.fhircore.quest.ui.register.REGISTER_CARD_TEST_TAG
import org.smartregister.fhircore.quest.ui.register.RegisterScreen
import org.smartregister.fhircore.quest.ui.register.RegisterUiState
import org.smartregister.fhircore.quest.ui.register.TOP_REGISTER_SCREEN_TEST_TAG

@HiltAndroidTest
class RegisterScreenTest {
@get:Rule val composeTestRule = createComposeRule()

@get:Rule val composeRegisterTestRule = createComposeRule()

private val noResults = NoResultsConfig()

@Before
fun setUp() {
@Test
fun testFloatingActionButtonIsDisplayed() {
val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
val registerUiState =
RegisterUiState(
screenTitle = "Register101",
isFirstTimeSync = false,
registerConfiguration =
configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"),
registerId = "register101",
totalRecordsCount = 1,
filteredRecordsCount = 0,
pagesCount = 0,
progressPercentage = flowOf(0),
isSyncUpload = flowOf(false),
params = emptyMap(),
)
val searchText = mutableStateOf("")
val currentPage = mutableStateOf(0)

composeTestRule.setContent {
NoRegisterDataView(modifier = Modifier, noResults = noResults, onClick = {})
val data = listOf(ResourceData("1", ResourceType.Patient, emptyMap()))

val pagingItems = flowOf(PagingData.from(data)).collectAsLazyPagingItems()

RegisterScreen(
modifier = Modifier,
openDrawer = {},
onEvent = {},
registerUiState = registerUiState,
searchText = searchText,
currentPage = currentPage,
pagingItems = pagingItems,
navController = rememberNavController(),
)
}
composeTestRule.waitUntil(5_000) { true }
composeTestRule.onAllNodesWithTag(FAB_BUTTON_REGISTER_TEST_TAG, useUnmergedTree = true)
}

@Test
fun testRegisterCardListIsRendered() {
val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
val registerUiState =
RegisterUiState(
screenTitle = "Register101",
isFirstTimeSync = false,
registerConfiguration =
configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"),
registerId = "register101",
totalRecordsCount = 1,
filteredRecordsCount = 0,
pagesCount = 1,
progressPercentage = flowOf(0),
isSyncUpload = flowOf(false),
params = emptyMap(),
)
val searchText = mutableStateOf("")
val currentPage = mutableStateOf(0)

composeTestRule.setContent {
val data = listOf(ResourceData("1", ResourceType.Patient, emptyMap()))

val pagingItems = flowOf(PagingData.from(data)).collectAsLazyPagingItems()

RegisterScreen(
modifier = Modifier,
openDrawer = {},
onEvent = {},
registerUiState = registerUiState,
searchText = searchText,
currentPage = currentPage,
pagingItems = pagingItems,
navController = rememberNavController(),
)
}

composeTestRule
.onNodeWithTag(REGISTER_CARD_TEST_TAG, useUnmergedTree = true)
.assertExists()
.assertIsDisplayed()
}

@Test
fun testThatDialogIsDisplayedDuringSyncing() {
val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
val registerUiState =
RegisterUiState(
screenTitle = "Register101",
isFirstTimeSync = true,
registerConfiguration =
configurationRegistry.retrieveConfiguration(ConfigType.Register, "childRegister"),
registerId = "register101",
totalRecordsCount = 0,
filteredRecordsCount = 0,
pagesCount = 1,
progressPercentage = flowOf(0),
isSyncUpload = flowOf(false),
params = emptyMap(),
)
val searchText = mutableStateOf("")
val currentPage = mutableStateOf(0)
val pagingItems = mockk<LazyPagingItems<ResourceData>>().apply {}

composeTestRule.setContent {
RegisterScreen(
modifier = Modifier,
openDrawer = {},
onEvent = {},
registerUiState = registerUiState,
searchText = searchText,
currentPage = currentPage,
pagingItems = pagingItems,
navController = rememberNavController(),
)
}
composeTestRule.onNodeWithTag(FIRST_TIME_SYNC_DIALOG, useUnmergedTree = true)
}

@Test
fun testThatTopScreenIsRendered() {
val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
val registerUiState =
RegisterUiState(
screenTitle = "Register101",
isFirstTimeSync = false,
registerConfiguration =
configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"),
registerId = "register101",
totalRecordsCount = 1,
filteredRecordsCount = 0,
pagesCount = 0,
progressPercentage = flowOf(0),
isSyncUpload = flowOf(false),
params = emptyMap(),
)
val searchText = mutableStateOf("")
val currentPage = mutableStateOf(0)

composeTestRule.setContent {
val data = listOf(ResourceData("1", ResourceType.Patient, emptyMap()))

val pagingItems = flowOf(PagingData.from(data)).collectAsLazyPagingItems()

RegisterScreen(
modifier = Modifier,
openDrawer = {},
onEvent = {},
registerUiState = registerUiState,
searchText = searchText,
currentPage = currentPage,
pagingItems = pagingItems,
navController = rememberNavController(),
)
}
composeTestRule.waitUntil(5_000) { true }
composeTestRule.onNodeWithTag(TOP_REGISTER_SCREEN_TEST_TAG, useUnmergedTree = true)
}

@Test
fun testNoRegisterDataViewDisplaysNoTestTag() {
composeTestRule.setContent {
NoRegisterDataView(modifier = Modifier, noResults = noResults, onClick = {})
}
composeTestRule
.onNodeWithTag(NO_REGISTER_VIEW_COLUMN_TEST_TAG, useUnmergedTree = true)
.assertExists()
Expand All @@ -56,13 +226,19 @@ class RegisterScreenTest {

@Test
fun testCountAllNodeNoRegisterDataViewDisplaysNoTestTag() {
composeTestRule.setContent {
NoRegisterDataView(modifier = Modifier, noResults = noResults, onClick = {})
}
composeTestRule
.onAllNodesWithTag(NO_REGISTER_VIEW_COLUMN_TEST_TAG, useUnmergedTree = true)
.assertCountEquals(1)
}

@Test
fun checkNodeWithNoRegisterViewColumTestTag() {
composeTestRule.setContent {
NoRegisterDataView(modifier = Modifier, noResults = noResults, onClick = {})
}
composeTestRule
.onNodeWithTag(NO_REGISTER_VIEW_COLUMN_TEST_TAG, useUnmergedTree = true)
.onChildAt(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Button
import androidx.compose.material.Icon
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
Expand Down Expand Up @@ -63,6 +63,10 @@
const val NO_REGISTER_VIEW_BUTTON_TEST_TAG = "noRegisterViewButtonTestTag"
const val NO_REGISTER_VIEW_BUTTON_ICON_TEST_TAG = "noRegisterViewButtonIconTestTag"
const val NO_REGISTER_VIEW_BUTTON_TEXT_TEST_TAG = "noRegisterViewButtonTextTestTag"
const val REGISTER_CARD_TEST_TAG = "registerCardListTestTag"
const val FIRST_TIME_SYNC_DIALOG = "firstTimeSyncTestTag"
const val FAB_BUTTON_REGISTER_TEST_TAG = "fabTestTag"
const val TOP_REGISTER_SCREEN_TEST_TAG = "topScreenTestTag"

@Composable
fun RegisterScreen(
Expand All @@ -80,52 +84,54 @@

Scaffold(
topBar = {
Column {
// Top section has toolbar and a results counts view
val filterActions = registerUiState.registerConfiguration?.registerFilter?.dataFilterActions
TopScreenSection(
title = registerUiState.screenTitle,
searchText = searchText.value,
filteredRecordsCount = registerUiState.filteredRecordsCount,
searchPlaceholder = registerUiState.registerConfiguration?.searchBar?.display,
toolBarHomeNavigation = toolBarHomeNavigation,
onSearchTextChanged = { searchText ->
onEvent(RegisterEvent.SearchRegister(searchText = searchText))
},
isFilterIconEnabled = filterActions?.isNotEmpty() ?: false,
) { event ->
when (event) {
ToolbarClickEvent.Navigate ->
when (toolBarHomeNavigation) {
ToolBarHomeNavigation.OPEN_DRAWER -> openDrawer(true)
ToolBarHomeNavigation.NAVIGATE_BACK -> navController.popBackStack()
}
ToolbarClickEvent.FilterData -> {
onEvent(RegisterEvent.ResetFilterRecordsCount)
filterActions?.handleClickEvent(navController)
// Top section has toolbar and a results counts view
val filterActions = registerUiState.registerConfiguration?.registerFilter?.dataFilterActions
TopScreenSection(
modifier = modifier.testTag(TOP_REGISTER_SCREEN_TEST_TAG),
title = registerUiState.screenTitle,
searchText = searchText.value,
filteredRecordsCount = registerUiState.filteredRecordsCount,

Check warning on line 93 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L89-L93

Added lines #L89 - L93 were not covered by tests
searchPlaceholder = registerUiState.registerConfiguration?.searchBar?.display,
toolBarHomeNavigation = toolBarHomeNavigation,
onSearchTextChanged = { searchText ->
onEvent(RegisterEvent.SearchRegister(searchText = searchText))
},

Check warning on line 98 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L95-L98

Added lines #L95 - L98 were not covered by tests
isFilterIconEnabled = filterActions?.isNotEmpty() ?: false,
) { event ->
when (event) {

Check warning on line 101 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L101

Added line #L101 was not covered by tests
ToolbarClickEvent.Navigate ->
when (toolBarHomeNavigation) {
ToolBarHomeNavigation.OPEN_DRAWER -> openDrawer(true)
ToolBarHomeNavigation.NAVIGATE_BACK -> navController.popBackStack()

Check warning on line 105 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L104-L105

Added lines #L104 - L105 were not covered by tests
}
ToolbarClickEvent.FilterData -> {
onEvent(RegisterEvent.ResetFilterRecordsCount)

Check warning on line 108 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L108

Added line #L108 was not covered by tests
filterActions?.handleClickEvent(navController)
}
}
// Only show counter during search
if (searchText.value.isNotEmpty()) RegisterHeader(resultCount = pagingItems.itemCount)
}
// Only show counter during search
if (searchText.value.isNotEmpty()) RegisterHeader(resultCount = pagingItems.itemCount)
},
floatingActionButton = {
val fabActions = registerUiState.registerConfiguration?.fabActions
if (!fabActions.isNullOrEmpty() && fabActions.first().visible) {
ExtendedFab(
modifier = modifier.testTag(FAB_BUTTON_REGISTER_TEST_TAG),

Check warning on line 120 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L120

Added line #L120 was not covered by tests
fabActions = fabActions,
navController = navController,
lazyListState = lazyListState,
)
}
},
) { innerPadding ->
Box(modifier = modifier.padding(innerPadding)) {
Box(
modifier = modifier.padding(innerPadding),

Check warning on line 129 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L129

Added line #L129 was not covered by tests
) {
if (registerUiState.isFirstTimeSync) {
val isSyncUpload = registerUiState.isSyncUpload.collectAsState(initial = false).value
LoaderDialog(
modifier = modifier,
modifier = modifier.testTag(FIRST_TIME_SYNC_DIALOG),

Check warning on line 134 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L134

Added line #L134 was not covered by tests
percentageProgressFlow = registerUiState.progressPercentage,
dialogMessage =
stringResource(
Expand All @@ -134,25 +140,26 @@
showPercentageProgress = true,
)
}
if (
registerUiState.totalRecordsCount > 0 &&
registerUiState.registerConfiguration?.registerCard != null
) {
RegisterCardList(
registerCardConfig = registerUiState.registerConfiguration.registerCard,
pagingItems = pagingItems,
navController = navController,
lazyListState = lazyListState,
onEvent = onEvent,
registerUiState = registerUiState,
currentPage = currentPage,
showPagination = searchText.value.isEmpty(),
)
} else {
registerUiState.registerConfiguration?.noResults?.let { noResultConfig ->
NoRegisterDataView(modifier = modifier, noResults = noResultConfig) {
noResultConfig.actionButton?.actions?.handleClickEvent(navController)
}
}
if (
registerUiState.totalRecordsCount > 0 &&
registerUiState.registerConfiguration?.registerCard != null
) {
RegisterCardList(
modifier = modifier.testTag(REGISTER_CARD_TEST_TAG),
registerCardConfig = registerUiState.registerConfiguration.registerCard,
pagingItems = pagingItems,
navController = navController,
lazyListState = lazyListState,
onEvent = onEvent,
registerUiState = registerUiState,
currentPage = currentPage,

Check warning on line 156 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L147-L156

Added lines #L147 - L156 were not covered by tests
showPagination = searchText.value.isEmpty(),
)
} else {
registerUiState.registerConfiguration?.noResults?.let { noResultConfig ->
NoRegisterDataView(modifier = modifier, noResults = noResultConfig) {

Check warning on line 161 in android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt#L161

Added line #L161 was not covered by tests
noResultConfig.actionButton?.actions?.handleClickEvent(navController)
}
}
}
Expand Down
Loading
Loading