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-1896] Update status label copy for PLOT-enabled pledges #2222

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,69 @@ final class ManagePledgeViewControllerTests: TestCase {
}
}
}

func testView_CurrentUser_IsBacker_PledgeOverTime() {
let user = User.template
|> User.lens.id .~ 1

let reward = Reward.template
|> Reward.lens.shipping.enabled .~ true
|> Reward.lens.remaining .~ 49
|> Reward.lens.localPickup .~ nil

let addOns = [Reward.postcards |> Reward.lens.minimum .~ 10]

let backing = Backing.template
|> Backing.lens.addOns .~ addOns
|> Backing.lens.amount .~ 22
|> Backing.lens.reward .~ reward
|> Backing.lens.rewardId .~ reward.id
|> Backing.lens.paymentSource .~ Backing.PaymentSource.template

let project = Project.cosmicSurgery
|> Project.lens.personalization.backing .~ backing

let env = ProjectAndBackingEnvelope(project: project, backing: backing)

let mockService = MockService(
fetchManagePledgeViewBackingResult: .success(env),
fetchProjectResult: .success(project),
fetchProjectRewardsResult: .success([reward])
)

let mockConfigClient = MockRemoteConfigClient()
mockConfigClient.features = [
RemoteConfigFeature.pledgeOverTime.rawValue: true
]

// TODO: Update to `all` languages when the string translations task is finished. [MBL-1860](https://kickstarter.atlassian.net/browse/MBL-1860)
orthogonalCombos([Language.en], [Device.phone4_7inch, Device.pad]).forEach { language, device in
withEnvironment(
apiService: mockService,
currentUser: user,
language: language,
remoteConfigClient: mockConfigClient
) {
let controller = ManagePledgeViewController.instantiate()
controller.configureWith(params: (Param.slug("project-slug"), Param.id(1)))
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = 1_200

// Network request completes
self.scheduler.advance()

// endRefreshing is delayed by 300ms for animation duration
self.scheduler.advance(by: .milliseconds(300))

controller.tableView.layoutIfNeeded()
controller.tableView.reloadData()

assertSnapshot(
matching: parent.view,
as: .image(perceptualPrecision: 0.98),
named: "lang_\(language)_device_\(device)"
)
}
}
}
}
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.
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