Skip to content

Commit

Permalink
add: semantics matchers and interactions for αὐτός buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanbarrossilva committed Mar 27, 2024
1 parent 80e9a1c commit 4cf7a21
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright © 2024 Orca
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If
* not, see https://www.gnu.org/licenses.
*/

package com.jeanbarrossilva.orca.platform.autos.test.kit.action.button

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.PrimaryButton
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.SecondaryButton
import com.jeanbarrossilva.orca.platform.autos.theme.AutosTheme
import org.junit.Rule
import org.junit.Test

internal class SemanticsMatcherExtensionsTests {
@get:Rule val composeRule = createComposeRule()

@Test
fun matchesPrimaryButton() {
composeRule
.apply { setContent { AutosTheme { PrimaryButton(onClick = {}) {} } } }
.onNode(isPrimaryButton())
.assertIsDisplayed()
}

@Test
fun matchesSecondaryButton() {
composeRule
.apply { setContent { AutosTheme { SecondaryButton(onClick = {}) {} } } }
.onNode(isSecondaryButton())
.assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright © 2024 Orca
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If
* not, see https://www.gnu.org/licenses.
*/

package com.jeanbarrossilva.orca.platform.autos.test.kit.action.button

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.PrimaryButton
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.SecondaryButton
import com.jeanbarrossilva.orca.platform.autos.theme.AutosTheme
import org.junit.Rule
import org.junit.Test

internal class SemanticsNodeInteractionsProviderExtensionsTests {
@get:Rule val composeRule = createComposeRule()

@Test
fun findsPrimaryButton() {
composeRule
.apply { setContent { AutosTheme { PrimaryButton(onClick = {}) {} } } }
.onPrimaryButton()
.assertIsDisplayed()
}

@Test
fun findsSecondaryButton() {
composeRule
.apply { setContent { AutosTheme { SecondaryButton(onClick = {}) {} } } }
.onSecondaryButton()
.assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright © 2024 Orca
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If
* not, see https://www.gnu.org/licenses.
*/

package com.jeanbarrossilva.orca.platform.autos.test.kit.action.button

import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.hasTestTag
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.PRIMARY_BUTTON_TAG
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.PrimaryButton
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.SECONDARY_BUTTON_TAG
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.SecondaryButton

/** [SemanticsMatcher] that matches a [PrimaryButton]. */
fun isPrimaryButton(): SemanticsMatcher {
return hasTestTag(PRIMARY_BUTTON_TAG)
}

/** [SemanticsMatcher] that matches a [SecondaryButton]. */
fun isSecondaryButton(): SemanticsMatcher {
return hasTestTag(SECONDARY_BUTTON_TAG)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright © 2024 Orca
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If
* not, see https://www.gnu.org/licenses.
*/

package com.jeanbarrossilva.orca.platform.autos.test.kit.action.button

import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.PrimaryButton
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.SecondaryButton

/** [SemanticsNodeInteraction] of a [PrimaryButton]. */
fun SemanticsNodeInteractionsProvider.onPrimaryButton(): SemanticsNodeInteraction {
return onNode(isPrimaryButton())
}

/** [SemanticsNodeInteraction] of a [SecondaryButton]. */
fun SemanticsNodeInteractionsProvider.onSecondaryButton(): SemanticsNodeInteraction {
return onNode(isSecondaryButton())
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import com.jeanbarrossilva.orca.platform.autos.colors.asColor
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.skeleton.Button
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.skeleton.ButtonDefaults as _ButtonDefaults
import com.jeanbarrossilva.orca.platform.autos.theme.AutosTheme
import com.jeanbarrossilva.orca.platform.autos.theme.MultiThemePreview

/** Tag that identifies a [PrimaryButton] for testing purposes. */
const val PRIMARY_BUTTON_TAG = "primary-button"

/**
* [Button] that represents a primary action, performed or requested to be performed through
* [onClick]; usually is placed on the bottom of the screen, filling its width.
Expand All @@ -46,7 +50,7 @@ fun PrimaryButton(
Button {
ElevatedButton(
onClick = { load(onClick) },
modifier,
modifier.testTag(PRIMARY_BUTTON_TAG),
isEnabled,
_ButtonDefaults.shape,
colors =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import com.jeanbarrossilva.orca.platform.autos.colors.asColor
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.skeleton.Button as _Button
import com.jeanbarrossilva.orca.platform.autos.kit.action.button.skeleton.ButtonDefaults as _ButtonDefaults
Expand All @@ -31,6 +32,9 @@ import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking

/** Tag that identifies the [SecondaryButton] for testing purposes. */
const val SECONDARY_BUTTON_TAG = "secondary-button"

/**
* [Button][_Button] that executes a secondary action when clicked, and is usually preceded by a
* [PrimaryButton] within a [ButtonBar].
Expand All @@ -49,7 +53,7 @@ fun SecondaryButton(
_Button {
Button(
onClick = { load(onClick) },
modifier,
modifier.testTag(SECONDARY_BUTTON_TAG),
shape = _ButtonDefaults.shape,
colors =
ButtonDefaults.buttonColors(
Expand Down

0 comments on commit 4cf7a21

Please sign in to comment.