Add tests
This commit is contained in:
parent
6bad590845
commit
8999932566
@ -291,10 +291,11 @@ class MainActivity : ComponentActivity() {
|
|||||||
state = ButtonState.Chips
|
state = ButtonState.Chips
|
||||||
)
|
)
|
||||||
|
|
||||||
SecondaryAppButton(
|
AppButton(
|
||||||
label = "Популярное",
|
label = "Популярное",
|
||||||
onClick = {},
|
onClick = {},
|
||||||
state = ButtonState.Chips
|
state = ButtonState.Chips,
|
||||||
|
enabled = false
|
||||||
)
|
)
|
||||||
|
|
||||||
CartButton(
|
CartButton(
|
||||||
|
@ -56,4 +56,8 @@ dependencies {
|
|||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
androidTestImplementation(libs.androidx.junit)
|
androidTestImplementation(libs.androidx.junit)
|
||||||
androidTestImplementation(libs.androidx.espresso.core)
|
androidTestImplementation(libs.androidx.espresso.core)
|
||||||
|
androidTestImplementation(platform(libs.androidx.compose.bom))
|
||||||
|
androidTestImplementation(libs.androidx.ui.test.junit4)
|
||||||
|
debugImplementation(libs.androidx.ui.tooling)
|
||||||
|
debugImplementation(libs.androidx.ui.test.manifest)
|
||||||
}
|
}
|
65
core/src/androidTest/java/com/example/core/ComponentsTest.kt
Normal file
65
core/src/androidTest/java/com/example/core/ComponentsTest.kt
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package com.example.core
|
||||||
|
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.test.assertIsDisplayed
|
||||||
|
import androidx.compose.ui.test.junit4.createAndroidComposeRule
|
||||||
|
import androidx.compose.ui.test.onNodeWithTag
|
||||||
|
import androidx.compose.ui.test.onNodeWithText
|
||||||
|
import androidx.compose.ui.test.performClick
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.example.core.component.button.AppButton
|
||||||
|
import com.example.core.component.button.ButtonState
|
||||||
|
import com.example.core.component.select.AppSelector
|
||||||
|
import com.example.core.component.select.Option
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class ComponentsTest {
|
||||||
|
@get:Rule
|
||||||
|
val composeTestRule = createAndroidComposeRule<ComponentActivity>()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun test_input_error() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun test_app_selector() {
|
||||||
|
composeTestRule.setContent {
|
||||||
|
var selectedOption1 by remember { mutableStateOf<Option?>(null) }
|
||||||
|
|
||||||
|
AppSelector(
|
||||||
|
selectedOption = selectedOption1,
|
||||||
|
options = listOf(
|
||||||
|
Option(label = "Мужской"),
|
||||||
|
Option(label = "Женский")
|
||||||
|
),
|
||||||
|
onOptionSelect = { selectedOption1 = it },
|
||||||
|
hint = "Пол"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
composeTestRule.onNodeWithText("Пол").performClick()
|
||||||
|
composeTestRule.onNodeWithTag("AppBottomSheet").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun test_chips_button() {
|
||||||
|
composeTestRule.setContent {
|
||||||
|
AppButton(
|
||||||
|
label = "Популярное",
|
||||||
|
onClick = {},
|
||||||
|
state = ButtonState.Chips,
|
||||||
|
enabled = false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
composeTestRule.onNodeWithText("Популярное").assertIsDisplayed()
|
||||||
|
}
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
package com.example.core
|
|
||||||
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
||||||
|
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
|
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instrumented test, which will execute on an Android device.
|
|
||||||
*
|
|
||||||
* See [testing documentation](http://d.android.com/tools/testing).
|
|
||||||
*/
|
|
||||||
@RunWith(AndroidJUnit4::class)
|
|
||||||
class ExampleInstrumentedTest {
|
|
||||||
@Test
|
|
||||||
fun useAppContext() {
|
|
||||||
// Context of the app under test.
|
|
||||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
|
||||||
assertEquals("com.example.core.test", appContext.packageName)
|
|
||||||
}
|
|
||||||
}
|
|
@ -29,6 +29,7 @@ fun AppButton(
|
|||||||
enabled: Boolean = true
|
enabled: Boolean = true
|
||||||
) {
|
) {
|
||||||
Box(contentAlignment = Alignment.Center, modifier = modifier) {
|
Box(contentAlignment = Alignment.Center, modifier = modifier) {
|
||||||
|
val commonCondition = state is ButtonState.Chips
|
||||||
Button(
|
Button(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.then(state.width())
|
.then(state.width())
|
||||||
@ -38,17 +39,22 @@ fun AppButton(
|
|||||||
enabled = enabled,
|
enabled = enabled,
|
||||||
colors = ButtonDefaults.buttonColors().copy(
|
colors = ButtonDefaults.buttonColors().copy(
|
||||||
containerColor = CustomTheme.colors.accent,
|
containerColor = CustomTheme.colors.accent,
|
||||||
disabledContainerColor = CustomTheme.colors.accentInactive
|
disabledContainerColor = if (commonCondition) CustomTheme.colors.inputBg else CustomTheme.colors.accentInactive
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text = label,
|
text = label,
|
||||||
style = state.typography()
|
style = state.typography()
|
||||||
.copy(color = CustomTheme.colors.white, textAlign = TextAlign.Center),
|
.copy(
|
||||||
|
color = if (commonCondition && !enabled) CustomTheme.colors.description else CustomTheme.colors.white,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = Modifier.then(state.width()).padding(horizontal = state.padding()),
|
modifier = Modifier
|
||||||
|
.then(state.width())
|
||||||
|
.padding(horizontal = state.padding()),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package com.example.core.component.button
|
package com.example.core.component.button
|
||||||
|
|
||||||
import androidx.compose.animation.animateColorAsState
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
@ -9,7 +8,6 @@ import androidx.compose.material3.Button
|
|||||||
import androidx.compose.material3.ButtonDefaults
|
import androidx.compose.material3.ButtonDefaults
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
@ -30,9 +28,6 @@ fun SecondaryAppButton(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
enabled: Boolean = true
|
enabled: Boolean = true
|
||||||
) {
|
) {
|
||||||
val textColor by animateColorAsState(
|
|
||||||
if (state is ButtonState.Chips) CustomTheme.colors.description else CustomTheme.colors.black
|
|
||||||
)
|
|
||||||
Box(contentAlignment = Alignment.Center, modifier = modifier) {
|
Box(contentAlignment = Alignment.Center, modifier = modifier) {
|
||||||
Button(
|
Button(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
@ -49,7 +44,8 @@ fun SecondaryAppButton(
|
|||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
text = label,
|
text = label,
|
||||||
style = state.typography().copy(color = textColor, textAlign = TextAlign.Center),
|
style = state.typography()
|
||||||
|
.copy(color = CustomTheme.colors.black, textAlign = TextAlign.Center),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
@ -63,7 +63,7 @@ fun EnterInputField(
|
|||||||
|
|
||||||
var hasFocus by rememberSaveable { mutableStateOf(false) }
|
var hasFocus by rememberSaveable { mutableStateOf(false) }
|
||||||
|
|
||||||
var showPassword by rememberSaveable { mutableStateOf(true) }
|
var showPassword by rememberSaveable { mutableStateOf(false) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Установка цвета рамки в зависимости от состояния
|
* Установка цвета рамки в зависимости от состояния
|
||||||
|
@ -19,7 +19,6 @@ import androidx.compose.material3.ExperimentalMaterial3Api
|
|||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
import androidx.compose.material3.ripple
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@ -30,6 +29,7 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.platform.testTag
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.example.core.theme.CustomIcons
|
import com.example.core.theme.CustomIcons
|
||||||
import com.example.core.theme.CustomTheme
|
import com.example.core.theme.CustomTheme
|
||||||
@ -54,7 +54,11 @@ fun AppSelector(
|
|||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
if (showSheet) {
|
if (showSheet) {
|
||||||
AppBottomSheet(sheetState = sheetState, onDismissRequest = { showSheet = false }) {
|
AppBottomSheet(
|
||||||
|
sheetState = sheetState,
|
||||||
|
onDismissRequest = { showSheet = false },
|
||||||
|
modifier = Modifier.testTag("AppBottomSheet")
|
||||||
|
) {
|
||||||
Column(verticalArrangement = Arrangement.Center) {
|
Column(verticalArrangement = Arrangement.Center) {
|
||||||
options.forEach { option ->
|
options.forEach { option ->
|
||||||
Row(
|
Row(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user