Skip to content

Commit

Permalink
[MBL-1815] PLOT plan selector - selected state (#2213)
Browse files Browse the repository at this point in the history
* Add functionality for the Pledge Over Time option selected

* Fix Tests

* Adding project to make the currency convertions and increments table alignment issue

* Test timestamp with constant

* Format

* PR feedback

* minor nit

* PR Feedback
  • Loading branch information
jovaniks authored Dec 17, 2024
1 parent 662bcbe commit 67c8b0e
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ protocol PledgePaymentPlansViewControllerDelegate: AnyObject {
_ viewController: PledgePaymentPlansViewController,
didSelectPaymentPlan paymentPlan: PledgePaymentPlansType
)
func pledgePaymentPlansViewController(
_ viewController: PledgePaymentPlansViewController,
didTapTermsOfUseWith helpType: HelpType
)
}

final class PledgePaymentPlansViewController: UIViewController {
Expand Down Expand Up @@ -39,11 +43,11 @@ final class PledgePaymentPlansViewController: UIViewController {
self.pledgeInFullOption.delegate = self
self.pledgeOverTimeOption.delegate = self

self.rootStackView.addArrangedSubviews([
self.rootStackView.addArrangedSubviews(
self.pledgeInFullOption,
self.separatorView,
self.pledgeOverTimeOption
])
)
}

private func setupConstraints() {
Expand Down Expand Up @@ -82,11 +86,15 @@ final class PledgePaymentPlansViewController: UIViewController {

self.pledgeInFullOption.configureWith(value: PledgePaymentPlanOptionData(
type: .pledgeInFull,
selectedType: data.selectedPlan
selectedType: data.selectedPlan,
paymentIncrements: data.paymentIncrements,
project: data.project
))
self.pledgeOverTimeOption.configureWith(value: PledgePaymentPlanOptionData(
type: .pledgeOverTime,
selectedType: data.selectedPlan
selectedType: data.selectedPlan,
paymentIncrements: data.paymentIncrements,
project: data.project
))
}

Expand All @@ -97,6 +105,13 @@ final class PledgePaymentPlansViewController: UIViewController {

self.delegate?.pledgePaymentPlansViewController(self, didSelectPaymentPlan: paymentPlan)
}
self.viewModel.outputs.notifyDelegateTermsOfUseTapped
.observeForUI()
.observeValues { [weak self] helpType in
guard let self = self else { return }

self.delegate?.pledgePaymentPlansViewController(self, didTapTermsOfUseWith: helpType)
}
}

// MARK: - Configuration
Expand All @@ -115,6 +130,13 @@ extension PledgePaymentPlansViewController: PledgePaymentPlanOptionViewDelegate
) {
self.viewModel.inputs.didSelectPlanType(paymentPlanType)
}

func pledgePaymentPlansViewController(
_: PledgePaymentPlanOptionView,
didTapTermsOfUseWith helpType: HelpType
) {
self.viewModel.inputs.didTapTermsOfUse(with: helpType)
}
}

// MARK: Styles
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@testable import Kickstarter_Framework
@testable import KsApi
@testable import Library
import Prelude
import SnapshotTesting
Expand All @@ -19,11 +20,12 @@ final class PledgePaymentPlansViewControllerTest: TestCase {
}

func testView_PledgeInFullSelected() {
let project = Project.template
orthogonalCombos([Language.en], [Device.pad, Device.phone4_7inch]).forEach { language, device in
withEnvironment(language: language) {
let controller = PledgePaymentPlansViewController.instantiate()

let data = PledgePaymentPlansAndSelectionData(selectedPlan: .pledgeInFull)
let data = PledgePaymentPlansAndSelectionData(selectedPlan: .pledgeInFull, project: project)
controller.configure(with: data)

let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
Expand All @@ -37,20 +39,45 @@ final class PledgePaymentPlansViewControllerTest: TestCase {
}

func testView_PledgeOverTimeSelected() {
let project = Project.template
let testIncrements = testPledgePaymentIncrement()
orthogonalCombos([Language.en], [Device.pad, Device.phone4_7inch]).forEach { language, device in
withEnvironment(language: language) {
let controller = PledgePaymentPlansViewController.instantiate()

let data = PledgePaymentPlansAndSelectionData(selectedPlan: .pledgeOverTime)
let data = PledgePaymentPlansAndSelectionData(
selectedPlan: .pledgeOverTime,
increments: testIncrements,
project: project
)
controller.configure(with: data)

controller.pledgePaymentPlanOptionView(
PledgePaymentPlanOptionView(),
didSelectPlanType: .pledgeOverTime
)

let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = 400

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

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

private func testPledgePaymentIncrement() -> [PledgePaymentIncrement] {
var increments: [PledgePaymentIncrement] = []
var timeStamp = TimeInterval(1_733_931_903)
for _ in 1...4 {
timeStamp += 30 * 24 * 60 * 60
increments.append(PledgePaymentIncrement(
amount: PledgePaymentIncrementAmount(amount: 250.0, currency: "USD"),
scheduledCollection: timeStamp
))
}

return increments
}
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.
Loading

0 comments on commit 67c8b0e

Please sign in to comment.