From 390ae4344df08f559ce1a02b3276b4c9fdf99edb Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 2 Mar 2022 18:07:13 +0000 Subject: [PATCH] allowing test withPrevious to be supplied a list --- .../features/onboarding/OnboardingViewModelTest.kt | 14 +++++--------- .../src/test/java/im/vector/app/test/Extensions.kt | 4 ++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt b/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt index 3c8279bafa..b6e92655c0 100644 --- a/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt @@ -196,7 +196,7 @@ class OnboardingViewModelTest { viewModel.handle(OnboardingAction.UpdateDisplayName(A_DISPLAY_NAME)) test - .assertStates(expectedSuccessfulDisplayNameUpdateStates(personalisedInitialState)) + .assertStatesWithPrevious(personalisedInitialState, expectedSuccessfulDisplayNameUpdateStates()) .assertEvents(OnboardingViewEvents.OnChooseProfilePicture) .finish() fakeSession.fakeProfileService.verifyUpdatedName(fakeSession.myUserId, A_DISPLAY_NAME) @@ -211,7 +211,7 @@ class OnboardingViewModelTest { viewModel.handle(OnboardingAction.UpdateDisplayName(A_DISPLAY_NAME)) test - .assertStates(expectedSuccessfulDisplayNameUpdateStates(personalisedInitialState)) + .assertStatesWithPrevious(personalisedInitialState, expectedSuccessfulDisplayNameUpdateStates()) .assertEvents(OnboardingViewEvents.OnPersonalizationComplete) .finish() fakeSession.fakeProfileService.verifyUpdatedName(fakeSession.myUserId, A_DISPLAY_NAME) @@ -339,14 +339,10 @@ class OnboardingViewModelTest { state.copy(asyncProfilePicture = Fail(cause)) ) - private fun expectedSuccessfulDisplayNameUpdateStates(personalisedInitialState: OnboardingViewState): List { + private fun expectedSuccessfulDisplayNameUpdateStates(): List OnboardingViewState> { return listOf( - personalisedInitialState, - personalisedInitialState.copy(asyncDisplayName = Loading()), - personalisedInitialState.copy( - asyncDisplayName = Success(Unit), - personalizationState = personalisedInitialState.personalizationState.copy(displayName = A_DISPLAY_NAME) - ) + { copy(asyncDisplayName = Loading()) }, + { copy(asyncDisplayName = Success(Unit), personalizationState = personalizationState.copy(displayName = A_DISPLAY_NAME)) } ) } diff --git a/vector/src/test/java/im/vector/app/test/Extensions.kt b/vector/src/test/java/im/vector/app/test/Extensions.kt index 136ca58d68..5fe07b967a 100644 --- a/vector/src/test/java/im/vector/app/test/Extensions.kt +++ b/vector/src/test/java/im/vector/app/test/Extensions.kt @@ -56,6 +56,10 @@ class ViewModelTest( } fun assertStatesWithPrevious(initial: S, vararg expected: S.() -> S): ViewModelTest { + return assertStatesWithPrevious(initial, expected.toList()) + } + + fun assertStatesWithPrevious(initial: S, expected: List S>): ViewModelTest { val reducedExpectedStates = expected.fold(mutableListOf(initial)) { acc, curr -> val next = curr.invoke(acc.last()) acc.add(next)