Skip to content

Commit

Permalink
Add tests for composable MemberProfileBottomSheetView (#2758)
Browse files Browse the repository at this point in the history
* Add tests for composable MemberProfileBottomSheetView

Co-authored-by:  hilpitome <[email protected]>

* Refactor bottomsheetViewtest.
Co-authored-by: Lazarus <[email protected]>
Co-authored-by: hilpitome <[email protected]>"

Signed-off-by: Lentumunai-Mark <[email protected]>

---------

Signed-off-by: Lentumunai-Mark <[email protected]>
Co-authored-by: L≡ZRS <[email protected]>
Co-authored-by: hilpitome <[email protected]>
Co-authored-by: Lentumunai-Mark <[email protected]>
  • Loading branch information
4 people authored Sep 18, 2023
1 parent fbfa0a4 commit 143b1c8
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2021-2023 Ona Systems, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.smartregister.fhircore.quest.integration.ui.profile.components

import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import org.hl7.fhir.r4.model.ResourceType
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.smartregister.fhircore.engine.configuration.view.ButtonProperties
import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.quest.ui.profile.components.ICON_FIELD_TAG
import org.smartregister.fhircore.quest.ui.profile.components.MemberProfileBottomSheetView
import org.smartregister.fhircore.quest.ui.profile.components.TOP_SECTION_ROW
import org.smartregister.fhircore.quest.ui.profile.components.VIEW_PROFILE_TAG

@OptIn(ExperimentalMaterialApi::class)
class MemberProfileBottomSheetViewTest {

@get:Rule val composeTestRule = createComposeRule()

@Before
fun setUp() {
val buttonProperties =
listOf(
ButtonProperties(text = "Issue bednet", status = "OVERDUE"),
)
composeTestRule.setContent {
MemberProfileBottomSheetView(
title = "John Doe, M, 35y",
buttonProperties = buttonProperties,
onViewProfile = { /*Do nothing*/},
resourceData = ResourceData("id", ResourceType.Patient, emptyMap()),
)
}
}

@Test
fun testTopMemberProfileSectionDisplayedCorrectly() {
composeTestRule.onNodeWithTag(TOP_SECTION_ROW).assertExists().assertIsDisplayed()
}

@Test
fun testViewProfileIsDisplayedAndHasClickAction() {
composeTestRule
.onNodeWithTag(VIEW_PROFILE_TAG)
.assertExists()
.assertIsDisplayed()
.assertHasClickAction()
}

@Test
fun testMemberProfileBottomSheetViewIconExistsAndHasClickAction() {
composeTestRule.onNodeWithTag(ICON_FIELD_TAG).assertExists().assertHasClickAction()
}

@Test
fun testMemberProfileBottomSheetViewButtonsRendersCorrectly() {
composeTestRule
.onNodeWithText("Issue bednet")
.assertExists()
.assertIsDisplayed()
.assertHasClickAction()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -58,15 +59,19 @@ import org.smartregister.fhircore.engine.util.annotation.PreviewWithBackgroundEx
import org.smartregister.fhircore.quest.R
import org.smartregister.fhircore.quest.ui.shared.components.ActionableButton

const val VIEW_PROFILE_TAG = "view-profile-tag"
const val TOP_SECTION_ROW = "top-section-row"
const val ICON_FIELD_TAG = "iconTestTag"

@Composable
fun MemberProfileBottomSheetView(
modifier: Modifier = Modifier,
coroutineScope: CoroutineScope,
bottomSheetScaffoldState: BottomSheetScaffoldState,
coroutineScope: CoroutineScope = rememberCoroutineScope(),
bottomSheetScaffoldState: BottomSheetScaffoldState = rememberBottomSheetScaffoldState(),
title: String,
buttonProperties: List<ButtonProperties>,
ResourceData: ResourceData,
navController: NavController,
resourceData: ResourceData,
navController: NavController = rememberNavController(),
onViewProfile: () -> Unit,
) {
Column {
Expand All @@ -75,7 +80,7 @@ fun MemberProfileBottomSheetView(
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = modifier.fillMaxWidth().padding(horizontal = 16.dp),
modifier = modifier.fillMaxWidth().padding(horizontal = 16.dp).testTag(TOP_SECTION_ROW),
) {
Column(modifier = modifier.wrapContentWidth(Alignment.Start)) {
Text(
Expand All @@ -90,13 +95,15 @@ fun MemberProfileBottomSheetView(
contentDescription = null,
tint = DefaultColor.copy(0.8f),
modifier =
modifier.clickable {
coroutineScope.launch {
if (!bottomSheetScaffoldState.bottomSheetState.isCollapsed) {
bottomSheetScaffoldState.bottomSheetState.collapse()
modifier
.clickable {
coroutineScope.launch {
if (!bottomSheetScaffoldState.bottomSheetState.isCollapsed) {
bottomSheetScaffoldState.bottomSheetState.collapse()
}
}
}
},
.testTag(ICON_FIELD_TAG),
)
}
Spacer(modifier = modifier.height(8.dp))
Expand All @@ -107,7 +114,7 @@ fun MemberProfileBottomSheetView(
buttonProperties.forEach {
ActionableButton(
buttonProperties = it.copy(buttonType = ButtonType.BIG),
resourceData = ResourceData,
resourceData = resourceData,
navController = navController,
)
}
Expand All @@ -123,7 +130,8 @@ fun MemberProfileBottomSheetView(
modifier
.fillMaxWidth()
.clickable { onViewProfile() }
.padding(horizontal = 16.dp, vertical = 16.dp),
.padding(horizontal = 16.dp, vertical = 16.dp)
.testTag(VIEW_PROFILE_TAG),
)
Spacer(modifier = modifier.height(16.dp))
}
Expand All @@ -139,7 +147,7 @@ private fun MemberProfileBottomSheetViewPreview() {
buttonProperties = emptyList(),
navController = rememberNavController(),
onViewProfile = { /*Do nothing*/},
ResourceData = ResourceData("id", ResourceType.Patient, emptyMap()),
resourceData = ResourceData("id", ResourceType.Patient, emptyMap()),
)
}

Expand All @@ -158,6 +166,6 @@ private fun MemberProfileBottomSheetViewWithFormDataPreview() {
),
navController = rememberNavController(),
onViewProfile = { /*Do nothing*/},
ResourceData = ResourceData("id", ResourceType.Patient, emptyMap()),
resourceData = ResourceData("id", ResourceType.Patient, emptyMap()),
)
}

0 comments on commit 143b1c8

Please sign in to comment.