From 427b3138da3a44b506bf8bcf1df073075f5d7a4b Mon Sep 17 00:00:00 2001 From: Scott Clampet <110618242+scottkicks@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:00:30 -0700 Subject: [PATCH] [MBL-1690] Crash When Selecting 'Edit Reward' Option In Manage Pledge Flow (#2145) * add a test for when the 'update pledge' option is not an option when the feature flag is enabled * scroll to index path should be based on rewards filtered by location --- .../ManagePledgeViewModelTests.swift | 36 +++++++++++++++++++ ...thShippingRewardsCollectionViewModel.swift | 9 +++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Library/ViewModels/ManagePledgeViewModelTests.swift b/Library/ViewModels/ManagePledgeViewModelTests.swift index b528575366..a3c620fe36 100644 --- a/Library/ViewModels/ManagePledgeViewModelTests.swift +++ b/Library/ViewModels/ManagePledgeViewModelTests.swift @@ -304,6 +304,42 @@ internal final class ManagePledgeViewModelTests: TestCase { } } + func testMenuButtonTapped_WhenProject_IsLive_NoShippingAtCheckout_doesNotInclude_updatePledge() { + let project = Project.template + |> Project.lens.state .~ .live + + let mockService = MockService( + fetchManagePledgeViewBackingResult: .success(.template), + fetchProjectResult: .success(project), + fetchProjectRewardsResult: .success([.template]) + ) + + let mockConfigClient = MockRemoteConfigClient() + mockConfigClient.features = [ + RemoteConfigFeature.noShippingAtCheckout.rawValue: true + ] + + withEnvironment(apiService: mockService, remoteConfigClient: mockConfigClient) { + self.vm.inputs.configureWith((Param.slug("project-slug"), Param.id(1))) + self.vm.inputs.viewDidLoad() + + self.scheduler.advance() + + self.showActionSheetMenuWithOptions.assertDidNotEmitValue() + + self.vm.inputs.menuButtonTapped() + + self.showActionSheetMenuWithOptions.assertValues([ + [ + ManagePledgeAlertAction.changePaymentMethod, + ManagePledgeAlertAction.chooseAnotherReward, + ManagePledgeAlertAction.contactCreator, + ManagePledgeAlertAction.cancelPledge + ] + ]) + } + } + func testMenuButtonTapped_WhenProject_IsSuccessful_CreatorContext() { let user = User.template let project = Project.template diff --git a/Library/ViewModels/WithShippingRewardsCollectionViewModel.swift b/Library/ViewModels/WithShippingRewardsCollectionViewModel.swift index 644d061bf1..5b4e903ed2 100644 --- a/Library/ViewModels/WithShippingRewardsCollectionViewModel.swift +++ b/Library/ViewModels/WithShippingRewardsCollectionViewModel.swift @@ -66,9 +66,14 @@ public final class WithShippingRewardsCollectionViewModel: WithShippingRewardsCo .map(first) .map(titleForContext) - self.scrollToBackedRewardIndexPath = Signal.combineLatest(project, rewards) + self.scrollToBackedRewardIndexPath = Signal.combineLatest(project, rewards, filteredByLocationRewards) .takeWhen(self.viewDidLayoutSubviewsProperty.signal.ignoreValues()) - .map(backedReward(_:rewards:)) + .map { project, rewards, filteredRewardsByLocation in + backedReward( + project, + rewards: filteredRewardsByLocation.isEmpty ? rewards : filteredRewardsByLocation + ) + } .skipNil() .take(first: 1)