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

[MBL-1197] Show unavailable rewards last #1947

Merged
merged 5 commits into from
Feb 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,47 @@ final class RewardsCollectionViewControllerTests: TestCase {
let project = Project.cosmicSurgery
|> Project.lens.state .~ .live

combos(Language.allLanguages, [Device.phone4_7inch, Device.phone5_8inch, Device.pad]).forEach {
language, device in
withEnvironment(language: language, locale: .init(identifier: language.rawValue)) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: vc)

assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
named: "lang_\(language)_device_\(device)"
)
}
let language = Language.en, device = Device.phone4_7inch
withEnvironment(language: language, locale: .init(identifier: language.rawValue)) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: vc)

assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
named: "lang_\(language)_device_\(device)"
)
}
}

func testRewards_NonBacker_LiveProject_Landscape() {
let project = Project.cosmicSurgery
|> Project.lens.state .~ .live
|> Project.lens.rewardData.rewards %~ { Array($0[1...3]) }
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 just reduces the number of items so that the unavailable one shows as well, even when it's last


let language = Language.de, device = Device.pad
withEnvironment(language: language, locale: .init(identifier: language.rawValue)) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .landscape, child: vc)

combos(Language.allLanguages, [Device.phone4_7inch, Device.phone5_8inch, Device.pad]).forEach {
language, device in
withEnvironment(language: language, locale: .init(identifier: language.rawValue)) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .landscape, child: vc)

assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
named: "lang_\(language)_device_\(device)"
)
}
assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
named: "lang_\(language)_device_\(device)"
)
}
}

func testRewards_Backer_LiveProject_Landscape() {
let reward = Project.cosmicSurgery.rewards[1]
let reward = Project.cosmicSurgery.rewards[3]
let project = Project.cosmicSurgery
|> Project.lens.state .~ .live
|> Project.lens.personalization.isBacking .~ true
Expand All @@ -77,24 +74,23 @@ final class RewardsCollectionViewControllerTests: TestCase {
|> Backing.lens.rewardId .~ reward.id
|> Backing.lens.shippingAmount .~ 10
|> Backing.lens.amount .~ 700.0
|> Backing.lens.addOns .~ []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opting out of add ons here ensures that this reward will be shown as unavailable when it's not selected. The default addOn has the same reward id as one of the rewards, which messes with our count for the reward.

)

let language = Language.es, device = Device.phone5_8inch
withEnvironment(language: language, locale: .init(identifier: language.rawValue)) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .landscape, child: vc)

combos(Language.allLanguages, [Device.phone4_7inch, Device.phone5_8inch, Device.pad]).forEach {
language, device in
withEnvironment(language: language, locale: .init(identifier: language.rawValue)) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .landscape, child: vc)

assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
named: "lang_\(language)_device_\(device)"
)
}
assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
named: "lang_\(language)_device_\(device)"
)
}
}

Expand All @@ -107,21 +103,19 @@ final class RewardsCollectionViewControllerTests: TestCase {
|> Project.lens.state .~ .live
|> Project.lens.rewardData.rewards .~ [reward]

combos(Language.allLanguages, [Device.pad]).forEach {
language, device in
withEnvironment(
language: language,
locale: .init(identifier: language.rawValue)
) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .landscape, child: vc)

assertSnapshot(matching: parent.view, as: .image, named: "lang_\(language)_device_\(device)")
}
let language = Language.fr, device = Device.pad
withEnvironment(
language: language,
locale: .init(identifier: language.rawValue)
) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .landscape, child: vc)

assertSnapshot(matching: parent.view, as: .image, named: "lang_\(language)_device_\(device)")
}
}

Expand All @@ -134,21 +128,19 @@ final class RewardsCollectionViewControllerTests: TestCase {
|> Project.lens.state .~ .live
|> Project.lens.rewardData.rewards .~ [reward]

combos(Language.allLanguages, [Device.phone5_8inch]).forEach {
language, device in
withEnvironment(
language: language,
locale: .init(identifier: language.rawValue)
) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: vc)

assertSnapshot(matching: parent.view, as: .image, named: "lang_\(language)_device_\(device)")
}
let language = Language.ja, device = Device.phone5_8inch
withEnvironment(
language: language,
locale: .init(identifier: language.rawValue)
) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: vc)

assertSnapshot(matching: parent.view, as: .image, named: "lang_\(language)_device_\(device)")
}
}

Expand All @@ -161,21 +153,19 @@ final class RewardsCollectionViewControllerTests: TestCase {
|> Project.lens.state .~ .live
|> Project.lens.rewardData.rewards .~ [.noReward, reward]

combos(Language.allLanguages, [Device.phone5_8inch]).forEach {
language, device in
withEnvironment(
language: language,
locale: .init(identifier: language.rawValue)
) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: vc)

assertSnapshot(matching: parent.view, as: .image, named: "lang_\(language)_device_\(device)")
}
let language = Language.en, device = Device.phone5_8inch
withEnvironment(
language: language,
locale: .init(identifier: language.rawValue)
) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: vc)

assertSnapshot(matching: parent.view, as: .image, named: "lang_\(language)_device_\(device)")
}
}

Expand All @@ -193,21 +183,19 @@ final class RewardsCollectionViewControllerTests: TestCase {
)
|> Project.lens.rewardData.rewards .~ [reward]

combos(Language.allLanguages, [Device.phone5_8inch]).forEach {
language, device in
withEnvironment(
language: language,
locale: .init(identifier: language.rawValue)
) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: vc)

assertSnapshot(matching: parent.view, as: .image, named: "lang_\(language)_device_\(device)")
}
let language = Language.de, device = Device.phone5_8inch
withEnvironment(
language: language,
locale: .init(identifier: language.rawValue)
) {
let vc = RewardsCollectionViewController.instantiate(
with: project,
refTag: nil,
context: .createPledge
)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: vc)

assertSnapshot(matching: parent.view, as: .image, named: "lang_\(language)_device_\(device)")
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
8 changes: 5 additions & 3 deletions Library/ViewModels/RewardsCollectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class RewardsCollectionViewModel: RewardsCollectionViewModelType,
.map(first)

let rewards = project
.map(allowableProjectRewards)
.map(allowableSortedProjectRewards)

self.title = configData
.map { project, _, context in (context, project) }
Expand Down Expand Up @@ -384,6 +384,8 @@ private func backingAndShippingTotal(for project: Project, and reward: Reward) -
return (backing, shippingTotal)
}

private func allowableProjectRewards(from project: Project) -> [Reward] {
project.rewards
private func allowableSortedProjectRewards(from project: Project) -> [Reward] {
let availableRewards = project.rewards.filter { rewardIsAvailable(project: project, reward: $0) }
let unAvailableRewards = project.rewards.filter { !rewardIsAvailable(project: project, reward: $0) }
return availableRewards + unAvailableRewards
}
4 changes: 2 additions & 2 deletions Library/ViewModels/RewardsCollectionViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class RewardsCollectionViewModelTests: TestCase {

let displayableRewards = self.reloadDataWithValues.lastValue?.compactMap { $0.reward }

XCTAssertEqual(displayableRewards, project.rewards)
XCTAssertEqual(displayableRewards?.sorted(), project.rewards.sorted())
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ final class RewardsCollectionViewModelTests: TestCase {

let displayableRewards = self.reloadDataWithValues.lastValue?.compactMap { $0.reward }

XCTAssertEqual(displayableRewards, allNonLocalPickupRewards)
XCTAssertEqual(displayableRewards?.sorted(), allNonLocalPickupRewards.sorted())
}
}

Expand Down