|
| 1 | +package to.bitkit.ui.screens.wallets.sheets |
| 2 | + |
| 3 | +import androidx.compose.ui.test.* |
| 4 | +import androidx.compose.ui.test.junit4.createComposeRule |
| 5 | +import dagger.hilt.android.testing.HiltAndroidRule |
| 6 | +import dagger.hilt.android.testing.HiltAndroidTest |
| 7 | +import org.junit.Before |
| 8 | +import org.junit.Rule |
| 9 | +import org.junit.Test |
| 10 | +import to.bitkit.models.NewTransactionSheetDetails |
| 11 | +import to.bitkit.models.NewTransactionSheetDirection |
| 12 | +import to.bitkit.models.NewTransactionSheetType |
| 13 | + |
| 14 | +@HiltAndroidTest |
| 15 | +class NewTransactionSheetViewTest { |
| 16 | + |
| 17 | + @get:Rule |
| 18 | + val composeTestRule = createComposeRule() |
| 19 | + |
| 20 | + @get:Rule |
| 21 | + val hiltRule = HiltAndroidRule(this) |
| 22 | + |
| 23 | + @Before |
| 24 | + fun setup() { |
| 25 | + hiltRule.inject() |
| 26 | + composeTestRule.mainClock.autoAdvance = false |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + fun testSentLightningTransaction() { |
| 31 | + // Arrange |
| 32 | + val details = NewTransactionSheetDetails( |
| 33 | + sats = 10000L, |
| 34 | + type = NewTransactionSheetType.LIGHTNING, |
| 35 | + direction = NewTransactionSheetDirection.SENT |
| 36 | + ) |
| 37 | + var detailsClicked = false |
| 38 | + var closeClicked = false |
| 39 | + |
| 40 | + // Act |
| 41 | + composeTestRule.setContent { |
| 42 | + NewTransactionSheetView( |
| 43 | + details = details, |
| 44 | + onCloseClick = { closeClicked = true }, |
| 45 | + onDetailClick = { detailsClicked = true } |
| 46 | + ) |
| 47 | + } |
| 48 | + |
| 49 | + // Wait for composition and layout |
| 50 | + composeTestRule.mainClock.advanceTimeBy(1000) |
| 51 | + composeTestRule.waitForIdle() |
| 52 | + |
| 53 | + // Assert |
| 54 | + composeTestRule.onNodeWithTag("new_transaction_sheet").assertExists() |
| 55 | + composeTestRule.onNodeWithTag("transaction_sent_image").assertExists() |
| 56 | + composeTestRule.onNodeWithTag("transaction_received_image").assertDoesNotExist() |
| 57 | + composeTestRule.onNodeWithTag("confetti_animation").assertExists() |
| 58 | + |
| 59 | + composeTestRule.mainClock.advanceTimeBy(1000) |
| 60 | + composeTestRule.waitForIdle() |
| 61 | + |
| 62 | +// composeTestRule.onNodeWithTag("balance_header").assertExists() Doesn't work because of viewmodel instance |
| 63 | + composeTestRule.onNodeWithTag("sent_buttons_row").assertExists() |
| 64 | + |
| 65 | + // Verify buttons exist and click interactions work |
| 66 | + composeTestRule.onNodeWithTag("details_button").assertExists().performClick() |
| 67 | + composeTestRule.waitForIdle() |
| 68 | + assert(detailsClicked) |
| 69 | + |
| 70 | + composeTestRule.onNodeWithTag("close_button").assertExists().performClick() |
| 71 | + composeTestRule.waitForIdle() |
| 72 | + assert(closeClicked) |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + fun testReceivedLightningTransaction() { |
| 77 | + // Arrange |
| 78 | + val details = NewTransactionSheetDetails( |
| 79 | + sats = 5000L, |
| 80 | + type = NewTransactionSheetType.LIGHTNING, |
| 81 | + direction = NewTransactionSheetDirection.RECEIVED |
| 82 | + ) |
| 83 | + var closeClicked = false |
| 84 | + |
| 85 | + // Act |
| 86 | + composeTestRule.setContent { |
| 87 | + NewTransactionSheetView( |
| 88 | + details = details, |
| 89 | + onCloseClick = { closeClicked = true }, |
| 90 | + onDetailClick = { } |
| 91 | + ) |
| 92 | + } |
| 93 | + |
| 94 | + // Wait for composition and layout |
| 95 | + composeTestRule.mainClock.advanceTimeBy(1000) |
| 96 | + composeTestRule.waitForIdle() |
| 97 | + |
| 98 | + // Assert |
| 99 | + composeTestRule.onNodeWithTag("new_transaction_sheet").assertExists() |
| 100 | + composeTestRule.onNodeWithTag("transaction_received_image").assertExists() |
| 101 | + composeTestRule.onNodeWithTag("transaction_sent_image").assertDoesNotExist() |
| 102 | + |
| 103 | + // Wait again for animations |
| 104 | + composeTestRule.mainClock.advanceTimeBy(1000) |
| 105 | + composeTestRule.waitForIdle() |
| 106 | + |
| 107 | + composeTestRule.onNodeWithTag("confetti_animation").assertExists() |
| 108 | +// composeTestRule.onNodeWithTag("balance_header").assertExists() |
| 109 | + composeTestRule.onNodeWithTag("sent_buttons_row").assertDoesNotExist() |
| 110 | + |
| 111 | + // Verify only OK button exists for received transactions |
| 112 | + composeTestRule.onNodeWithTag("ok_button").assertExists().performClick() |
| 113 | + composeTestRule.waitForIdle() |
| 114 | + assert(closeClicked) |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + fun testOnchainTransaction() { |
| 119 | + // Arrange |
| 120 | + val details = NewTransactionSheetDetails( |
| 121 | + sats = 75000L, |
| 122 | + type = NewTransactionSheetType.ONCHAIN, |
| 123 | + direction = NewTransactionSheetDirection.RECEIVED |
| 124 | + ) |
| 125 | + |
| 126 | + // Act |
| 127 | + composeTestRule.setContent { |
| 128 | + NewTransactionSheetView( |
| 129 | + details = details, |
| 130 | + onCloseClick = { }, |
| 131 | + onDetailClick = { } |
| 132 | + ) |
| 133 | + } |
| 134 | + |
| 135 | + // Assert - verify orange confetti is used for onchain |
| 136 | + composeTestRule.onNodeWithTag("confetti_animation").assertExists() |
| 137 | + } |
| 138 | +} |
0 commit comments