Skip to content

Commit

Permalink
[NT-1495] Update logic for quantity attributed text in RewardCardView (
Browse files Browse the repository at this point in the history
…#1308)

* Update logic for quantity attributed text in RewardCardView

* Inadvertently committed an empty line deletion. Reverting here.

* Run formatter script

* Add unit test for single add on in title label
  • Loading branch information
singhhari authored Sep 28, 2020
1 parent 3bbb921 commit aacc37f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Library/ViewModels/RewardCardViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private func rewardTitle(project: Project, reward: Reward) -> NSAttributedString
// Not the base reward, for that we just return the title without quantity.
reward.id != backing.reward?.id,
let selectedQuantity = selectedRewardQuantities(in: backing)[reward.id],
selectedQuantity > 0 else {
selectedQuantity > 1 else {
return titleAttributed
}

Expand All @@ -214,7 +214,6 @@ private func rewardTitle(project: Project, reward: Reward) -> NSAttributedString
attributes: attributes,
bolding: [title]
)

return qtyAttributed + titleAttributed
}

Expand Down
18 changes: 18 additions & 0 deletions Library/ViewModels/RewardCardViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ final class RewardCardViewModelTests: TestCase {
XCTAssertEqual(self.rewardTitleLabelAttributedText.values.map { $0.string }, ["2 x The thing"])
}

func testTitleLabel_Backed_AddOn_Single() {
let reward = .template
|> Reward.lens.id .~ 99
|> Reward.lens.title .~ "The thing"
|> Reward.lens.remaining .~ nil

let backing = Backing.template
|> Backing.lens.addOns .~ [reward]

let project = Project.template
|> Project.lens.personalization.isBacking .~ true
|> Project.lens.personalization.backing .~ backing

self.vm.inputs.configure(with: (project, reward, .pledge))

XCTAssertEqual(self.rewardTitleLabelAttributedText.values.map { $0.string }, ["The thing"])
}

// MARK: - Reward Minimum

func testMinimumLabel_US_Project_US_UserLocation() {
Expand Down

0 comments on commit aacc37f

Please # to comment.