Skip to content

Commit

Permalink
[MBL-1197] Show unavailable rewards last (#1947)
Browse files Browse the repository at this point in the history
* Update rewards tests

* Sort rewards by unavailable last
  • Loading branch information
ifosli committed Feb 15, 2024
1 parent b628e03 commit 8aa9945
Show file tree
Hide file tree
Showing 64 changed files with 104 additions and 114 deletions.
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]) }

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 .~ []
)

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.
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

0 comments on commit 8aa9945

Please sign in to comment.