-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add expandable floating action buttons tests
- Loading branch information
1 parent
dfe1545
commit f79a15b
Showing
7 changed files
with
260 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
...lin/com/divinelink/core/ui/components/expandablefab/ExpandableFloatingActionButtonTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package com.divinelink.core.ui.components.expandablefab | ||
|
||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.rounded.Add | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.assertIsNotDisplayed | ||
import androidx.compose.ui.test.onNodeWithContentDescription | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.performClick | ||
import com.divinelink.core.testing.ComposeTest | ||
import com.divinelink.core.testing.setContentWithTheme | ||
import com.divinelink.core.ui.IconWrapper | ||
import com.divinelink.core.ui.R | ||
import com.divinelink.core.ui.TestTags | ||
import com.divinelink.core.ui.UIText | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlin.test.Test | ||
|
||
class ExpandableFloatingActionButtonTest : ComposeTest() { | ||
|
||
@Test | ||
fun `test buttons are shown when fab button is clicked`() { | ||
var extraActionIsClicked = false | ||
|
||
val actionButtons = listOf( | ||
FloatingActionButtonItem( | ||
icon = IconWrapper.Vector(Icons.Rounded.Add), | ||
label = UIText.StringText("Add"), | ||
contentDescription = UIText.StringText("Add Button"), | ||
onClick = { extraActionIsClicked = true }, | ||
), | ||
FloatingActionButtonItem( | ||
icon = IconWrapper.Image(R.drawable.core_ui_ic_jellyseerr), | ||
label = UIText.StringText("Delete"), | ||
contentDescription = UIText.StringText("Delete Button"), | ||
onClick = { extraActionIsClicked = true }, | ||
), | ||
FloatingActionButtonItem( | ||
icon = IconWrapper.Icon(R.drawable.core_ui_ic_error_64), | ||
label = UIText.StringText("Close"), | ||
contentDescription = UIText.StringText("Close Button"), | ||
onClick = { extraActionIsClicked = true }, | ||
), | ||
) | ||
|
||
setContentWithTheme { | ||
ExpandableFloatActionButton( | ||
buttons = actionButtons, | ||
) | ||
} | ||
|
||
with(composeTestRule) { | ||
onNodeWithTag(TestTags.Components.ExpandableFab.BUTTON).assertIsDisplayed() | ||
onNodeWithContentDescription("Add Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Delete Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Close Button").assertIsNotDisplayed() | ||
|
||
onNodeWithTag(TestTags.Components.ExpandableFab.BUTTON).performClick() | ||
|
||
onNodeWithContentDescription("Add Button").assertIsDisplayed() | ||
onNodeWithContentDescription("Delete Button").assertIsDisplayed() | ||
onNodeWithContentDescription("Close Button").assertIsDisplayed() | ||
|
||
assertThat(extraActionIsClicked).isFalse() | ||
|
||
onNodeWithContentDescription("Add Button").performClick() | ||
|
||
onNodeWithTag(TestTags.Components.ExpandableFab.BUTTON).assertIsDisplayed() | ||
|
||
onNodeWithContentDescription("Add Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Delete Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Close Button").assertIsNotDisplayed() | ||
assertThat(extraActionIsClicked).isTrue() | ||
} | ||
} | ||
|
||
@Test | ||
fun `test icons are displayed`() { | ||
val actionButtons = listOf( | ||
FloatingActionButtonItem( | ||
icon = IconWrapper.Vector(Icons.Rounded.Add), | ||
label = UIText.StringText("Add"), | ||
contentDescription = UIText.StringText("Add Button"), | ||
onClick = { }, | ||
), | ||
FloatingActionButtonItem( | ||
icon = IconWrapper.Image(R.drawable.core_ui_ic_jellyseerr), | ||
label = UIText.StringText("Delete"), | ||
contentDescription = UIText.StringText("Delete Button"), | ||
onClick = { }, | ||
), | ||
FloatingActionButtonItem( | ||
icon = IconWrapper.Icon(R.drawable.core_ui_ic_error_64), | ||
label = UIText.StringText("Close"), | ||
contentDescription = UIText.StringText("Close Button"), | ||
onClick = { }, | ||
), | ||
) | ||
|
||
setContentWithTheme { | ||
ExpandableFloatActionButton( | ||
buttons = actionButtons, | ||
) | ||
} | ||
|
||
with(composeTestRule) { | ||
onNodeWithTag(TestTags.Components.ExpandableFab.BUTTON).assertIsDisplayed() | ||
|
||
onNodeWithContentDescription("Add Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Delete Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Close Button").assertIsNotDisplayed() | ||
|
||
onNodeWithTag(TestTags.Components.ExpandableFab.BUTTON).performClick() | ||
|
||
onNodeWithContentDescription("Add Button").assertIsDisplayed() | ||
onNodeWithContentDescription("Delete Button").assertIsDisplayed() | ||
onNodeWithContentDescription("Close Button").assertIsDisplayed() | ||
} | ||
} | ||
|
||
@Test | ||
fun `test clicking on background dismisses actions`() { | ||
val actionButtons = listOf( | ||
FloatingActionButtonItem( | ||
icon = IconWrapper.Vector(Icons.Rounded.Add), | ||
label = UIText.StringText("Add"), | ||
contentDescription = UIText.StringText("Add Button"), | ||
onClick = { }, | ||
), | ||
FloatingActionButtonItem( | ||
icon = IconWrapper.Image(R.drawable.core_ui_ic_jellyseerr), | ||
label = UIText.StringText("Delete"), | ||
contentDescription = UIText.StringText("Delete Button"), | ||
onClick = { }, | ||
), | ||
FloatingActionButtonItem( | ||
icon = IconWrapper.Icon(R.drawable.core_ui_ic_error_64), | ||
label = UIText.StringText("Close"), | ||
contentDescription = UIText.StringText("Close Button"), | ||
onClick = { }, | ||
), | ||
) | ||
|
||
setContentWithTheme { | ||
ExpandableFloatActionButton( | ||
buttons = actionButtons, | ||
) | ||
} | ||
|
||
with(composeTestRule) { | ||
onNodeWithTag(TestTags.Components.ExpandableFab.BUTTON).assertIsDisplayed() | ||
onNodeWithContentDescription("Add Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Delete Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Close Button").assertIsNotDisplayed() | ||
|
||
onNodeWithTag(TestTags.Components.ExpandableFab.BUTTON).performClick() | ||
|
||
onNodeWithContentDescription("Add Button").assertIsDisplayed() | ||
onNodeWithContentDescription("Delete Button").assertIsDisplayed() | ||
onNodeWithContentDescription("Close Button").assertIsDisplayed() | ||
|
||
onNodeWithTag(TestTags.Components.ExpandableFab.BACKGROUND).performClick() | ||
onNodeWithContentDescription("Add Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Delete Button").assertIsNotDisplayed() | ||
onNodeWithContentDescription("Close Button").assertIsNotDisplayed() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters