Skip to content

Commit

Permalink
Add AccountsTest.kt & remove "UI tests" workflow from README
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliyan Germanov committed Nov 22, 2021
1 parent 48b114f commit 6cbe418
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 8 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
![Latest Release](https://img.shields.io/github/v/release/iliyangermanov/ivy-wallet)
[![UI Tests](https://github.com/ILIYANGERMANOV/ivy-wallet/actions/workflows/ui_tests.yml/badge.svg)](https://github.com/ILIYANGERMANOV/ivy-wallet/actions/workflows/ui_tests.yml)
[![Lint](https://github.com/ILIYANGERMANOV/ivy-wallet/actions/workflows/lint.yml/badge.svg)](https://github.com/ILIYANGERMANOV/ivy-wallet/actions/workflows/lint.yml)
[![Internal Release](https://github.com/ILIYANGERMANOV/ivy-wallet/actions/workflows/internal_release.yml/badge.svg)](https://github.com/ILIYANGERMANOV/ivy-wallet/actions/workflows/internal_release.yml)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package com.ivy.wallet.compose
import android.content.Context
import android.util.Log
import androidx.compose.ui.test.IdlingResource
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.platform.app.InstrumentationRegistry
import androidx.work.Configuration
import androidx.work.impl.utils.SynchronousExecutor
import androidx.work.testing.WorkManagerTestInitHelper
import com.ivy.wallet.base.TestIdlingResource
import com.ivy.wallet.base.TestingContext
import com.ivy.wallet.base.timeNowUTC
import com.ivy.wallet.base.toEpochSeconds
import com.ivy.wallet.persistence.IvyRoomDatabase
import com.ivy.wallet.persistence.SharedPrefs
import com.ivy.wallet.session.IvySession
Expand Down Expand Up @@ -98,5 +101,11 @@ abstract class IvyComposeTest {
private fun context(): Context {
return InstrumentationRegistry.getInstrumentation().targetContext
}
}

fun ComposeTestRule.wait(secondsToWait: Long) {
val secondsStart = timeNowUTC().toEpochSeconds()
this.waitUntil(timeoutMillis = (secondsToWait + 5) * 1000) {
secondsStart - timeNowUTC().toEpochSeconds() < -secondsToWait
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package com.ivy.wallet.compose.helpers

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ivy.wallet.compose.printTree

class AccountModal<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
) {
val ivyColorPicker = IvyColorPicker(composeTestRule)
val chooseIconFlow = ChooseIconFlow(composeTestRule)

fun enterTitle(
title: String
) {
composeTestRule.printTree()

composeTestRule.onNodeWithTag("base_input")
.performTextInput(title)
}

fun clickBalance() {
composeTestRule
.onNode(hasTestTag("amount_balance"))
Expand All @@ -21,4 +32,10 @@ class AccountModal<A : ComponentActivity>(
.onNode(hasText("Save"))
.performClick()
}

fun clickAdd() {
composeTestRule
.onNode(hasText("Add"))
.performClick()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ivy.wallet.compose.helpers

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.test.ext.junit.rules.ActivityScenarioRule

class ChooseIconFlow<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
) {

fun chooseIcon(icon: String) {
composeTestRule.onNodeWithTag("modal_item_icon")
.performClick()

composeTestRule.onNodeWithTag(icon)
.performScrollTo()
.performClick()

composeTestRule.onNodeWithText("Save")
.performClick()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.ivy.wallet.compose.helpers

import androidx.activity.ComponentActivity
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ivy.wallet.compose.printTree

class IvyColorPicker<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
) {

fun chooseColor(color: Color) {
composeTestRule.printTree()

composeTestRule.onNode(hasTestTag("color_item_${color.value}"))
.performScrollTo()
.performClick()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.ivy.wallet.compose.scenario

import com.ivy.wallet.compose.IvyComposeTest
import com.ivy.wallet.compose.helpers.*
import com.ivy.wallet.ui.theme.Blue
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Test

@HiltAndroidTest
class AccountsTest : IvyComposeTest() {

private val onboarding = OnboardingFlow(composeTestRule)
private val amountInput = AmountInput(composeTestRule)
private val accountModal = AccountModal(composeTestRule)
private val mainBottomBar = MainBottomBar(composeTestRule)
private val transactionFlow = TransactionFlow(composeTestRule)
private val homeTab = HomeTab(composeTestRule)
private val accountsTab = AccountsTab(composeTestRule)
private val editTransactionScreen = EditTransactionScreen(composeTestRule)


@Test
fun contextLoads() {
}

@Test
fun CreateAccount() {
onboarding.quickOnboarding()

mainBottomBar.clickAccounts()
mainBottomBar.clickAddFAB()

accountModal.apply {
enterTitle("Revolut")
ivyColorPicker.chooseColor(Blue)
chooseIconFlow.chooseIcon("revolut")
clickAdd()
}

accountsTab.assertAccountBalance(
account = "Revolut",
balance = "0",
balanceDecimal = ".00",
currency = "USD"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -159,7 +160,8 @@ private fun ColorItem(
}
.clickable(onClick = {
onSelected(ivyColor)
}),
})
.testTag("color_item_${ivyColor.color.value}"),
contentAlignment = Alignment.Center
) {
if (ivyColor.premium && !ivyContext.isPremium) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.*
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -61,7 +62,8 @@ fun IvyNameTextField(

val view = LocalView.current
BasicTextField(
modifier = Modifier,
modifier = Modifier
.testTag("base_input"),
value = value,
onValueChange = onValueChanged,
textStyle = Typo.body1.style(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.ivy.wallet.base.hideKeyboard
Expand Down Expand Up @@ -179,7 +180,8 @@ private fun Icon(
.clickable {
onClick()
}
.padding(all = 8.dp),
.padding(all = 8.dp)
.testTag(icon),
iconName = icon,
tint = if (selected) color.dynamicContrast() else IvyTheme.colors.mediumInverse
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
Expand Down Expand Up @@ -178,7 +179,8 @@ fun IconNameRow(
.background(color, CircleShape)
.clickable {
showChooseIconModal()
},
}
.testTag("modal_item_icon"),
iconName = icon,
tint = color.dynamicContrast(),
defaultIcon = defaultIcon
Expand Down

0 comments on commit 6cbe418

Please sign in to comment.