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-1815] PLOT plan selector - selected state #2213

Merged
merged 11 commits into from
Dec 17, 2024
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