Skip to content

Commit

Permalink
WIP: Reorder accounts & categories tests (currently failing)
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliyan Germanov committed Nov 24, 2021
1 parent c16ef88 commit e33789e
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.ext.junit.rules.ActivityScenarioRule

class CategoryScreen<A : ComponentActivity>(
class CategoriesScreen<A : ComponentActivity>(
private val composeTestRule: AndroidComposeTestRule<ActivityScenarioRule<A>, A>
) {
private val categoryModal = CategoryModal(composeTestRule)
Expand Down Expand Up @@ -50,4 +50,10 @@ class CategoryScreen<A : ComponentActivity>(
.performScrollTo()
.performClick()
}


fun clickReorder() {
composeTestRule.onNodeWithTag("reorder_button")
.performClick()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ class HomeMoreMenu<A : ComponentActivity>(
composeTestRule.onNodeWithText("Budgets")
.performClick()
}

fun clickCategories() {
composeTestRule.onNodeWithText("Categories")
.performClick()
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.ivy.wallet.compose.helpers

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.hasContentDescription
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.performGesture
import androidx.compose.ui.test.swipeUp
import androidx.test.ext.junit.rules.ActivityScenarioRule

class ReorderModal<A : ComponentActivity>(
Expand All @@ -21,4 +18,9 @@ class ReorderModal<A : ComponentActivity>(
swipeUp()
}
}

fun clickDone() {
composeTestRule.onNodeWithTag("reorder_done")
.performClick()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.ivy.wallet.compose.scenario
import android.icu.util.Currency
import com.ivy.wallet.compose.IvyComposeTest
import com.ivy.wallet.compose.helpers.*
import com.ivy.wallet.compose.waitSeconds
import com.ivy.wallet.ui.theme.Blue
import com.ivy.wallet.ui.theme.Purple1
import com.ivy.wallet.ui.theme.Purple2
Expand Down Expand Up @@ -154,18 +153,16 @@ class AccountsTest : IvyComposeTest() {
)
}

@Ignore("RecyclerView reorder not working with ComposeTestRule")
/**
* semiTest because no actual reordering is being gone
*/
@Ignore
@Test
fun ReorderAccounts() {
//TODO: RecyclerView reorder not working
fun ReorderAccounts_semiTest() {
onboarding.quickOnboarding()
mainBottomBar.clickAccounts()

accountsTab.clickReorder()
reorderModal.moveToTop(
itemPosition = 1
)

composeTestRule.waitSeconds(3)
reorderModal.clickDone()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@ import com.ivy.wallet.ui.theme.Blue
import com.ivy.wallet.ui.theme.Blue2
import com.ivy.wallet.ui.theme.Ivy
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Ignore
import org.junit.Test

@HiltAndroidTest
class CategoriesTest : IvyComposeTest() {
private val onboardingFlow = OnboardingFlow(composeTestRule)
private val homeMoreMenu = HomeMoreMenu(composeTestRule)
private val categoryModal = CategoryModal(composeTestRule)
private val categoryScreen = CategoryScreen(composeTestRule)
private val categoryScreen = CategoriesScreen(composeTestRule)
private val itemStatisticScreen = ItemStatisticScreen(composeTestRule)
private val deleteConfirmationModal = DeleteConfirmationModal(composeTestRule)
private val reorderModal = ReorderModal(composeTestRule)

@Test
fun contextLoads() {
}

@Test
fun CreateCategory() {
onboardingFlow.onboardWith1AccountAnd1Category()

homeMoreMenu.clickOpenCloseArrow()
homeMoreMenu.clickCategories()

composeTestRule.onNodeWithText("Categories")
.performClick()

composeTestRule.onNodeWithText("Add category")
.performClick()
Expand All @@ -46,8 +50,7 @@ class CategoriesTest : IvyComposeTest() {
fun AddSeveralCategories() {
onboardingFlow.onboardWith1AccountAnd1Category()
homeMoreMenu.clickOpenCloseArrow()
composeTestRule.onNodeWithText("Categories")
.performClick()
homeMoreMenu.clickCategories()

categoryScreen.addCategory(
categoryName = "Entertainment"
Expand All @@ -66,8 +69,7 @@ class CategoriesTest : IvyComposeTest() {
fun EditCategory() {
onboardingFlow.onboardWith1AccountAnd1Category()
homeMoreMenu.clickOpenCloseArrow()
composeTestRule.onNodeWithText("Categories")
.performClick()
homeMoreMenu.clickCategories()

categoryScreen.clickCategory(
categoryName = "Food & Drinks"
Expand Down Expand Up @@ -96,8 +98,7 @@ class CategoriesTest : IvyComposeTest() {
fun DeleteCategory() {
onboardingFlow.onboardWith1AccountAnd1Category()
homeMoreMenu.clickOpenCloseArrow()
composeTestRule.onNodeWithText("Categories")
.performClick()
homeMoreMenu.clickCategories()

categoryScreen.clickCategory(
categoryName = "Food & Drinks"
Expand All @@ -110,4 +111,18 @@ class CategoriesTest : IvyComposeTest() {
categoryName = "Food & Drinks"
)
}

/**
* semiTest because no actual reordering is being gone
*/
@Ignore
@Test
fun ReorderCategories_semiTest() {
onboardingFlow.quickOnboarding()
homeMoreMenu.clickOpenCloseArrow()
homeMoreMenu.clickCategories()

categoryScreen.clickReorder()
reorderModal.clickDone()
}
}
25 changes: 21 additions & 4 deletions app/src/main/java/com/ivy/wallet/ui/budget/BudgetViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package com.ivy.wallet.ui.budget
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ivy.wallet.base.asLiveData
import com.ivy.wallet.base.getDefaultFIATCurrency
import com.ivy.wallet.base.ioThread
import com.ivy.wallet.base.isNotNullOrBlank
import com.ivy.wallet.base.*
import com.ivy.wallet.logic.BudgetCreator
import com.ivy.wallet.logic.WalletLogic
import com.ivy.wallet.logic.currency.ExchangeRatesLogic
Expand Down Expand Up @@ -67,6 +64,8 @@ class BudgetViewModel @Inject constructor(

fun start() {
viewModelScope.launch {
TestIdlingResource.increment()

_categories.value = ioThread {
categoryDao.findAll()
}!!
Expand Down Expand Up @@ -118,6 +117,8 @@ class BudgetViewModel @Inject constructor(
)
}
}!!

TestIdlingResource.decrement()
}
}

Expand Down Expand Up @@ -160,31 +161,45 @@ class BudgetViewModel @Inject constructor(

fun createBudget(data: CreateBudgetData) {
viewModelScope.launch {
TestIdlingResource.increment()

budgetCreator.createBudget(data) {
start()
}

TestIdlingResource.decrement()
}
}

fun editBudget(budget: Budget) {
viewModelScope.launch {
TestIdlingResource.increment()

budgetCreator.editBudget(budget) {
start()
}

TestIdlingResource.decrement()
}
}

fun deleteBudget(budget: Budget) {
viewModelScope.launch {
TestIdlingResource.increment()

budgetCreator.deleteBudget(budget) {
start()
}

TestIdlingResource.decrement()
}
}


fun reorder(newOrder: List<DisplayBudget>) {
viewModelScope.launch {
TestIdlingResource.increment()

ioThread {
newOrder.forEachIndexed { index, item ->
budgetDao.save(
Expand All @@ -200,6 +215,8 @@ class BudgetViewModel @Inject constructor(
ioThread {
budgetSync.sync()
}

TestIdlingResource.decrement()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.ivy.wallet.ui.category
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ivy.wallet.base.TestIdlingResource
import com.ivy.wallet.base.asLiveData
import com.ivy.wallet.base.ioThread
import com.ivy.wallet.logic.CategoryCreator
Expand Down Expand Up @@ -35,6 +36,8 @@ class CategoriesViewModel @Inject constructor(

fun start() {
viewModelScope.launch {
TestIdlingResource.increment()

val range = TimePeriod.currentMonth(
startDayOfMonth = ivyContext.startDayOfMonth
).toRange(ivyContext.startDayOfMonth) //this must be monthly
Expand Down Expand Up @@ -62,11 +65,15 @@ class CategoriesViewModel @Inject constructor(
)
}
}!!

TestIdlingResource.decrement()
}
}

fun reorder(newOrder: List<CategoryData>) {
viewModelScope.launch {
TestIdlingResource.increment()

ioThread {
newOrder.forEachIndexed { index, categoryData ->
categoryDao.save(
Expand All @@ -82,14 +89,20 @@ class CategoriesViewModel @Inject constructor(
ioThread {
categorySync.sync()
}

TestIdlingResource.decrement()
}
}

fun createCategory(data: CreateCategoryData) {
viewModelScope.launch {
TestIdlingResource.increment()

categoryCreator.createCategory(data) {
start()
}

TestIdlingResource.decrement()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class OnboardingViewModel @Inject constructor(
_currency.value = defaultCurrency

ioThread {
TestIdlingResource.increment()

if (settingsDao.findAll().isEmpty()) {
settingsDao.save(
Settings(
Expand All @@ -132,6 +134,8 @@ class OnboardingViewModel @Inject constructor(
)
)
}

TestIdlingResource.decrement()
}
}

Expand Down Expand Up @@ -167,6 +171,8 @@ class OnboardingViewModel @Inject constructor(
}

private suspend fun loginWithGoogleOnServer(idToken: String) {
TestIdlingResource.increment()

val authResponse = restClient.authService.googleSignIn(
GoogleSignInRequest(
googleIdToken = idToken,
Expand All @@ -185,6 +191,8 @@ class OnboardingViewModel @Inject constructor(
}

_opGoogleSignIn.value = OpResult.success(Unit)

TestIdlingResource.decrement()
}

fun loginOfflineAccount() {
Expand Down Expand Up @@ -233,11 +241,15 @@ class OnboardingViewModel @Inject constructor(

private suspend fun updateBaseCurrency(baseCurrency: IvyCurrency) {
ioThread {
TestIdlingResource.increment()

settingsDao.save(
settingsDao.findFirst().copy(
currency = baseCurrency.code
)
)

TestIdlingResource.decrement()
}
_currency.value = baseCurrency
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ fun <T : Reorderable> BoxScope.ReorderView(
PrimaryAction = {
IvyCircleButton(
modifier = Modifier
.size(48.dp),
.size(48.dp)
.testTag("reorder_done"),
backgroundGradient = GradientGreen,
icon = R.drawable.ic_check,
tint = White
Expand Down

0 comments on commit e33789e

Please sign in to comment.