Skip to content

Commit

Permalink
made tests more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
mazunin-v-jb committed Jun 17, 2024
1 parent d6382ec commit 45c2185
Showing 1 changed file with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import kotlin.experimental.ExperimentalNativeApi
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

@OptIn(ExperimentalNativeApi::class)
class TextFieldSelectionManagerTest {
Expand All @@ -38,7 +40,8 @@ class TextFieldSelectionManagerTest {
50.0f,
Rect(Offset(0f, 0f), Offset(744.0f, 50.0f))
)
assert(isStartVisible && isEndVisible)
assertTrue(isStartVisible)
assertTrue(isEndVisible)
}

@Test
Expand All @@ -56,7 +59,8 @@ class TextFieldSelectionManagerTest {
54.0f,
Rect(Offset(0f, 0f), Offset(744.0f, 54.0f))
)
assert(isStartVisible && isEndVisible)
assertTrue(isStartVisible)
assertTrue(isEndVisible)
}

@Test
Expand All @@ -74,67 +78,71 @@ class TextFieldSelectionManagerTest {
54.0f,
Rect(Offset(0f, 0f), Offset(744.0f, 54.0f))
)
assert(isStartVisible && isEndVisible)
assertTrue(isStartVisible)
assertTrue(isEndVisible)
}

@Test
fun isSelectionHandleIsVisible_ltr_text_not_visible() {
// Text = "I am TextField"
val isStartInvisible = !isSelectionHandleIsVisible(
val isStartVisible = isSelectionHandleIsVisible(
true,
Offset(94.58f, 50.0f),
50.0f,
Rect(Offset(0f, 217.0f), Offset(1194.0f, 2230.0f))
)
val isEndInvisible = !isSelectionHandleIsVisible(
val isEndVisible = isSelectionHandleIsVisible(
false,
Offset(272.38f, 50.0f),
50.0f,
Rect(Offset(0f, 217.0f), Offset(1194.0f, 2230.0f))
)
assert(isStartInvisible && isEndInvisible)
assertFalse(isStartVisible)
assertFalse(isEndVisible)
}

@Test
fun isSelectionHandleIsVisible_rtl_text_not_visible() {
// Text = "أنا حقل النص"
val isStartInvisible = !isSelectionHandleIsVisible(
val isStartVisible = isSelectionHandleIsVisible(
true,
Offset(153.84f, 56.0f),
54.0f,
Rect(Offset(0f, 217.0f), Offset(1194.0f, 2230.0f))
)
val isEndInvisible = !isSelectionHandleIsVisible(
val isEndVisible = isSelectionHandleIsVisible(
false,
Offset(92.93f, 56.0f),
54.0f,
Rect(Offset(0f, 217.0f), Offset(1194.0f, 2230.0f))
)
assert(isStartInvisible && isEndInvisible)
assertFalse(isStartVisible)
assertFalse(isEndVisible)
}

@Test
fun isSelectionHandleIsVisible_bidi_text_not_visible() {
// Text = "I am TextField أنا حقل النص"
val isStartInvisible = !isSelectionHandleIsVisible(
val isStartVisible = isSelectionHandleIsVisible(
true,
Offset(365.31f, 56.0f),
54.0f,
Rect(Offset(0f, 217.0f), Offset(1194.0f, 2230.0f))
)
val isEndInvisible = !isSelectionHandleIsVisible(
val isEndVisible = isSelectionHandleIsVisible(
false,
Offset(284.2f, 56.0f),
54.0f,
Rect(Offset(0f, 217.0f), Offset(1194.0f, 2230.0f))
)
assert(isStartInvisible && isEndInvisible)
assertFalse(isStartVisible)
assertFalse(isEndVisible)
}

@Test
fun isSelectionHandleIsVisible_start_is_invisible_end_is_visible() {
/* Selected text in multiline scrollable textfield, start handle is located above then visible bounds */
val isStartInvisible = !isSelectionHandleIsVisible(
val isStartVisible = isSelectionHandleIsVisible(
true,
Offset(94.79f, 250.0f),
50.0f,
Expand All @@ -146,7 +154,8 @@ class TextFieldSelectionManagerTest {
50.0f,
Rect(Offset(0f, 217.0f), Offset(1194.0f, 2230.0f))
)
assert(isStartInvisible && isEndVisible)
assertFalse(isStartVisible)
assertTrue(isEndVisible)
}

@Test
Expand All @@ -158,12 +167,13 @@ class TextFieldSelectionManagerTest {
50.0f,
Rect(Offset(0f, 211.0f), Offset(1194.0f, 2224.0f))
)
val isEndInvisible = !isSelectionHandleIsVisible(
val isEndVisible = isSelectionHandleIsVisible(
false,
Offset(82.97f, 2250.0f),
54.0f,
Rect(Offset(0f, 211.0f), Offset(744.0f, 54.0f))
)
assert(isStartVisible && isEndInvisible)
assertTrue(isStartVisible)
assertFalse(isEndVisible)
}
}

0 comments on commit 45c2185

Please sign in to comment.