Skip to content

Commit

Permalink
Add keyboard view first row keys UI tests (#29)
Browse files Browse the repository at this point in the history
* fix: πŸ› resolve counter clockwise button not working

* test: πŸ’ add first row key counter clockwise button test case

* refactor: πŸ’‘ extract setUp and click actions

* test: πŸ’ add wide notation test case

* test: πŸ’ add turn degree test cases

* refactor: πŸ’‘ select control key buttons with test tag

* refactor: πŸ’‘ extract key assertion

* test: πŸ’ modify rotation direction test case
  • Loading branch information
ricky9667 authored May 10, 2024
1 parent bfbec3e commit acecabc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fun HushKeyboardContent(state: KeyboardState) {
},
rotateDirectionButtonAction = {
keyConfigState = keyConfigState.copy(
isCounterClockwise = keyConfigState.isCounterClockwise
isCounterClockwise = !keyConfigState.isCounterClockwise
)
if (state.vibrateOnTap) vibratorManager?.maybeVibrate()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -55,7 +56,7 @@ fun ControlKeyButtonRow(
}
)
ControlKeyButton(
modifier = controlKeyModifier,
modifier = controlKeyModifier.testTag("RotateDirectionButton"),
onClick = rotateDirectionButtonAction,
isDarkTheme = isDarkTheme,
content = {
Expand All @@ -68,7 +69,7 @@ fun ControlKeyButtonRow(
}
)
ControlKeyButton(
modifier = controlKeyModifier,
modifier = controlKeyModifier.testTag("TurnDegreeButton"),
onClick = turnDegreeButtonAction,
isDarkTheme = isDarkTheme,
content = {
Expand All @@ -81,7 +82,7 @@ fun ControlKeyButtonRow(
}
)
ControlKeyButton(
modifier = controlKeyModifier,
modifier = controlKeyModifier.testTag("WideTurnButton"),
onClick = wideTurnButtonAction,
isDarkTheme = isDarkTheme,
content = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.rickyhu.hushkeyboard.ui

import androidx.compose.ui.test.assertHasClickAction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsEnabled
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 com.rickyhu.hushkeyboard.keyboard.HushKeyboardContent
import com.rickyhu.hushkeyboard.keyboard.KeyboardState
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand All @@ -16,16 +20,69 @@ class HushKeyboardUiTest {
@get:Rule
val composeTestRule = createComposeRule()

@Test
fun `First row key should exist, should be enabled, and should have click action`() {
@Before
fun setUp() {
composeTestRule.setContent {
HushKeyboardContent(state = KeyboardState())
}
}

@Test
fun `First row key should exist, should be enabled, and should have click action`() {
keyButtonShouldBe("R ")
}

@Test
fun `First row key should show ' notation after clicking counter clockwise button`() {
clickCounterClockwiseButton()
keyButtonShouldBe("R' ")

clickCounterClockwiseButton()
keyButtonShouldBe("R ")
}

@Test
fun `First row key should show w notation after clicking wide notation button`() {
clickWideNotationButton()
keyButtonShouldBe("Rw ")
}

@Test
fun `First row key should show correct turn degree after clicking turn degree button`() {
clickTurnDegreeButton()
keyButtonShouldBe("R2 ")

clickTurnDegreeButton()
keyButtonShouldBe("R3 ")

clickTurnDegreeButton()
keyButtonShouldBe("R ")
}

private fun keyButtonShouldBe(text: String) {
composeTestRule
.onNodeWithText("R ")
.onNodeWithText(text)
.assertExists()
.assertIsEnabled()
.assertIsDisplayed()
.assertHasClickAction()
}

private fun clickCounterClockwiseButton() {
composeTestRule
.onNodeWithTag("RotateDirectionButton")
.performClick()
}

private fun clickTurnDegreeButton() {
composeTestRule
.onNodeWithTag("TurnDegreeButton")
.performClick()
}

private fun clickWideNotationButton() {
composeTestRule
.onNodeWithTag("WideTurnButton")
.performClick()
}
}

0 comments on commit acecabc

Please sign in to comment.