From a8db5bfcf8cdcd101691c3e602d9ab80d1bb79eb Mon Sep 17 00:00:00 2001 From: = Date: Thu, 5 Oct 2023 09:24:09 +0200 Subject: [PATCH 01/16] add:[ANDROAPP-5575] Component added, screen added --- .../kotlin/org/hisp/dhis/common/App.kt | 4 +- .../hisp/dhis/common/screens/Components.kt | 1 + .../common/screens/InputFileResourceScreen.kt | 25 +++++++ .../component/InputFileResource.kt | 72 +++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt create mode 100644 designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt index ff5f39eed..6f299af44 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt @@ -41,6 +41,7 @@ import org.hisp.dhis.common.screens.InputCheckBoxScreen import org.hisp.dhis.common.screens.InputCoordinateScreen import org.hisp.dhis.common.screens.InputDateTimeScreen import org.hisp.dhis.common.screens.InputDropDownScreen +import org.hisp.dhis.common.screens.InputFileResourceScreen import org.hisp.dhis.common.screens.InputEmailScreen import org.hisp.dhis.common.screens.InputIntegerScreen import org.hisp.dhis.common.screens.InputLetterScreen @@ -87,7 +88,7 @@ fun App() { @Composable fun Main() { - val currentScreen = remember { mutableStateOf(Components.INPUT_BARCODE) } + val currentScreen = remember { mutableStateOf(Components.CAROUSEL_BUTTONS) } var expanded by remember { mutableStateOf(false) } Column( @@ -182,6 +183,7 @@ fun Main() { Components.INPUT_POLYGON -> InputPolygonScreen() Components.INPUT_ORG_UNIT -> InputOrgUnitScreen() Components.IMAGE_BLOCK -> ImageBlockScreen() + Components.INPUT_FILE_RESOURCE -> InputFileResourceScreen() Components.INPUT_DROPDOWN -> InputDropDownScreen() Components.INPUT_DATE_TIME -> InputDateTimeScreen() Components.INPUT_COORDINATE -> InputCoordinateScreen() diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/Components.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/Components.kt index ca09185c7..8d3397346 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/Components.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/Components.kt @@ -49,6 +49,7 @@ enum class Components(val label: String) { INPUT_POLYGON("Input Polygon"), INPUT_ORG_UNIT("Input Org. Unit"), IMAGE_BLOCK("Image Block"), + INPUT_FILE_RESOURCE("Input File Resource"), INPUT_DROPDOWN("Input Dropdown"), INPUT_DATE_TIME("Input Date Time"), INPUT_COORDINATE("Input Coordinate"), diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt new file mode 100644 index 000000000..02f9496d3 --- /dev/null +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt @@ -0,0 +1,25 @@ +package org.hisp.dhis.common.screens + +import androidx.compose.runtime.Composable +import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer +import org.hisp.dhis.mobile.ui.designsystem.component.InputFileResource +import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState + +@Composable +fun InputFileResourceScreen() { + ColumnComponentContainer { + InputFileResource( + title = "Label" + ) + InputFileResource( + title = "Label", + uploadFileState = UploadFileState.UPLOADING + ) + InputFileResource( + title = "Label", + fileName = "filename.extension", + fileWeight = "524kb", + uploadFileState = UploadFileState.LOADED + ) + } +} \ No newline at end of file diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt new file mode 100644 index 000000000..f527bde10 --- /dev/null +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -0,0 +1,72 @@ +package org.hisp.dhis.mobile.ui.designsystem.component + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.FileUpload +import androidx.compose.material3.Icon +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.LOADED +import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.UPLOADING +import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD +import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing + +@Composable +fun InputFileResource( + title: String, + fileName: String? = null, + fileWeight: String? = null, + uploadFileState: UploadFileState = ADD +) { + var currentState by remember { + mutableStateOf(uploadFileState) + } + + InputShell( + title, + state = if(currentState == UPLOADING) InputShellState.FOCUSED else InputShellState.UNFOCUSED, + inputField = { + when(currentState) { + ADD -> { + Button( + modifier = Modifier.padding(end = Spacing.Spacing16).fillMaxWidth(), + style = ButtonStyle.ELEVATED, + text = "Add file", + icon = { + Icon( + imageVector = Icons.Outlined.FileUpload, + contentDescription = "Upload Icon Button", + ) + } + ) { currentState = LOADED } + } + UPLOADING -> { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.Center + ) { + ProgressIndicator(type = ProgressIndicatorType.CIRCULAR) + } + } + LOADED -> { + fileName?.let { BasicTextField(helper = fileWeight, helperStyle = InputStyle.WITH_HELPER_AFTER, inputText = it, onInputChanged = { }) } + } + } + } + ) +} + +enum class UploadFileState { + ADD, + UPLOADING, + LOADED +} + + From 7c3d54b68ec528f9d78d08fce1ed20e7ad2e6629 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 5 Oct 2023 11:26:16 +0200 Subject: [PATCH 02/16] add: [ANDROAPP-5575] onClicks added --- .../common/screens/InputFileResourceScreen.kt | 12 +++-- .../component/InputFileResource.kt | 52 +++++++++++++++++-- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt index 02f9496d3..7081ab7ef 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt @@ -9,17 +9,23 @@ import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState fun InputFileResourceScreen() { ColumnComponentContainer { InputFileResource( - title = "Label" + title = "Label", + onSelectFile = {}, + onUploadFile = {} ) InputFileResource( title = "Label", - uploadFileState = UploadFileState.UPLOADING + uploadFileState = UploadFileState.UPLOADING, + onSelectFile = {}, + onUploadFile = {} ) InputFileResource( title = "Label", fileName = "filename.extension", fileWeight = "524kb", - uploadFileState = UploadFileState.LOADED + uploadFileState = UploadFileState.LOADED, + onSelectFile = {}, + onUploadFile = {} ) } } \ No newline at end of file diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index f527bde10..35920c7d1 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Cancel import androidx.compose.material.icons.outlined.FileUpload import androidx.compose.material3.Icon import androidx.compose.runtime.Composable @@ -13,6 +14,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.LOADED import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.UPLOADING import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD @@ -23,12 +25,35 @@ fun InputFileResource( title: String, fileName: String? = null, fileWeight: String? = null, + onSelectFile: () -> Unit, + onUploadFile: () -> Unit, + onClear: () -> Unit = {}, uploadFileState: UploadFileState = ADD ) { var currentState by remember { mutableStateOf(uploadFileState) } + var primaryButton: @Composable (() -> Unit)? = if (currentState == LOADED) { + { + IconButton( + modifier = Modifier.testTag("INPUT_FILE_RESOURCE_CLEAR_BUTTON"), + icon = { + Icon( + imageVector = Icons.Outlined.Cancel, + contentDescription = "Icon Button", + ) + }, + onClick = { + currentState = ADD + onClear.invoke() + }, + ) + } + } else { + null + } + InputShell( title, state = if(currentState == UPLOADING) InputShellState.FOCUSED else InputShellState.UNFOCUSED, @@ -45,7 +70,10 @@ fun InputFileResource( contentDescription = "Upload Icon Button", ) } - ) { currentState = LOADED } + ) { + currentState = LOADED + onSelectFile.invoke() + } } UPLOADING -> { Row( @@ -56,10 +84,28 @@ fun InputFileResource( } } LOADED -> { - fileName?.let { BasicTextField(helper = fileWeight, helperStyle = InputStyle.WITH_HELPER_AFTER, inputText = it, onInputChanged = { }) } + Row() { + fileName?.let { BasicTextField(helper = fileWeight, helperStyle = InputStyle.WITH_HELPER_AFTER, inputText = it, onInputChanged = { }) } + } } } - } + }, + primaryButton = primaryButton, + secondaryButton = { + if (currentState == LOADED) { + SquareIconButton( + icon = { + Icon( + imageVector = Icons.Outlined.FileUpload, + contentDescription = "Upload Icon Button", + ) + } + ) { + currentState = UPLOADING + onUploadFile.invoke() + } + } + }, ) } From 2dfcf5a344183ffc2e9bd6a4a292fcbc8c0a0157 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 5 Oct 2023 11:32:24 +0200 Subject: [PATCH 03/16] update: [ANDROAPP-5575] primary and secondary button moved outside of the component --- .../component/InputFileResource.kt | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 35920c7d1..2eb4bad7d 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -54,6 +54,25 @@ fun InputFileResource( null } + var secondaryButton: @Composable (() -> Unit)? = + if (currentState == LOADED) { + { + SquareIconButton( + icon = { + Icon( + imageVector = Icons.Outlined.FileUpload, + contentDescription = "Upload Icon Button", + ) + } + ) { + currentState = UPLOADING + onUploadFile.invoke() + } + } + } else { + null + } + InputShell( title, state = if(currentState == UPLOADING) InputShellState.FOCUSED else InputShellState.UNFOCUSED, @@ -91,21 +110,7 @@ fun InputFileResource( } }, primaryButton = primaryButton, - secondaryButton = { - if (currentState == LOADED) { - SquareIconButton( - icon = { - Icon( - imageVector = Icons.Outlined.FileUpload, - contentDescription = "Upload Icon Button", - ) - } - ) { - currentState = UPLOADING - onUploadFile.invoke() - } - } - }, + secondaryButton = secondaryButton, ) } From 1923f40815d38cd3482298f98da41135ee6bf77a Mon Sep 17 00:00:00 2001 From: = Date: Fri, 6 Oct 2023 12:23:50 +0200 Subject: [PATCH 04/16] update: [ANDROAPP-5575] String added, fileName and fileWeight to MutableState, code formated --- .../common/screens/InputFileResourceScreen.kt | 34 ++++++++++++++---- .../component/InputFileResource.kt | 36 +++++++++---------- .../resources/values/strings_en.xml | 1 + 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt index 7081ab7ef..c675054fb 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt @@ -1,6 +1,10 @@ package org.hisp.dhis.common.screens import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputFileResource import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState @@ -8,24 +12,40 @@ import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState @Composable fun InputFileResourceScreen() { ColumnComponentContainer { + val currentFileName: MutableState = + mutableStateOf("filename.extension") + val currentFileWeight: MutableState = + mutableStateOf("524kb") + val currentFileName2: MutableState = + mutableStateOf("filename.extension") + val currentFileWeight2: MutableState = + mutableStateOf("524kb") + InputFileResource( title = "Label", - onSelectFile = {}, - onUploadFile = {} + fileName = currentFileName, + fileWeight = currentFileWeight, + onSelectFile = { + currentFileName.value = "file" + currentFileWeight.value = "weight" + }, + onUploadFile = {}, ) InputFileResource( title = "Label", + fileName = currentFileName, + fileWeight = currentFileWeight, uploadFileState = UploadFileState.UPLOADING, onSelectFile = {}, - onUploadFile = {} + onUploadFile = {}, ) InputFileResource( title = "Label", - fileName = "filename.extension", - fileWeight = "524kb", + fileName = currentFileName2, + fileWeight = currentFileWeight2, uploadFileState = UploadFileState.LOADED, onSelectFile = {}, - onUploadFile = {} + onUploadFile = {}, ) } -} \ No newline at end of file +} diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 2eb4bad7d..9e6eb2012 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -9,32 +9,34 @@ import androidx.compose.material.icons.outlined.Cancel import androidx.compose.material.icons.outlined.FileUpload import androidx.compose.material3.Icon import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag +import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.LOADED import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.UPLOADING -import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD +import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing @Composable fun InputFileResource( title: String, - fileName: String? = null, - fileWeight: String? = null, + fileName: MutableState = mutableStateOf(null), + fileWeight: MutableState = mutableStateOf(null), onSelectFile: () -> Unit, onUploadFile: () -> Unit, onClear: () -> Unit = {}, - uploadFileState: UploadFileState = ADD + uploadFileState: UploadFileState = ADD, ) { var currentState by remember { mutableStateOf(uploadFileState) } - var primaryButton: @Composable (() -> Unit)? = if (currentState == LOADED) { + val primaryButton: @Composable (() -> Unit)? = if (currentState == LOADED) { { IconButton( modifier = Modifier.testTag("INPUT_FILE_RESOURCE_CLEAR_BUTTON"), @@ -54,7 +56,7 @@ fun InputFileResource( null } - var secondaryButton: @Composable (() -> Unit)? = + val secondaryButton: @Composable (() -> Unit)? = if (currentState == LOADED) { { SquareIconButton( @@ -63,7 +65,7 @@ fun InputFileResource( imageVector = Icons.Outlined.FileUpload, contentDescription = "Upload Icon Button", ) - } + }, ) { currentState = UPLOADING onUploadFile.invoke() @@ -75,37 +77,35 @@ fun InputFileResource( InputShell( title, - state = if(currentState == UPLOADING) InputShellState.FOCUSED else InputShellState.UNFOCUSED, + state = if (currentState == UPLOADING) InputShellState.FOCUSED else InputShellState.UNFOCUSED, inputField = { - when(currentState) { + when (currentState) { ADD -> { Button( modifier = Modifier.padding(end = Spacing.Spacing16).fillMaxWidth(), style = ButtonStyle.ELEVATED, - text = "Add file", + text = provideStringResource("add_file"), icon = { Icon( imageVector = Icons.Outlined.FileUpload, contentDescription = "Upload Icon Button", ) - } + }, ) { - currentState = LOADED onSelectFile.invoke() + currentState = LOADED } } UPLOADING -> { Row( modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.Center + horizontalArrangement = Arrangement.Center, ) { ProgressIndicator(type = ProgressIndicatorType.CIRCULAR) } } LOADED -> { - Row() { - fileName?.let { BasicTextField(helper = fileWeight, helperStyle = InputStyle.WITH_HELPER_AFTER, inputText = it, onInputChanged = { }) } - } + fileName.value?.let { BasicTextField(helper = fileWeight.value, helperStyle = InputStyle.WITH_HELPER_AFTER, inputText = it, onInputChanged = { }) } } } }, @@ -117,7 +117,5 @@ fun InputFileResource( enum class UploadFileState { ADD, UPLOADING, - LOADED + LOADED, } - - diff --git a/designsystem/src/commonMain/resources/values/strings_en.xml b/designsystem/src/commonMain/resources/values/strings_en.xml index 6cab9e0be..9c6c192bf 100644 --- a/designsystem/src/commonMain/resources/values/strings_en.xml +++ b/designsystem/src/commonMain/resources/values/strings_en.xml @@ -15,6 +15,7 @@ Show fields Hide fields Next + Add file Yes No Enter phone number From 457c2176f77b29013f3fbd72d969d11de2e13d2e Mon Sep 17 00:00:00 2001 From: = Date: Fri, 6 Oct 2023 12:38:16 +0200 Subject: [PATCH 05/16] update: [ANDROAPP-5575] Code formatted --- common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt index 6f299af44..27a060260 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt @@ -43,6 +43,7 @@ import org.hisp.dhis.common.screens.InputDateTimeScreen import org.hisp.dhis.common.screens.InputDropDownScreen import org.hisp.dhis.common.screens.InputFileResourceScreen import org.hisp.dhis.common.screens.InputEmailScreen +import org.hisp.dhis.common.screens.InputFileResourceScreen import org.hisp.dhis.common.screens.InputIntegerScreen import org.hisp.dhis.common.screens.InputLetterScreen import org.hisp.dhis.common.screens.InputLinkScreen From 93018070eb60c82358f5c094c791fb6d8c98c3c8 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 10 Oct 2023 09:41:22 +0200 Subject: [PATCH 06/16] add: [ANDROAPP-5575] Tests added, component state can be managed externaly --- .../kotlin/org/hisp/dhis/common/App.kt | 2 +- .../common/screens/InputFileResourceScreen.kt | 20 ++- .../component/InputFileResource.kt | 57 ++++-- .../component/InputFileResourceTest.kt | 167 ++++++++++++++++++ 4 files changed, 230 insertions(+), 16 deletions(-) create mode 100644 designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt index 27a060260..604c416dd 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt @@ -89,7 +89,7 @@ fun App() { @Composable fun Main() { - val currentScreen = remember { mutableStateOf(Components.CAROUSEL_BUTTONS) } + val currentScreen = remember { mutableStateOf(Components.INPUT_FILE_RESOURCE) } var expanded by remember { mutableStateOf(false) } Column( diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt index c675054fb..ed7b66b01 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt @@ -1,13 +1,20 @@ package org.hisp.dhis.common.screens import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.currentCoroutineContext +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputFileResource import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState +import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource +import kotlin.coroutines.coroutineContext @Composable fun InputFileResourceScreen() { @@ -20,9 +27,11 @@ fun InputFileResourceScreen() { mutableStateOf("filename.extension") val currentFileWeight2: MutableState = mutableStateOf("524kb") + val inputFileState = mutableStateOf(UploadFileState.LOADED) InputFileResource( title = "Label", + buttonText = provideStringResource("add_file"), fileName = currentFileName, fileWeight = currentFileWeight, onSelectFile = { @@ -33,19 +42,24 @@ fun InputFileResourceScreen() { ) InputFileResource( title = "Label", + buttonText = provideStringResource("add_file"), fileName = currentFileName, fileWeight = currentFileWeight, - uploadFileState = UploadFileState.UPLOADING, + uploadFileState = mutableStateOf(UploadFileState.UPLOADING), onSelectFile = {}, onUploadFile = {}, ) InputFileResource( title = "Label", + buttonText = provideStringResource("add_file"), fileName = currentFileName2, fileWeight = currentFileWeight2, - uploadFileState = UploadFileState.LOADED, + uploadFileState = inputFileState, onSelectFile = {}, - onUploadFile = {}, + onUploadFile = { + delay(3000) + inputFileState.value = UploadFileState.ADD + }, ) } } diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 9e6eb2012..9ee55313e 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -13,33 +13,45 @@ import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag +import kotlinx.coroutines.launch import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.LOADED import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.UPLOADING -import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing +const val inputFileTestTag = "INPUT_FILE_RESOURCE_" +const val clearButtonTestTag = "CLEAR_BUTTON" +const val uploadButtonTestTag = "UPLOAD_BUTTON" +const val addButtonTestTag = "ADD_BUTTON" +const val progressIndicatorTestTag = "PROGRESS_INDICATOR" +const val uploadHelperTestTag = "UPLOAD_HELPER" + + @Composable fun InputFileResource( title: String, + buttonText: String, fileName: MutableState = mutableStateOf(null), fileWeight: MutableState = mutableStateOf(null), onSelectFile: () -> Unit, - onUploadFile: () -> Unit, + onUploadFile: suspend () -> Unit, onClear: () -> Unit = {}, - uploadFileState: UploadFileState = ADD, + uploadFileState: MutableState = mutableStateOf(ADD), ) { + var currentState by remember { - mutableStateOf(uploadFileState) + uploadFileState } + val scope = rememberCoroutineScope() val primaryButton: @Composable (() -> Unit)? = if (currentState == LOADED) { { IconButton( - modifier = Modifier.testTag("INPUT_FILE_RESOURCE_CLEAR_BUTTON"), + modifier = Modifier.testTag(inputFileTestTag + clearButtonTestTag), icon = { Icon( imageVector = Icons.Outlined.Cancel, @@ -47,6 +59,7 @@ fun InputFileResource( ) }, onClick = { + uploadFileState.value = ADD currentState = ADD onClear.invoke() }, @@ -60,6 +73,7 @@ fun InputFileResource( if (currentState == LOADED) { { SquareIconButton( + modifier = Modifier.testTag(inputFileTestTag + uploadButtonTestTag), icon = { Icon( imageVector = Icons.Outlined.FileUpload, @@ -67,8 +81,11 @@ fun InputFileResource( ) }, ) { - currentState = UPLOADING - onUploadFile.invoke() + scope.launch { + uploadFileState.value = UPLOADING + currentState = UPLOADING + onUploadFile.invoke() + } } } } else { @@ -82,9 +99,12 @@ fun InputFileResource( when (currentState) { ADD -> { Button( - modifier = Modifier.padding(end = Spacing.Spacing16).fillMaxWidth(), + modifier = Modifier + .testTag(inputFileTestTag + addButtonTestTag) + .padding(end = Spacing.Spacing16) + .fillMaxWidth(), style = ButtonStyle.ELEVATED, - text = provideStringResource("add_file"), + text = buttonText, icon = { Icon( imageVector = Icons.Outlined.FileUpload, @@ -92,8 +112,10 @@ fun InputFileResource( ) }, ) { - onSelectFile.invoke() + uploadFileState.value = LOADED currentState = LOADED + onSelectFile.invoke() + } } UPLOADING -> { @@ -101,11 +123,22 @@ fun InputFileResource( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center, ) { - ProgressIndicator(type = ProgressIndicatorType.CIRCULAR) + ProgressIndicator( + modifier = Modifier.testTag(inputFileTestTag + progressIndicatorTestTag), + type = ProgressIndicatorType.CIRCULAR + ) } } LOADED -> { - fileName.value?.let { BasicTextField(helper = fileWeight.value, helperStyle = InputStyle.WITH_HELPER_AFTER, inputText = it, onInputChanged = { }) } + fileName.value?.let { + BasicTextField( + modifier = Modifier.testTag(inputFileTestTag + uploadHelperTestTag), + helper = fileWeight.value, + helperStyle = InputStyle.WITH_HELPER_AFTER, + inputText = it, + onInputChanged = { } + ) + } } } }, diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt new file mode 100644 index 000000000..4bcde2b26 --- /dev/null +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt @@ -0,0 +1,167 @@ +package org.hisp.dhis.mobile.ui.designsystem.component + +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.mutableStateOf +import androidx.compose.ui.test.InternalTestApi +import androidx.compose.ui.test.TestOwner +import androidx.compose.ui.test.assert +import androidx.compose.ui.test.createTestContext +import androidx.compose.ui.test.hasText +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performClick +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.delay +import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource +import org.junit.Rule +import org.junit.Test +import java.util.Timer +import java.util.logging.Handler +import kotlin.coroutines.coroutineContext + +class InputFileResourceTest { + + @get:Rule + val rule = createComposeRule() + + @Test + fun shouldShowLoaderAfterUploadFile() { + + rule.setContent { + InputFileResource( + title = "Label", + buttonText = provideStringResource("add_file"), + fileName = mutableStateOf("filename.extension"), + fileWeight = mutableStateOf("524kb"), + uploadFileState = mutableStateOf(UploadFileState.LOADED), + onSelectFile = {}, + onUploadFile = {}, + ) + } + + rule.onNodeWithTag(inputFileTestTag + uploadButtonTestTag).performClick() + rule.onNodeWithTag(inputFileTestTag + progressIndicatorTestTag).assertExists() + + } + + @Test + fun shouldShowClearButtonAndHelperWhenFileIsSelected() { + + val testFileName: MutableState = mutableStateOf("filename.extension") + val testFileWeight: MutableState = mutableStateOf("524kb") + + rule.setContent { + InputFileResource( + title = "Label", + buttonText = provideStringResource("add_file"), + fileName = testFileName, + fileWeight = testFileWeight, + onSelectFile = {}, + onUploadFile = {}, + ) + } + + rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).performClick() + rule.onNodeWithTag(inputFileTestTag + uploadButtonTestTag).assertExists() + rule.onNodeWithTag(inputFileTestTag + uploadHelperTestTag).assertExists() + rule.onNodeWithTag(inputFileTestTag + uploadHelperTestTag).assert(hasText(testFileName.value.toString() + " " + testFileWeight.value.toString())) + + } + + @Test + fun shouldDisplayButtonWithCustomText() { + + rule.setContent { + InputFileResource( + title = "Label", + buttonText = "select a file", + fileName = mutableStateOf("filename.extension"), + fileWeight = mutableStateOf("524kb"), + onSelectFile = {}, + onUploadFile = {}, + ) + } + + rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assertExists() + rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assert(hasText("select a file")) + + } + + @Test + fun shouldChangeFileNameAndFileWeightAfterModifyIt() { + + val testFileName: MutableState = mutableStateOf("test.filename.extension") + val testFileWeight: MutableState = mutableStateOf("256kb") + var newFileName: String? = null + var newFileWeight: String? = null + + rule.setContent { + InputFileResource( + title = "Label", + buttonText = provideStringResource("add_file"), + fileName = testFileName, + fileWeight = testFileWeight, + uploadFileState = mutableStateOf(UploadFileState.LOADED), + onSelectFile = { + testFileName.value = newFileName + testFileWeight.value = newFileWeight + }, + onUploadFile = {}, + ) + } + rule.onNodeWithTag(inputFileTestTag + uploadHelperTestTag).assert(hasText("test.filename.extension 256kb")) + rule.onNodeWithTag(inputFileTestTag + clearButtonTestTag).performClick() + newFileName = "test_file" + newFileWeight = "512gb" + rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).performClick() + rule.onNodeWithTag(inputFileTestTag + uploadHelperTestTag).assert(hasText("test_file 512gb")) + + + } + + @Test + fun shouldAppearIconTextButtonWhenUploadIsCancelled() { + + rule.setContent { + InputFileResource( + title = "Label", + buttonText = "add file", + fileName = mutableStateOf("filename.extension"), + fileWeight = mutableStateOf("524kb"), + uploadFileState = mutableStateOf(UploadFileState.LOADED), + onSelectFile = {}, + onUploadFile = {}, + ) + } + + rule.onNodeWithTag(inputFileTestTag + clearButtonTestTag).performClick() + rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assertExists() + rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assert(hasText("add file")) + + } + + @Test + fun shouldDisplayToastAfterUploadFile() { + + val inputFileState = mutableStateOf(UploadFileState.LOADED) + + rule.setContent { + InputFileResource( + title = "Label", + buttonText = "add file", + fileName = mutableStateOf("filename.extension"), + fileWeight = mutableStateOf("524kb"), + uploadFileState = inputFileState, + onSelectFile = {}, + onUploadFile = { + delay(5000) + inputFileState.value = UploadFileState.ADD + }, + ) + } + + rule.onNodeWithTag(inputFileTestTag + uploadButtonTestTag).performClick() + rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assertExists() + + } +} \ No newline at end of file From bbfc12ba0feca29d70ded3472f5a4524058297d3 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 10 Oct 2023 12:09:57 +0200 Subject: [PATCH 07/16] update: [ANDROAPP-5575] Supporting text added, modifier added, input shell state added, test removed --- .../common/screens/InputFileResourceScreen.kt | 24 ++---- .../component/InputFileResource.kt | 63 +++++++------- .../component/InputFileResourceTest.kt | 82 +++++-------------- 3 files changed, 60 insertions(+), 109 deletions(-) diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt index ed7b66b01..45376b82b 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt @@ -1,24 +1,19 @@ package org.hisp.dhis.common.screens import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.MutableState -import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.currentCoroutineContext -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import org.hisp.dhis.mobile.ui.designsystem.component.ColumnComponentContainer import org.hisp.dhis.mobile.ui.designsystem.component.InputFileResource +import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource -import kotlin.coroutines.coroutineContext @Composable fun InputFileResourceScreen() { - ColumnComponentContainer { + ColumnComponentContainer( + title = "Input File Component" + ) { val currentFileName: MutableState = mutableStateOf("filename.extension") val currentFileWeight: MutableState = @@ -27,7 +22,6 @@ fun InputFileResourceScreen() { mutableStateOf("filename.extension") val currentFileWeight2: MutableState = mutableStateOf("524kb") - val inputFileState = mutableStateOf(UploadFileState.LOADED) InputFileResource( title = "Label", @@ -45,7 +39,8 @@ fun InputFileResourceScreen() { buttonText = provideStringResource("add_file"), fileName = currentFileName, fileWeight = currentFileWeight, - uploadFileState = mutableStateOf(UploadFileState.UPLOADING), + uploadFileState = UploadFileState.UPLOADING, + inputShellState = InputShellState.FOCUSED, onSelectFile = {}, onUploadFile = {}, ) @@ -54,12 +49,9 @@ fun InputFileResourceScreen() { buttonText = provideStringResource("add_file"), fileName = currentFileName2, fileWeight = currentFileWeight2, - uploadFileState = inputFileState, + uploadFileState = UploadFileState.LOADED, onSelectFile = {}, - onUploadFile = { - delay(3000) - inputFileState.value = UploadFileState.ADD - }, + onUploadFile = {}, ) } } diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 9ee55313e..9a9ccb2d7 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -13,23 +13,21 @@ import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag -import kotlinx.coroutines.launch import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.LOADED import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.UPLOADING import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing -const val inputFileTestTag = "INPUT_FILE_RESOURCE_" -const val clearButtonTestTag = "CLEAR_BUTTON" -const val uploadButtonTestTag = "UPLOAD_BUTTON" -const val addButtonTestTag = "ADD_BUTTON" -const val progressIndicatorTestTag = "PROGRESS_INDICATOR" -const val uploadHelperTestTag = "UPLOAD_HELPER" - +const val INPUT_FILE_TEST_TAG = "INPUT_FILE_RESOURCE_" +const val CLEAR_BUTTON_TEST_TAG = "CLEAR_BUTTON" +const val UPLOAD_BUTTON_TEST_TAG = "UPLOAD_BUTTON" +const val ADD_BUTTON_TEST_TAG = "ADD_BUTTON" +const val PROGRESS_INDICATOR_TEST_TAG = "PROGRESS_INDICATOR" +const val UPLOAD_HELPER_TEST_TAG = "UPLOAD_HELPER" +const val SUPPORTING_TEXT_TEST_TAG = "SUPPORTING_TEXT" @Composable fun InputFileResource( @@ -38,20 +36,21 @@ fun InputFileResource( fileName: MutableState = mutableStateOf(null), fileWeight: MutableState = mutableStateOf(null), onSelectFile: () -> Unit, - onUploadFile: suspend () -> Unit, + onUploadFile: () -> Unit, onClear: () -> Unit = {}, - uploadFileState: MutableState = mutableStateOf(ADD), + uploadFileState: UploadFileState = ADD, + inputShellState: InputShellState = InputShellState.UNFOCUSED, + supportingText: List? = null, + modifier: Modifier = Modifier, ) { - var currentState by remember { - uploadFileState + mutableStateOf(uploadFileState) } - val scope = rememberCoroutineScope() val primaryButton: @Composable (() -> Unit)? = if (currentState == LOADED) { { IconButton( - modifier = Modifier.testTag(inputFileTestTag + clearButtonTestTag), + modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + CLEAR_BUTTON_TEST_TAG), icon = { Icon( imageVector = Icons.Outlined.Cancel, @@ -59,7 +58,6 @@ fun InputFileResource( ) }, onClick = { - uploadFileState.value = ADD currentState = ADD onClear.invoke() }, @@ -73,7 +71,7 @@ fun InputFileResource( if (currentState == LOADED) { { SquareIconButton( - modifier = Modifier.testTag(inputFileTestTag + uploadButtonTestTag), + modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_BUTTON_TEST_TAG), icon = { Icon( imageVector = Icons.Outlined.FileUpload, @@ -81,11 +79,8 @@ fun InputFileResource( ) }, ) { - scope.launch { - uploadFileState.value = UPLOADING - currentState = UPLOADING - onUploadFile.invoke() - } + currentState = UPLOADING + onUploadFile.invoke() } } } else { @@ -94,13 +89,22 @@ fun InputFileResource( InputShell( title, - state = if (currentState == UPLOADING) InputShellState.FOCUSED else InputShellState.UNFOCUSED, + state = inputShellState, + supportingText = { + supportingText?.forEach { label -> + SupportingText( + label.text, + label.state, + modifier = modifier.testTag(INPUT_FILE_TEST_TAG + SUPPORTING_TEXT_TEST_TAG), + ) + } + }, inputField = { when (currentState) { ADD -> { Button( modifier = Modifier - .testTag(inputFileTestTag + addButtonTestTag) + .testTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG) .padding(end = Spacing.Spacing16) .fillMaxWidth(), style = ButtonStyle.ELEVATED, @@ -112,10 +116,8 @@ fun InputFileResource( ) }, ) { - uploadFileState.value = LOADED currentState = LOADED onSelectFile.invoke() - } } UPLOADING -> { @@ -124,19 +126,19 @@ fun InputFileResource( horizontalArrangement = Arrangement.Center, ) { ProgressIndicator( - modifier = Modifier.testTag(inputFileTestTag + progressIndicatorTestTag), - type = ProgressIndicatorType.CIRCULAR + modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + PROGRESS_INDICATOR_TEST_TAG), + type = ProgressIndicatorType.CIRCULAR, ) } } LOADED -> { fileName.value?.let { BasicTextField( - modifier = Modifier.testTag(inputFileTestTag + uploadHelperTestTag), + modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG), helper = fileWeight.value, helperStyle = InputStyle.WITH_HELPER_AFTER, inputText = it, - onInputChanged = { } + onInputChanged = { }, ) } } @@ -144,6 +146,7 @@ fun InputFileResource( }, primaryButton = primaryButton, secondaryButton = secondaryButton, + modifier = modifier, ) } diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt index 4bcde2b26..e73e22586 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt @@ -2,22 +2,14 @@ package org.hisp.dhis.mobile.ui.designsystem.component import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf -import androidx.compose.ui.test.InternalTestApi -import androidx.compose.ui.test.TestOwner import androidx.compose.ui.test.assert -import androidx.compose.ui.test.createTestContext import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.performClick -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.delay import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource import org.junit.Rule import org.junit.Test -import java.util.Timer -import java.util.logging.Handler -import kotlin.coroutines.coroutineContext class InputFileResourceTest { @@ -26,27 +18,24 @@ class InputFileResourceTest { @Test fun shouldShowLoaderAfterUploadFile() { - rule.setContent { InputFileResource( title = "Label", buttonText = provideStringResource("add_file"), fileName = mutableStateOf("filename.extension"), fileWeight = mutableStateOf("524kb"), - uploadFileState = mutableStateOf(UploadFileState.LOADED), + uploadFileState = UploadFileState.LOADED, onSelectFile = {}, onUploadFile = {}, ) } - rule.onNodeWithTag(inputFileTestTag + uploadButtonTestTag).performClick() - rule.onNodeWithTag(inputFileTestTag + progressIndicatorTestTag).assertExists() - + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_BUTTON_TEST_TAG).performClick() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + PROGRESS_INDICATOR_TEST_TAG).assertExists() } @Test fun shouldShowClearButtonAndHelperWhenFileIsSelected() { - val testFileName: MutableState = mutableStateOf("filename.extension") val testFileWeight: MutableState = mutableStateOf("524kb") @@ -61,16 +50,14 @@ class InputFileResourceTest { ) } - rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).performClick() - rule.onNodeWithTag(inputFileTestTag + uploadButtonTestTag).assertExists() - rule.onNodeWithTag(inputFileTestTag + uploadHelperTestTag).assertExists() - rule.onNodeWithTag(inputFileTestTag + uploadHelperTestTag).assert(hasText(testFileName.value.toString() + " " + testFileWeight.value.toString())) - + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG).performClick() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_BUTTON_TEST_TAG).assertExists() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG).assertExists() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG).assert(hasText(testFileName.value.toString() + " " + testFileWeight.value.toString())) } @Test fun shouldDisplayButtonWithCustomText() { - rule.setContent { InputFileResource( title = "Label", @@ -82,14 +69,12 @@ class InputFileResourceTest { ) } - rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assertExists() - rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assert(hasText("select a file")) - + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG).assertExists() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG).assert(hasText("select a file")) } @Test fun shouldChangeFileNameAndFileWeightAfterModifyIt() { - val testFileName: MutableState = mutableStateOf("test.filename.extension") val testFileWeight: MutableState = mutableStateOf("256kb") var newFileName: String? = null @@ -101,7 +86,7 @@ class InputFileResourceTest { buttonText = provideStringResource("add_file"), fileName = testFileName, fileWeight = testFileWeight, - uploadFileState = mutableStateOf(UploadFileState.LOADED), + uploadFileState = UploadFileState.LOADED, onSelectFile = { testFileName.value = newFileName testFileWeight.value = newFileWeight @@ -109,59 +94,30 @@ class InputFileResourceTest { onUploadFile = {}, ) } - rule.onNodeWithTag(inputFileTestTag + uploadHelperTestTag).assert(hasText("test.filename.extension 256kb")) - rule.onNodeWithTag(inputFileTestTag + clearButtonTestTag).performClick() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG).assert(hasText("test.filename.extension 256kb")) + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + CLEAR_BUTTON_TEST_TAG).performClick() newFileName = "test_file" newFileWeight = "512gb" - rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).performClick() - rule.onNodeWithTag(inputFileTestTag + uploadHelperTestTag).assert(hasText("test_file 512gb")) - - + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG).performClick() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG).assert(hasText("test_file 512gb")) } @Test fun shouldAppearIconTextButtonWhenUploadIsCancelled() { - rule.setContent { InputFileResource( title = "Label", buttonText = "add file", fileName = mutableStateOf("filename.extension"), fileWeight = mutableStateOf("524kb"), - uploadFileState = mutableStateOf(UploadFileState.LOADED), + uploadFileState = UploadFileState.LOADED, onSelectFile = {}, onUploadFile = {}, ) } - rule.onNodeWithTag(inputFileTestTag + clearButtonTestTag).performClick() - rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assertExists() - rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assert(hasText("add file")) - - } - - @Test - fun shouldDisplayToastAfterUploadFile() { - - val inputFileState = mutableStateOf(UploadFileState.LOADED) - - rule.setContent { - InputFileResource( - title = "Label", - buttonText = "add file", - fileName = mutableStateOf("filename.extension"), - fileWeight = mutableStateOf("524kb"), - uploadFileState = inputFileState, - onSelectFile = {}, - onUploadFile = { - delay(5000) - inputFileState.value = UploadFileState.ADD - }, - ) - } - - rule.onNodeWithTag(inputFileTestTag + uploadButtonTestTag).performClick() - rule.onNodeWithTag(inputFileTestTag + addButtonTestTag).assertExists() - + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + CLEAR_BUTTON_TEST_TAG).performClick() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG).assertExists() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG).assert(hasText("add file")) } -} \ No newline at end of file +} From a4f6db3b6f8c0e3c83a91147f8363ff3b07d5bbb Mon Sep 17 00:00:00 2001 From: = Date: Tue, 10 Oct 2023 14:59:59 +0200 Subject: [PATCH 08/16] update: [ANDROAPP-5575] Code formatted --- .../org/hisp/dhis/common/screens/InputFileResourceScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt index 45376b82b..12d740ece 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt @@ -12,7 +12,7 @@ import org.hisp.dhis.mobile.ui.designsystem.resource.provideStringResource @Composable fun InputFileResourceScreen() { ColumnComponentContainer( - title = "Input File Component" + title = "Input File Component", ) { val currentFileName: MutableState = mutableStateOf("filename.extension") From ab7e83e09ab127d442f50c1805680c20666506b7 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 13 Oct 2023 14:56:46 +0200 Subject: [PATCH 09/16] update: [ANDROAPP-5575] Icon changed, disabled mode added, progress bar now is nested, hover disabled in text field, button type changed --- .../common/screens/InputFileResourceScreen.kt | 25 +++++++++++++ .../component/InputFileResource.kt | 36 ++++++++++++++----- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt index 12d740ece..018ad82fb 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/screens/InputFileResourceScreen.kt @@ -53,5 +53,30 @@ fun InputFileResourceScreen() { onSelectFile = {}, onUploadFile = {}, ) + InputFileResource( + title = "Label", + buttonText = provideStringResource("add_file"), + fileName = currentFileName, + fileWeight = currentFileWeight, + inputShellState = InputShellState.DISABLED, + onSelectFile = { + currentFileName.value = "file" + currentFileWeight.value = "weight" + }, + onUploadFile = {}, + ) + InputFileResource( + title = "Label", + buttonText = provideStringResource("add_file"), + fileName = currentFileName, + fileWeight = currentFileWeight, + inputShellState = InputShellState.DISABLED, + uploadFileState = UploadFileState.LOADED, + onSelectFile = { + currentFileName.value = "file" + currentFileWeight.value = "weight" + }, + onUploadFile = {}, + ) } } diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 9a9ccb2d7..7f99a6df2 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -1,11 +1,16 @@ package org.hisp.dhis.mobile.ui.designsystem.component +import androidx.compose.foundation.hoverable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Cancel +import androidx.compose.material.icons.outlined.FileDownload import androidx.compose.material.icons.outlined.FileUpload import androidx.compose.material3.Icon import androidx.compose.runtime.Composable @@ -15,11 +20,16 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.input.pointer.PointerIcon +import androidx.compose.ui.input.pointer.pointerHoverIcon +import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.testTag import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.LOADED import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.UPLOADING import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing +import org.hisp.dhis.mobile.ui.designsystem.theme.hoverPointerIcon +import org.hisp.dhis.mobile.ui.designsystem.theme.textFieldHoverPointerIcon const val INPUT_FILE_TEST_TAG = "INPUT_FILE_RESOURCE_" const val CLEAR_BUTTON_TEST_TAG = "CLEAR_BUTTON" @@ -50,6 +60,7 @@ fun InputFileResource( val primaryButton: @Composable (() -> Unit)? = if (currentState == LOADED) { { IconButton( + enabled = inputShellState != InputShellState.DISABLED, modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + CLEAR_BUTTON_TEST_TAG), icon = { Icon( @@ -71,11 +82,12 @@ fun InputFileResource( if (currentState == LOADED) { { SquareIconButton( + enabled = inputShellState != InputShellState.DISABLED, modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_BUTTON_TEST_TAG), icon = { Icon( - imageVector = Icons.Outlined.FileUpload, - contentDescription = "Upload Icon Button", + imageVector = Icons.Outlined.FileDownload, + contentDescription = "Download Icon Button", ) }, ) { @@ -103,11 +115,12 @@ fun InputFileResource( when (currentState) { ADD -> { Button( + enabled = inputShellState != InputShellState.DISABLED, modifier = Modifier .testTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG) .padding(end = Spacing.Spacing16) .fillMaxWidth(), - style = ButtonStyle.ELEVATED, + style = ButtonStyle.KEYBOARDKEY, text = buttonText, icon = { Icon( @@ -125,16 +138,23 @@ fun InputFileResource( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center, ) { - ProgressIndicator( - modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + PROGRESS_INDICATOR_TEST_TAG), - type = ProgressIndicatorType.CIRCULAR, - ) + Box( + Modifier + .padding(top = Spacing.Spacing4, bottom = Spacing.Spacing4) + .size(Spacing.Spacing48), + ) { + ProgressIndicator( + modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + PROGRESS_INDICATOR_TEST_TAG), + type = ProgressIndicatorType.CIRCULAR, + ) + } } } LOADED -> { fileName.value?.let { BasicTextField( - modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG), + enabled = inputShellState != InputShellState.DISABLED, + modifier = Modifier.textFieldHoverPointerIcon(enabled = false).testTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG), helper = fileWeight.value, helperStyle = InputStyle.WITH_HELPER_AFTER, inputText = it, From d4f2aefdefe5343680f14e2729adde9a2c9de3e7 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 16 Oct 2023 10:42:38 +0200 Subject: [PATCH 10/16] update: [ANDROAPP-5575] Code formatted --- .../mobile/ui/designsystem/component/InputFileResource.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 7f99a6df2..bac5c2602 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -1,7 +1,5 @@ package org.hisp.dhis.mobile.ui.designsystem.component -import androidx.compose.foundation.hoverable -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row @@ -20,15 +18,11 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.input.pointer.PointerIcon -import androidx.compose.ui.input.pointer.pointerHoverIcon -import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.testTag import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.LOADED import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.UPLOADING import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing -import org.hisp.dhis.mobile.ui.designsystem.theme.hoverPointerIcon import org.hisp.dhis.mobile.ui.designsystem.theme.textFieldHoverPointerIcon const val INPUT_FILE_TEST_TAG = "INPUT_FILE_RESOURCE_" From 7a8cc6e8b05c606f11c6c1288bdb9c144fbc756e Mon Sep 17 00:00:00 2001 From: = Date: Tue, 17 Oct 2023 13:38:27 +0200 Subject: [PATCH 11/16] update: [ANDROAPP-5575] helper removed, Text added, using buttonblock instead button, visual changes --- .../component/InputFileResource.kt | 73 +++++++++++-------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index bac5c2602..62aaf78c7 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -11,19 +11,22 @@ import androidx.compose.material.icons.outlined.Cancel import androidx.compose.material.icons.outlined.FileDownload import androidx.compose.material.icons.outlined.FileUpload import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.ADD import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.LOADED import org.hisp.dhis.mobile.ui.designsystem.component.UploadFileState.UPLOADING import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing -import org.hisp.dhis.mobile.ui.designsystem.theme.textFieldHoverPointerIcon +import org.hisp.dhis.mobile.ui.designsystem.theme.TextColor const val INPUT_FILE_TEST_TAG = "INPUT_FILE_RESOURCE_" const val CLEAR_BUTTON_TEST_TAG = "CLEAR_BUTTON" @@ -51,10 +54,9 @@ fun InputFileResource( mutableStateOf(uploadFileState) } - val primaryButton: @Composable (() -> Unit)? = if (currentState == LOADED) { + val primaryButton: @Composable (() -> Unit)? = if (currentState == LOADED && inputShellState != InputShellState.DISABLED) { { IconButton( - enabled = inputShellState != InputShellState.DISABLED, modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + CLEAR_BUTTON_TEST_TAG), icon = { Icon( @@ -76,7 +78,6 @@ fun InputFileResource( if (currentState == LOADED) { { SquareIconButton( - enabled = inputShellState != InputShellState.DISABLED, modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_BUTTON_TEST_TAG), icon = { Icon( @@ -108,24 +109,28 @@ fun InputFileResource( inputField = { when (currentState) { ADD -> { - Button( - enabled = inputShellState != InputShellState.DISABLED, - modifier = Modifier - .testTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG) - .padding(end = Spacing.Spacing16) - .fillMaxWidth(), - style = ButtonStyle.KEYBOARDKEY, - text = buttonText, - icon = { - Icon( - imageVector = Icons.Outlined.FileUpload, - contentDescription = "Upload Icon Button", - ) + ButtonBlock( + primaryButton = { + Button( + enabled = inputShellState != InputShellState.DISABLED, + modifier = Modifier + .testTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG) + .padding(end = Spacing.Spacing16) + .fillMaxWidth(), + style = ButtonStyle.KEYBOARDKEY, + text = buttonText, + icon = { + Icon( + imageVector = Icons.Outlined.FileUpload, + contentDescription = "Upload Icon Button", + ) + }, + ) { + currentState = LOADED + onSelectFile.invoke() + } }, - ) { - currentState = LOADED - onSelectFile.invoke() - } + ) } UPLOADING -> { Row( @@ -145,15 +150,23 @@ fun InputFileResource( } } LOADED -> { - fileName.value?.let { - BasicTextField( - enabled = inputShellState != InputShellState.DISABLED, - modifier = Modifier.textFieldHoverPointerIcon(enabled = false).testTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG), - helper = fileWeight.value, - helperStyle = InputStyle.WITH_HELPER_AFTER, - inputText = it, - onInputChanged = { }, - ) + Row( + verticalAlignment = Alignment.CenterVertically, + ) { + fileName.value?.let { + Text( + text = it, + style = MaterialTheme.typography.bodyLarge.copy(color = if (inputShellState != InputShellState.DISABLED) TextColor.OnSurface else TextColor.OnDisabledSurface), + maxLines = 1, + ) + } + fileWeight.value?.let { + Text( + text = " $it", + style = MaterialTheme.typography.bodyLarge.copy(TextColor.OnDisabledSurface), + maxLines = 1, + ) + } } } } From 37364aa8f826f5a95e14a8d91ebd0ac8030fca81 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 17 Oct 2023 14:03:56 +0200 Subject: [PATCH 12/16] update: [ANDROAPP-5575] Tests fixed --- .../ui/designsystem/component/InputFileResource.kt | 5 ++++- .../designsystem/component/InputFileResourceTest.kt | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 62aaf78c7..438d64a96 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -33,7 +33,8 @@ const val CLEAR_BUTTON_TEST_TAG = "CLEAR_BUTTON" const val UPLOAD_BUTTON_TEST_TAG = "UPLOAD_BUTTON" const val ADD_BUTTON_TEST_TAG = "ADD_BUTTON" const val PROGRESS_INDICATOR_TEST_TAG = "PROGRESS_INDICATOR" -const val UPLOAD_HELPER_TEST_TAG = "UPLOAD_HELPER" +const val UPLOAD_TEXT_FILE_NAME_TEST_TAG = "UPLOAD_TEXT_FILE_NAME" +const val UPLOAD_TEXT_FILE_WEIGHT_TEST_TAG = "UPLOAD_TEXT_FILE_WEIGHT" const val SUPPORTING_TEXT_TEST_TAG = "SUPPORTING_TEXT" @Composable @@ -158,6 +159,7 @@ fun InputFileResource( text = it, style = MaterialTheme.typography.bodyLarge.copy(color = if (inputShellState != InputShellState.DISABLED) TextColor.OnSurface else TextColor.OnDisabledSurface), maxLines = 1, + modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_NAME_TEST_TAG), ) } fileWeight.value?.let { @@ -165,6 +167,7 @@ fun InputFileResource( text = " $it", style = MaterialTheme.typography.bodyLarge.copy(TextColor.OnDisabledSurface), maxLines = 1, + modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_WEIGHT_TEST_TAG), ) } } diff --git a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt index e73e22586..b073af65b 100644 --- a/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt +++ b/designsystem/src/desktopTest/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResourceTest.kt @@ -52,8 +52,10 @@ class InputFileResourceTest { rule.onNodeWithTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG).performClick() rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_BUTTON_TEST_TAG).assertExists() - rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG).assertExists() - rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG).assert(hasText(testFileName.value.toString() + " " + testFileWeight.value.toString())) + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_NAME_TEST_TAG).assertExists() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_WEIGHT_TEST_TAG).assertExists() + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_NAME_TEST_TAG).assert(hasText(testFileName.value.toString())) + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_WEIGHT_TEST_TAG).assert(hasText(" " + testFileWeight.value.toString())) } @Test @@ -94,12 +96,14 @@ class InputFileResourceTest { onUploadFile = {}, ) } - rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG).assert(hasText("test.filename.extension 256kb")) + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_NAME_TEST_TAG).assert(hasText("test.filename.extension")) + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_WEIGHT_TEST_TAG).assert(hasText(" 256kb")) rule.onNodeWithTag(INPUT_FILE_TEST_TAG + CLEAR_BUTTON_TEST_TAG).performClick() newFileName = "test_file" newFileWeight = "512gb" rule.onNodeWithTag(INPUT_FILE_TEST_TAG + ADD_BUTTON_TEST_TAG).performClick() - rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_HELPER_TEST_TAG).assert(hasText("test_file 512gb")) + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_NAME_TEST_TAG).assert(hasText("test_file")) + rule.onNodeWithTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_WEIGHT_TEST_TAG).assert(hasText(" 512gb")) } @Test From 438dd2a6a7f9589ddc75c0a85cccffa5a260de44 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 18 Oct 2023 12:30:48 +0200 Subject: [PATCH 13/16] update: [ANDROAPP-5575] Progress indicator spacing modified --- .../dhis/mobile/ui/designsystem/component/InputFileResource.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 438d64a96..5977850e3 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -140,7 +140,7 @@ fun InputFileResource( ) { Box( Modifier - .padding(top = Spacing.Spacing4, bottom = Spacing.Spacing4) + .padding(top = Spacing.Spacing8, bottom = Spacing.Spacing8) .size(Spacing.Spacing48), ) { ProgressIndicator( From 5ef16f34b087c4390e7bcf5e2caa7213839a58f7 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 18 Oct 2023 13:16:38 +0200 Subject: [PATCH 14/16] update: [ANDROAPP-5575] Modify color instead --- .../mobile/ui/designsystem/component/InputFileResource.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 5977850e3..937d7fbbf 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -131,6 +131,7 @@ fun InputFileResource( onSelectFile.invoke() } }, + modifier = Modifier.padding(top = Spacing.Spacing4, bottom = Spacing.Spacing4), ) } UPLOADING -> { @@ -140,7 +141,7 @@ fun InputFileResource( ) { Box( Modifier - .padding(top = Spacing.Spacing8, bottom = Spacing.Spacing8) + .padding(top = Spacing.Spacing4, bottom = Spacing.Spacing4) .size(Spacing.Spacing48), ) { ProgressIndicator( @@ -157,7 +158,7 @@ fun InputFileResource( fileName.value?.let { Text( text = it, - style = MaterialTheme.typography.bodyLarge.copy(color = if (inputShellState != InputShellState.DISABLED) TextColor.OnSurface else TextColor.OnDisabledSurface), + color = if (inputShellState != InputShellState.DISABLED) TextColor.OnSurface else TextColor.OnDisabledSurface, maxLines = 1, modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_NAME_TEST_TAG), ) @@ -165,7 +166,7 @@ fun InputFileResource( fileWeight.value?.let { Text( text = " $it", - style = MaterialTheme.typography.bodyLarge.copy(TextColor.OnDisabledSurface), + color = TextColor.OnDisabledSurface, maxLines = 1, modifier = Modifier.testTag(INPUT_FILE_TEST_TAG + UPLOAD_TEXT_FILE_WEIGHT_TEST_TAG), ) From 4ecbdb0480ddb3e9ab187f57cc0524ea5f04c7d3 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 18 Oct 2023 13:27:06 +0200 Subject: [PATCH 15/16] update: [ANDROAPP-5575] code formatted --- .../mobile/ui/designsystem/component/InputFileResource.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt index 937d7fbbf..e124efed8 100644 --- a/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt +++ b/designsystem/src/commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/InputFileResource.kt @@ -11,7 +11,6 @@ import androidx.compose.material.icons.outlined.Cancel import androidx.compose.material.icons.outlined.FileDownload import androidx.compose.material.icons.outlined.FileUpload import androidx.compose.material3.Icon -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState @@ -131,7 +130,6 @@ fun InputFileResource( onSelectFile.invoke() } }, - modifier = Modifier.padding(top = Spacing.Spacing4, bottom = Spacing.Spacing4), ) } UPLOADING -> { @@ -141,7 +139,7 @@ fun InputFileResource( ) { Box( Modifier - .padding(top = Spacing.Spacing4, bottom = Spacing.Spacing4) + .padding(top = Spacing.Spacing8, bottom = Spacing.Spacing8) .size(Spacing.Spacing48), ) { ProgressIndicator( From aad59213be71e4b773caab4bfc706d29a0f77c93 Mon Sep 17 00:00:00 2001 From: = Date: Thu, 19 Oct 2023 13:19:31 +0200 Subject: [PATCH 16/16] update: [ANDROAPP-5575] code formatted after rebase --- common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt index 604c416dd..0bf0c5417 100644 --- a/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt +++ b/common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt @@ -41,7 +41,6 @@ import org.hisp.dhis.common.screens.InputCheckBoxScreen import org.hisp.dhis.common.screens.InputCoordinateScreen import org.hisp.dhis.common.screens.InputDateTimeScreen import org.hisp.dhis.common.screens.InputDropDownScreen -import org.hisp.dhis.common.screens.InputFileResourceScreen import org.hisp.dhis.common.screens.InputEmailScreen import org.hisp.dhis.common.screens.InputFileResourceScreen import org.hisp.dhis.common.screens.InputIntegerScreen