From a8e5a262d9eac9e0579803868f927e17cb053be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=88=D0=B5=20=D0=98=D0=BC=D1=8F?= Date: Mon, 26 May 2025 16:52:15 +0300 Subject: [PATCH] tests --- .../com/example/libary/BottomSheetTest.kt | 22 +++++++++ .../java/com/example/libary/ButtonChipTest.kt | 22 +++++++++ .../java/com/example/libary/InputTest.kt | 26 +++++++++++ .../java/com/example/libary/TabbarTest.kt | 46 +++++++++++++++++++ .../main/java/com/example/libary/Select.kt | 3 +- .../main/java/com/example/libary/Tabbar.kt | 3 +- 6 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 libary/src/androidTest/java/com/example/libary/ButtonChipTest.kt create mode 100644 libary/src/androidTest/java/com/example/libary/InputTest.kt create mode 100644 libary/src/androidTest/java/com/example/libary/TabbarTest.kt diff --git a/libary/src/androidTest/java/com/example/libary/BottomSheetTest.kt b/libary/src/androidTest/java/com/example/libary/BottomSheetTest.kt index 14a429f..9519cef 100644 --- a/libary/src/androidTest/java/com/example/libary/BottomSheetTest.kt +++ b/libary/src/androidTest/java/com/example/libary/BottomSheetTest.kt @@ -1,11 +1,33 @@ package com.example.libary +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +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 androidx.compose.ui.test.performClick +import org.junit.Rule import org.junit.Test class BottomSheetTest { + @get:Rule + val composeRule = createComposeRule() + @Test fun test1() { + composeRule.setContent { + val ins = remember { mutableStateOf("") } + Select( + value = ins, + data = listOf( + "test1" + ) + ) + } + composeRule.onNodeWithTag("dr_1").performClick() + composeRule.onNodeWithText("test1").assertIsDisplayed() } } \ No newline at end of file diff --git a/libary/src/androidTest/java/com/example/libary/ButtonChipTest.kt b/libary/src/androidTest/java/com/example/libary/ButtonChipTest.kt new file mode 100644 index 0000000..c34d2e4 --- /dev/null +++ b/libary/src/androidTest/java/com/example/libary/ButtonChipTest.kt @@ -0,0 +1,22 @@ +package com.example.libary + +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.test.junit4.createComposeRule +import org.junit.Assert +import org.junit.Rule +import org.junit.Test + +class ButtonChipTest { + + @get:Rule + val composeRule = createComposeRule() + + @Test + fun test() { + Assert.assertEquals(ChipButtonState.On.textColor, Color(0xFFFFFFFF)) + Assert.assertEquals(ChipButtonState.On.containerColor, Color(0xFF1A6FEE)) + + Assert.assertEquals(ChipButtonState.Off.textColor, Color(0xFF7E7E9A)) + Assert.assertEquals(ChipButtonState.Off.containerColor, Color(0xFFF5F5F9)) + } +} \ No newline at end of file diff --git a/libary/src/androidTest/java/com/example/libary/InputTest.kt b/libary/src/androidTest/java/com/example/libary/InputTest.kt new file mode 100644 index 0000000..5e59587 --- /dev/null +++ b/libary/src/androidTest/java/com/example/libary/InputTest.kt @@ -0,0 +1,26 @@ +package com.example.libary + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithText +import org.junit.Rule +import org.junit.Test + +class InputTest { + + @get:Rule + val composeRule = createComposeRule() + + @Test + fun test1() { + composeRule.setContent { + Input( + value = "", + onValueChange = {}, + errorText = "error test" + ) + } + + composeRule.onNodeWithText("error test").assertIsDisplayed() + } +} \ No newline at end of file diff --git a/libary/src/androidTest/java/com/example/libary/TabbarTest.kt b/libary/src/androidTest/java/com/example/libary/TabbarTest.kt new file mode 100644 index 0000000..e7010b7 --- /dev/null +++ b/libary/src/androidTest/java/com/example/libary/TabbarTest.kt @@ -0,0 +1,46 @@ +package com.example.libary + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performClick +import androidx.compose.ui.unit.dp +import org.junit.Assert +import org.junit.Rule +import org.junit.Test + +class TabbarTest { + + @get:Rule + val composeRule = createComposeRule() + + @Test + fun test() { + + var valueName = "" + + composeRule.setContent { + val value = remember { mutableStateOf(defaultTabBarData[0]) } + + LaunchedEffect(value.value) { + valueName = value.value.name + } + + Column { + Spacer(Modifier.height(100.dp)) + TabBar( + value = value + ) + } + } + + composeRule.onNodeWithTag("Главная").performClick() + Assert.assertEquals(valueName, "Главная") + } +} \ No newline at end of file diff --git a/libary/src/main/java/com/example/libary/Select.kt b/libary/src/main/java/com/example/libary/Select.kt index ecb1582..0c160f3 100644 --- a/libary/src/main/java/com/example/libary/Select.kt +++ b/libary/src/main/java/com/example/libary/Select.kt @@ -17,6 +17,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 androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview @@ -65,7 +66,7 @@ fun Select( Image( painter = painterResource(R.drawable.dr_1), contentDescription = null, - modifier = Modifier.clickable { + modifier = Modifier.testTag("dr_1").clickable { modal = true } ) diff --git a/libary/src/main/java/com/example/libary/Tabbar.kt b/libary/src/main/java/com/example/libary/Tabbar.kt index 7b739e9..2f7e3c4 100644 --- a/libary/src/main/java/com/example/libary/Tabbar.kt +++ b/libary/src/main/java/com/example/libary/Tabbar.kt @@ -19,6 +19,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.draw.shadow import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview @@ -26,7 +27,6 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.libary.theme.AccentColor import com.example.libary.theme.IconsColor -import com.example.libary.theme.InputIconColor import com.example.libary.theme.TabBarShad data class TabBarData( @@ -71,6 +71,7 @@ fun TabBar( data.forEach { NavigationBarItem( selected = value.value == it, + modifier = Modifier.testTag(it.name), colors = NavigationBarItemDefaults.colors( indicatorColor = Color.Transparent ),