Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NT-1296, NT-1297] Manage Pledge view info bugfixes #1241

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Library/ViewModels/ManagePledgeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ public final class ManagePledgeViewModel:

self.configurePaymentMethodView = backing.map(managePledgePaymentMethodViewData)

self.configurePledgeSummaryView = Signal.combineLatest(project, graphBackingEnvelope)
.filterMap { project, env in managePledgeSummaryViewData(with: project, envelope: env) }
self.configurePledgeSummaryView = Signal.combineLatest(projectAndReward, graphBackingEnvelope)
.map(unpack)
.filterMap(managePledgeSummaryViewData)

let projectOrBackingFailedToLoad = Signal.merge(
fetchProjectEvent.map { $0.error as Error? },
Expand Down Expand Up @@ -468,12 +469,9 @@ private func managePledgePaymentMethodViewData(

private func managePledgeSummaryViewData(
with project: Project,
backedReward: Reward,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're now passing in the backed reward instead of trying to retrieve it from the Project's personalization property as the latter is unavailable in the creator context.

envelope: ManagePledgeViewBackingEnvelope
) -> ManagePledgeSummaryViewData? {
guard let backing = project.personalization.backing else { return nil }

let backedReward = reward(from: backing, inProject: project)

return .init(
backerId: envelope.backing.backer.uid,
backerName: envelope.backing.backer.name,
Expand Down Expand Up @@ -511,8 +509,13 @@ private func rewardsData(
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-DD"

var existingAddOnIds = Set<String>()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintaining a Set of add-on IDs here to avoid duplicates in the list.


return addOns.compactMap { addOn in
Reward.addOnReward(
guard existingAddOnIds.contains(addOn.id) == false else { return nil }
existingAddOnIds.insert(addOn.id)

return Reward.addOnReward(
from: addOn,
project: project,
selectedAddOnQuantities: selectedAddOnQuantities,
Expand Down
17 changes: 11 additions & 6 deletions Library/ViewModels/ManagePledgeViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,11 @@ internal final class ManagePledgeViewModelTests: TestCase {
)

let envelope = ManagePledgeViewBackingEnvelope.template
|> \.backing .~ (.template |> \.addOns .~ nil)
|> \.backing .~ (
.template
|> \.addOns .~ nil
|> \.reward .~ nil // no reward
)

// Pledge amount 25
let initialPledgeViewSummaryData = ManagePledgeSummaryViewData(
Expand All @@ -688,7 +692,7 @@ internal final class ManagePledgeViewModelTests: TestCase {
projectCountry: project.country,
projectDeadline: 1_476_657_315.0,
projectState: ProjectState.live,
rewardMinimum: 159.0,
rewardMinimum: 0,
shippingAmount: envelope.backing.shippingAmount?.amount
)

Expand All @@ -709,7 +713,7 @@ internal final class ManagePledgeViewModelTests: TestCase {
projectCountry: project.country,
projectDeadline: 1_476_657_315.0,
projectState: ProjectState.live,
rewardMinimum: 159.0,
rewardMinimum: 0,
shippingAmount: envelope.backing.shippingAmount?.amount
)

Expand All @@ -734,7 +738,7 @@ internal final class ManagePledgeViewModelTests: TestCase {
let expectedRewardReceivedData = ManageViewPledgeRewardReceivedViewData(
project: project,
backerCompleted: false,
estimatedDeliveryOn: 1_506_897_315.0,
estimatedDeliveryOn: 0,
backingState: .pledged
)

Expand All @@ -756,7 +760,7 @@ internal final class ManagePledgeViewModelTests: TestCase {
self.configurePledgeSummaryView.assertValues([initialPledgeViewSummaryData])

self.loadProjectAndRewardsIntoDataSourceProject.assertValues([project])
self.loadProjectAndRewardsIntoDataSourceReward.assertValues([[.template]])
self.loadProjectAndRewardsIntoDataSourceReward.assertValues([[.noReward]])
self.configureRewardReceivedWithData.assertValues([expectedRewardReceivedData])
self.title.assertValues(["Manage your pledge"])
}
Expand All @@ -778,12 +782,13 @@ internal final class ManagePledgeViewModelTests: TestCase {
pledgePaymentMethodViewData
])
self.configurePledgeSummaryView.assertValues([
initialPledgeViewSummaryData,
initialPledgeViewSummaryData,
updatedPledgeViewSummaryData
])

self.loadProjectAndRewardsIntoDataSourceProject.assertValues([project, project, project])
self.loadProjectAndRewardsIntoDataSourceReward.assertValues([[.template], [.template], [.template]])
self.loadProjectAndRewardsIntoDataSourceReward.assertValues([[.noReward], [.noReward], [.noReward]])
self.configureRewardReceivedWithData.assertValues([
expectedRewardReceivedData,
expectedRewardReceivedData,
Expand Down
2 changes: 1 addition & 1 deletion Library/ViewModels/RewardCardViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private func localizedDescription(project: Project, reward: Reward) -> String {
}

private func rewardTitle(project: Project, reward: Reward) -> NSAttributedString {
guard project.personalization.isBacking == true else {
guard project.personalization.isBacking == true || currentUserIsCreator(of: project) else {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This guard was preventing the reward title from being formatted correctly in the creator context.

return NSAttributedString(
string: reward.isNoReward ? Strings.Pledge_without_a_reward() : reward.title.coalesceWith("")
)
Expand Down