Skip to content

Commit

Permalink
[MBL-1631] Remove Shipping Dropdown From Add-Ons (#2097)
Browse files Browse the repository at this point in the history
* WIP: populate shipping countries using the project's rewards

* No longer using individually passed in Rewards

* remove shipping dropdown from Add-Ons View Controller

* select reward with selected ShippingRule, or nil if no shippable rewards

* update RewardsCollectionViewModel Tests

* update RewardAddOnSelectionViewModel Tests

* update PledgeViewModel Tests

* update ConfirmDetailsViewModel Tests

* use passed in selectedShippingRule, if not nil, so that the manage pledge flow knows about the correct shipping rule

* this is temporary since shipping will be removed from checkout during this milestone

* update ManagePledgeViewModel Tests

* update snapshot tests
  • Loading branch information
scottkicks authored Jul 22, 2024
1 parent e495aca commit b9398aa
Show file tree
Hide file tree
Showing 124 changed files with 339 additions and 344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -87,6 +88,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -121,6 +123,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -171,6 +174,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -220,6 +224,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -264,6 +269,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -308,6 +314,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -353,6 +360,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -401,6 +409,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -450,6 +459,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -493,6 +503,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -525,6 +536,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: .template,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -561,6 +573,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: .template,
rewards: [reward, .noReward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1, Reward.noReward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -599,6 +612,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: .template,
rewards: [reward, .noReward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1, Reward.noReward.id: 1],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -639,6 +653,7 @@ final class PledgeViewControllerTests: TestCase {
let data = PledgeViewData(
project: project,
rewards: [reward, addOnReward1, addOnReward2],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [reward.id: 1, addOnReward1.id: 2, addOnReward2.id: 1],
selectedLocationId: ShippingRule.template.id,
refTag: .projectPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ final class RewardAddOnSelectionViewController: UIViewController {
private lazy var headerLabel: UILabel = UILabel(frame: .zero)
private lazy var headerView: UIView = UIView(frame: .zero)
private lazy var headerRootStackView: UIStackView = UIStackView(frame: .zero)
private lazy var pledgeShippingLocationViewController: PledgeShippingLocationViewController = {
PledgeShippingLocationViewController.instantiate()
|> \.delegate .~ self
}()

private lazy var continueCTAView: RewardAddOnSelectionContinueCTAView = {
RewardAddOnSelectionContinueCTAView(frame: .zero)
Expand Down Expand Up @@ -96,11 +92,8 @@ final class RewardAddOnSelectionViewController: UIViewController {
|> ksr_addSubviewToParent()
|> ksr_constrainViewToEdgesInParent(priority: UILayoutPriority(rawValue: 999))

_ = ([self.headerLabel, self.pledgeShippingLocationViewController.view], self.headerRootStackView)
_ = ([self.headerLabel], self.headerRootStackView)
|> ksr_addArrangedSubviewsToStackView()

self.addChild(self.pledgeShippingLocationViewController)
self.pledgeShippingLocationViewController.didMove(toParent: self)
}

private func setupConstraints() {
Expand Down Expand Up @@ -146,21 +139,12 @@ final class RewardAddOnSelectionViewController: UIViewController {
override func bindViewModel() {
super.bindViewModel()

self.pledgeShippingLocationViewController.view.rac.hidden
= self.viewModel.outputs.shippingLocationViewIsHidden

self.viewModel.outputs.configureContinueCTAViewWithData
.observeForUI()
.observeValues { [weak self] data in
self?.continueCTAView.configure(with: data)
}

self.viewModel.outputs.configurePledgeShippingLocationViewControllerWithData
.observeForUI()
.observeValues { [weak self] data in
self?.pledgeShippingLocationViewController.configureWith(value: data)
}

self.viewModel.outputs.loadAddOnRewardsIntoDataSourceAndReloadTableView
.observeForUI()
.observeValues { [weak self] items in
Expand Down Expand Up @@ -227,25 +211,6 @@ final class RewardAddOnSelectionViewController: UIViewController {
}
}

// MARK: - PledgeShippingLocationViewControllerDelegate

extension RewardAddOnSelectionViewController: PledgeShippingLocationViewControllerDelegate {
func pledgeShippingLocationViewController(
_: PledgeShippingLocationViewController,
didSelect shippingRule: ShippingRule
) {
self.viewModel.inputs.shippingRuleSelected(shippingRule)
}

func pledgeShippingLocationViewControllerLayoutDidUpdate(_: PledgeShippingLocationViewController) {
self.tableView.ksr_sizeHeaderFooterViewsToFit()
}

func pledgeShippingLocationViewControllerFailedToLoad(_: PledgeShippingLocationViewController) {
self.viewModel.inputs.shippingLocationViewDidFailToLoad()
}
}

// MARK: - RewardAddOnCardViewDelegate

extension RewardAddOnSelectionViewController: RewardAddOnCardViewDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {

let mockService = MockService(fetchRewardAddOnsSelectionViewRewardsResult: .success(project))

combos(Language.allLanguages, Device.allCases).forEach { language, device in
orthogonalCombos(Language.allLanguages, Device.allCases).forEach { language, device in
withEnvironment(apiService: mockService) {
let controller = RewardAddOnSelectionViewController.instantiate()

let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [:],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -97,12 +98,13 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
fetchRewardAddOnsSelectionViewRewardsResult: .success(project)
)

combos(Language.allLanguages, Device.allCases).forEach { language, device in
orthogonalCombos(Language.allLanguages, Device.allCases).forEach { language, device in
withEnvironment(apiService: mockService) {
let controller = RewardAddOnSelectionViewController.instantiate()
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [:],
selectedLocationId: nil,
refTag: nil,
Expand All @@ -114,13 +116,6 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {

self.scheduler.advance()

controller.pledgeShippingLocationViewController(
PledgeShippingLocationViewController.instantiate(),
didSelect: .template
)

self.scheduler.advance(by: .seconds(1))

assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
Expand Down Expand Up @@ -201,12 +196,13 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
fetchRewardAddOnsSelectionViewRewardsResult: .success(project)
)

combos(Language.allLanguages, Device.allCases).forEach { language, device in
orthogonalCombos(Language.allLanguages, Device.allCases).forEach { language, device in
withEnvironment(apiService: mockService) {
let controller = RewardAddOnSelectionViewController.instantiate()
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [:],
selectedLocationId: nil,
refTag: nil,
Expand All @@ -218,13 +214,6 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {

self.scheduler.advance()

controller.pledgeShippingLocationViewController(
PledgeShippingLocationViewController.instantiate(),
didSelect: shippingRule
)

self.scheduler.advance(by: .seconds(1))

assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
Expand All @@ -242,13 +231,14 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {

let mockService = MockService(fetchRewardAddOnsSelectionViewRewardsResult: .failure(.couldNotParseJSON))

combos(Language.allLanguages, Device.allCases).forEach { language, device in
orthogonalCombos(Language.allLanguages, Device.allCases).forEach { language, device in
withEnvironment(apiService: mockService) {
let controller = RewardAddOnSelectionViewController.instantiate()

let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [:],
selectedLocationId: nil,
refTag: nil,
Expand Down Expand Up @@ -288,13 +278,14 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {

let mockService = MockService(fetchRewardAddOnsSelectionViewRewardsResult: .success(project))

combos(Language.allLanguages, [Device.phone5_8inch, Device.pad]).forEach { language, device in
orthogonalCombos(Language.allLanguages, [Device.phone5_8inch, Device.pad]).forEach { language, device in
withEnvironment(apiService: mockService, language: language) {
let controller = RewardAddOnSelectionViewController.instantiate()

let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: ShippingRule.template,
selectedQuantities: [:],
selectedLocationId: nil,
refTag: nil,
Expand Down
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
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.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ final class RewardsCollectionViewController: UICollectionViewController {
self.setupConstraints()

self.viewModel.inputs.viewDidLoad()
self.viewModel.inputs.shippingRuleSelected(nil)
}

override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -389,11 +390,15 @@ extension RewardsCollectionViewController: RewardCellDelegate {
extension RewardsCollectionViewController: PledgeShippingLocationViewControllerDelegate {
func pledgeShippingLocationViewController(
_: PledgeShippingLocationViewController,
didSelect _: ShippingRule
) {}
didSelect shippingRule: ShippingRule
) {
self.viewModel.inputs.shippingRuleSelected(shippingRule)
}

func pledgeShippingLocationViewControllerLayoutDidUpdate(_: PledgeShippingLocationViewController) {}
func pledgeShippingLocationViewControllerFailedToLoad(_: PledgeShippingLocationViewController) {}
func pledgeShippingLocationViewControllerFailedToLoad(_: PledgeShippingLocationViewController) {
self.viewModel.inputs.shippingLocationViewDidFailToLoad()
}
}

// MARK: Styles
Expand Down
Loading

0 comments on commit b9398aa

Please sign in to comment.