Skip to content

Commit

Permalink
[MBL-1690] Crash When Selecting 'Edit Reward' Option In Manage Pledge…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
scottkicks authored Sep 5, 2024
1 parent 15ffdd8 commit 427b313
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
36 changes: 36 additions & 0 deletions Library/ViewModels/ManagePledgeViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 427b313

Please sign in to comment.