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-206] Reward received toggle business logic #866

Merged
merged 10 commits into from
Oct 3, 2019

Conversation

dusi
Copy link
Contributor

@dusi dusi commented Oct 1, 2019

📲 What

Adds the business logic to

  • Hide reward received toggle section if either is true (reward = NoReward, backing status != collected
  • Show the initial value properly
  • Allow toggling the value by also calling our endpoint

🤔 Why

Now that we have UI & a11y it's time to hook up the business logic

✅ Acceptance criteria

Default value

  • Navigating to manage pledge screen should HIDE reward received toggle section if the project backing status is NOT collected
  • Navigating to manage pledge screen should HIDE reward received toggle section if the
    reward is NoReward
  • Navigating to manage pledge screen should SHOW reward received toggle section if both the project backing status IS collected and the reward is NOT a NoReward

(this could be verified against the backend by going to https://www.kickstarter.com/profile/backings?ref=user_menu and comparing the Got it! column for backed projects.

Toggling value

  • Toggling the value ON updates the value on the backend so that leaving this screen and navigating back again will persist the value properly
  • Toggling the value ON updates the value on the backend so that leaving this screen and navigating back again will persist the value properly

(instead of navigating back and forth this could be verified against the backend by going to https://www.kickstarter.com/profile/backings?ref=user_menu

@@ -6,6 +6,8 @@ import UIKit
final class ManagePledgeViewController: UIViewController {
// MARK: - Properties

private let viewModel: ManagePledgeViewModelType = ManagePledgeViewModel()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved the viewModel to the top of Properties section. This is consistent with the rest of the codebase and makes it easier to glance at the same place where we would in other VC

@@ -44,15 +46,6 @@ final class ManagePledgeViewController: UIViewController {
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

private let viewModel: ManagePledgeViewModelType = ManagePledgeViewModel()
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've mostly used two step configuration

  1. Instantiate
  2. Configure

So I've gotten rid of this because it was effectively introducing pattern we've been trying to move away from and making the configureWith function obsolete.

@@ -93,6 +96,9 @@ public final class ManagePledgeViewModel:
self.goToChangePaymentMethod = self.menuOptionSelectedSignal
.filter { $0 == .changePaymentMethod }
.ignoreValues()

self.rewardReceivedViewControllerViewIsHidden = projectAndReward
.map { project, reward in reward.isNoReward || project.personalization.backing?.status != .collected }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hopefully this is the same logic @eoji was trying to explain to me ... please let me know if I'm off here

Copy link
Contributor

Choose a reason for hiding this comment

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

:chefs_kiss: lgtm!

@@ -195,4 +199,160 @@ internal final class ManagePledgeViewModelTests: TestCase {
self.goToUpdatePledgeProject.assertValues([Project.template])
self.goToUpdatePledgeReward.assertValues([Reward.template])
}

func testRewardReceivedViewControllerIsHidden_NoReward_Canceled() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests could potentially only test when the view is NOT hidden but since tests are cheap it should be not a problem for testing all the variations here.

@ksr-ci-bot
Copy link

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

Copy link
Contributor

@justinswart justinswart left a comment

Choose a reason for hiding this comment

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

Looking good, minor comments, will test 👍

self.viewModel.outputs.rewardReceived
.observeForUI()
.observeValues { [weak self] isOn in
self?.toggle.isOn = isOn
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't you add a RAC binding for this? self.toggle.rac.on?

Copy link
Contributor Author

@dusi dusi Oct 3, 2019

Choose a reason for hiding this comment

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

Ah, got tripped by it being called on not isOn ... yeah I can use it!

if AppEnvironment.current.device.userInterfaceIdiom == .pad {
_ = nav
_ = nc
Copy link
Contributor

Choose a reason for hiding this comment

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

The diff would probably be small with less renaming here 😬

Copy link
Contributor

@justinswart justinswart left a comment

Choose a reason for hiding this comment

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

LGTM! 🚢

@dusi dusi merged commit 51966e8 into master Oct 3, 2019
@dusi dusi deleted the reward-received-toggle-initial-value branch October 3, 2019 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants