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-1816] PLOT Ineligible state #2220

Merged
merged 23 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7fda0e7
Add functionality for the Pledge Over Time option selected
jovaniks Dec 5, 2024
5169766
Fix Tests
jovaniks Dec 5, 2024
ed401ec
Adding project to make the currency convertions and increments table …
jovaniks Dec 11, 2024
eff7fa4
Test timestamp with constant
jovaniks Dec 11, 2024
a334555
Add ineligible option
jovaniks Dec 11, 2024
b5aab6c
Format
jovaniks Dec 11, 2024
1c0df65
Fix test and add a new for ineligible
jovaniks Dec 11, 2024
43bd0a5
PR feedback
jovaniks Dec 11, 2024
5db01cb
Merge branch 'main' into jluna/MBL-1815/plot-plan-selector-selected-s…
jovaniks Dec 11, 2024
0f4c23e
Merge branch 'jluna/MBL-1815/plot-plan-selector-selected-state' into …
jovaniks Dec 11, 2024
2bcd664
minor nit
jovaniks Dec 11, 2024
acc641d
Minor nits
jovaniks Dec 12, 2024
7d6faa3
Merge branch 'jluna/MBL-1815/plot-plan-selector-selected-state' into …
jovaniks Dec 12, 2024
ee2bca5
Format
jovaniks Dec 12, 2024
809c848
update ineligible arg position
jovaniks Dec 13, 2024
8893498
PR Feedback
jovaniks Dec 17, 2024
8589d20
Merge branch 'main' into jluna/MBL-1815/plot-plan-selector-selected-s…
jovaniks Dec 17, 2024
d38cfa3
Merge branch 'main' into jluna/MBL-1815/plot-plan-selector-selected-s…
jovaniks Dec 17, 2024
26845e1
Merge conflicts and PR feedback
jovaniks Dec 17, 2024
581c945
Formatting
jovaniks Dec 17, 2024
d1da37d
Merge conflicts
jovaniks Dec 17, 2024
306337b
Merge branch 'main' into jluna/MBL-1816/plot-ineligible-state
jovaniks Dec 17, 2024
d42d885
Update GraphAPI file
jovaniks Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,20 @@ final class PledgePaymentPlansViewController: UIViewController {
guard let self = self else { return }

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import SnapshotTesting
import UIKit

final class PledgePaymentPlansViewControllerTest: TestCase {
private let thresholdAmount = 125.0
override func setUp() {
super.setUp()
AppEnvironment.pushEnvironment(mainBundle: Bundle.framework)
Expand All @@ -25,7 +26,11 @@ final class PledgePaymentPlansViewControllerTest: TestCase {
withEnvironment(language: language) {
let controller = PledgePaymentPlansViewController.instantiate()

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

let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
Expand All @@ -48,7 +53,9 @@ final class PledgePaymentPlansViewControllerTest: TestCase {
let data = PledgePaymentPlansAndSelectionData(
selectedPlan: .pledgeOverTime,
increments: testIncrements,
project: project
ineligible: false,
project: project,
thresholdAmount: thresholdAmount
)
controller.configure(with: data)

Expand All @@ -60,7 +67,32 @@ final class PledgePaymentPlansViewControllerTest: TestCase {
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)
parent.view.frame.size.height = 400

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

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

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

let data = PledgePaymentPlansAndSelectionData(
selectedPlan: .pledgeInFull,
increments: testPledgePaymentIncrement(),
ineligible: true,
project: Project.template,
thresholdAmount: self.thresholdAmount
)

controller.configure(with: data)

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

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

assertSnapshot(matching: parent.view, as: .image, named: "lang_\(language)_device_\(device)")
}
Expand Down
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 @@ -8,9 +8,14 @@ private enum Constants {
public static let detailsStackViewSpacing = Styles.grid(6)
public static let incrementStackViewSpacing = Styles.gridHalf(1)
public static let optionDescriptorStackViewSpacing = Styles.grid(1)
public static let ineligibleBadgeTopButtonPadding = 6.0
public static let ineligibleBadgeLeadingTrailingPadding = 8.0

/// Size
public static let selectionIndicatorImageWith = Styles.grid(4)

/// Corner radius
public static let defaultCornerRadius = Styles.grid(1)
}

protocol PledgePaymentPlanOptionViewDelegate: AnyObject {
Expand All @@ -34,6 +39,8 @@ final class PledgePaymentPlanOptionView: UIView {
private lazy var selectionIndicatorImageView: UIImageView = { UIImageView(frame: .zero) }()
private lazy var termsOfUseButton: UIButton = { UIButton(frame: .zero) }()
private lazy var paymentIncrementsStackView: UIStackView = { UIStackView(frame: .zero) }()
private lazy var ineligibleBadgeLabel: UILabel = { UILabel(frame: .zero) }()
private lazy var ineligibleBadgeView: UIView = { UIView(frame: .zero) }()

private let viewModel: PledgePaymentPlansOptionViewModelType = PledgePaymentPlansOptionViewModel()

Expand Down Expand Up @@ -64,6 +71,7 @@ final class PledgePaymentPlanOptionView: UIView {
self.optionDescriptorStackView.addArrangedSubviews(
self.titleLabel,
self.subtitleLabel,
self.ineligibleBadgeView,
self.termsOfUseButton,
self.paymentIncrementsStackView
)
Expand Down Expand Up @@ -130,6 +138,30 @@ final class PledgePaymentPlanOptionView: UIView {
])

self.termsOfUseButton.setContentHuggingPriority(.required, for: .horizontal)

self.ineligibleBadgeView.addSubview(self.ineligibleBadgeLabel)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be slightly cleaner/more brief if the ineligibleBadgeView was its own UIView subclass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to the follow up/clean up ticket https://kickstarter.atlassian.net/browse/MBL-1940

self.ineligibleBadgeLabel.translatesAutoresizingMaskIntoConstraints = false
self.ineligibleBadgeLabel.setContentHuggingPriority(.required, for: .horizontal)
self.ineligibleBadgeView.setContentHuggingPriority(.required, for: .horizontal)

NSLayoutConstraint.activate([
self.ineligibleBadgeLabel.topAnchor.constraint(
equalTo: self.ineligibleBadgeView.topAnchor,
constant: Constants.ineligibleBadgeTopButtonPadding
),
self.ineligibleBadgeLabel.bottomAnchor.constraint(
equalTo: self.ineligibleBadgeView.bottomAnchor,
constant: -Constants.ineligibleBadgeTopButtonPadding
),
self.ineligibleBadgeLabel.leadingAnchor.constraint(
equalTo: self.ineligibleBadgeView.leadingAnchor,
constant: Constants.ineligibleBadgeLeadingTrailingPadding
),
self.ineligibleBadgeLabel.trailingAnchor.constraint(
equalTo: self.ineligibleBadgeView.trailingAnchor,
constant: -Constants.ineligibleBadgeLeadingTrailingPadding
)
])
}

private func configureTapGestureAndActions() {
Expand Down Expand Up @@ -158,6 +190,8 @@ final class PledgePaymentPlanOptionView: UIView {
applySelectionIndicatorImageViewStyle(self.selectionIndicatorImageView)
applyTermsOfUseStyle(self.termsOfUseButton)
applyPaymentIncrementsStackViewStyle(self.paymentIncrementsStackView)
applyIneligibleBadgeViewStyle(self.ineligibleBadgeView)
applyIneligibleBadgeLabelStyle(self.ineligibleBadgeLabel)
}

// MARK: - View model
Expand Down Expand Up @@ -192,9 +226,21 @@ final class PledgePaymentPlanOptionView: UIView {
self.delegate?.pledgePaymentPlansViewController(self, didTapTermsOfUseWith: helpType)
}

self.ineligibleBadgeView.rac.hidden = self.viewModel.outputs.ineligibleBadgeHidden
self.ineligibleBadgeLabel.rac.text = self.viewModel.outputs.ineligibleBadgeText

self.termsOfUseButton.rac.hidden = self.viewModel.outputs.termsOfUseButtonHidden
self.paymentIncrementsStackView.rac.hidden = self.viewModel.outputs.paymentIncrementsHidden

self.viewModel.outputs.optionViewEnabled
.observeForUI()
.observeValues { [weak self] isOptionViewEnabled in
guard let self = self else { return }

self.isUserInteractionEnabled = isOptionViewEnabled
applyTextColorByState(self.titleLabel, isEnabled: isOptionViewEnabled)
}

self.viewModel.outputs.paymentIncrements
.observeForUI()
.observeValues { [weak self] increments in
Expand Down Expand Up @@ -284,7 +330,6 @@ private func applyTitleLabelStyle(_ label: UILabel) {
label.adjustsFontForContentSizeCategory = true
label.numberOfLines = 0
label.font = UIFont.ksr_subhead().bolded
label.textColor = .ksr_black
}

private func applySubtitleLabelStyle(_ label: UILabel) {
Expand Down Expand Up @@ -317,6 +362,7 @@ private func applyIncrementStackViewStyle(_ stackView: UIStackView) {

private func applyIncrementDetailsStackViewStyle(_ stackview: UIStackView) {
stackview.axis = .horizontal
stackview.distribution = .fill
stackview.spacing = Constants.detailsStackViewSpacing
}

Expand All @@ -334,3 +380,20 @@ private func applyIncrementDateLabelStyle(_ label: UILabel) {
label.textAlignment = .left
label.adjustsFontForContentSizeCategory = true
}

private func applyIneligibleBadgeViewStyle(_ view: UIView) {
view.backgroundColor = .ksr_support_100
view.rounded(with: Constants.defaultCornerRadius)
}

private func applyIneligibleBadgeLabelStyle(_ label: UILabel) {
label.font = UIFont.ksr_caption1().bolded
label.textColor = .ksr_support_500
label.textAlignment = .center
label.numberOfLines = 0
label.adjustsFontForContentSizeCategory = true
}

private func applyTextColorByState(_ label: UILabel, isEnabled: Bool) {
label.textColor = isEnabled ? .ksr_black : .ksr_support_300
}
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,54 @@ final class NoShippingPledgeViewControllerTests: TestCase {
RemoteConfigFeature.pledgeOverTime.rawValue: true
]

orthogonalCombos([Language.en], [Device.phone4_7inch, Device.pad])
.forEach { language, device in
withEnvironment(
apiService: mockService,
currentUser: User.template,
language: language,
remoteConfigClient: mockConfigClient
) {
let controller = NoShippingPledgeViewController.instantiate()
let data = PledgeViewData(
project: project,
rewards: [reward],
selectedShippingRule: .template,
selectedQuantities: [reward.id: 15], // To pass the threshold validation
selectedLocationId: nil,
refTag: nil,
context: .pledge
)
controller.configure(with: data)
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)

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

self.allowLayoutPass()

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

func testView_ShowCollectionPlans_Ineligible() {
let response = UserEnvelope<GraphUser>(me: self.userWithCards)
let mockService = MockService(fetchGraphUserResult: .success(response))
let project = Project.template
|> \.availableCardTypes .~ [CreditCardType.discover.rawValue]
|> Project.lens.isPledgeOverTimeAllowed .~ true
let reward = Reward.template

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

orthogonalCombos([Language.en], [Device.phone4_7inch, Device.pad])
.forEach { language, device in
withEnvironment(
Expand Down
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
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.
4 changes: 4 additions & 0 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
3385CF012CF6116B00A33D86 /* UIStackView+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3385CF002CF6115D00A33D86 /* UIStackView+Helper.swift */; };
3386546E2CE29AEC00AB16A9 /* PledgePaymentPlansOptionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3386546D2CE29AD500AB16A9 /* PledgePaymentPlansOptionViewModel.swift */; };
338654752CE3D22600AB16A9 /* PledgePaymentPlansViewModelTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 338654732CE3D17200AB16A9 /* PledgePaymentPlansViewModelTest.swift */; };
33914D6D2D07D24500A67C47 /* UIView+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33914D6C2D07D23B00A67C47 /* UIView+Helper.swift */; };
339ED5602CE41015004B301D /* PledgePaymentPlansViewControllerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 339ED55E2CE40FC5004B301D /* PledgePaymentPlansViewControllerTest.swift */; };
339ED5662CE43099004B301D /* PledgePaymentPlansOptionViewModelTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 339ED5642CE41AFC004B301D /* PledgePaymentPlansOptionViewModelTest.swift */; };
33C9F0BE2CF5104C00B62E14 /* PledgePaymentPlanOptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33C9F0BC2CED6DEF00B62E14 /* PledgePaymentPlanOptionView.swift */; };
Expand Down Expand Up @@ -1926,6 +1927,7 @@
3385CF002CF6115D00A33D86 /* UIStackView+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIStackView+Helper.swift"; sourceTree = "<group>"; };
3386546D2CE29AD500AB16A9 /* PledgePaymentPlansOptionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PledgePaymentPlansOptionViewModel.swift; sourceTree = "<group>"; };
338654732CE3D17200AB16A9 /* PledgePaymentPlansViewModelTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PledgePaymentPlansViewModelTest.swift; sourceTree = "<group>"; };
33914D6C2D07D23B00A67C47 /* UIView+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Helper.swift"; sourceTree = "<group>"; };
339ED55E2CE40FC5004B301D /* PledgePaymentPlansViewControllerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PledgePaymentPlansViewControllerTest.swift; sourceTree = "<group>"; };
339ED5642CE41AFC004B301D /* PledgePaymentPlansOptionViewModelTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PledgePaymentPlansOptionViewModelTest.swift; sourceTree = "<group>"; };
33C9F0BC2CED6DEF00B62E14 /* PledgePaymentPlanOptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PledgePaymentPlanOptionView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5882,6 +5884,7 @@
778F891A22D3E35600D095C5 /* Extensions */ = {
isa = PBXGroup;
children = (
33914D6C2D07D23B00A67C47 /* UIView+Helper.swift */,
3385CF002CF6115D00A33D86 /* UIStackView+Helper.swift */,
77C9122623C4F99400F3D2C9 /* Double+Currency.swift */,
77C9123023C637FD00F3D2C9 /* DoubleCurrencyTests.swift */,
Expand Down Expand Up @@ -8082,6 +8085,7 @@
8AC3E13A269F781D00168BF8 /* ErrorEnvelope+LocalizedDescription.swift in Sources */,
D04AAC34218BB70D00CF713E /* SettingsAccountPickerCellViewModel.swift in Sources */,
A75511691C8642C3005355CF /* UILabel+IBClear.swift in Sources */,
33914D6D2D07D24500A67C47 /* UIView+Helper.swift in Sources */,
06BD75C926C431A000A12D4E /* CommentDialogViewModel.swift in Sources */,
064B007827A463D2007B21FE /* ImageViewElementCellViewModel.swift in Sources */,
A7F441E51D005A9400FE6FC5 /* SearchViewModel.swift in Sources */,
Expand Down
10 changes: 10 additions & 0 deletions KsApi/GraphAPI.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Library/Extensions/UIView+Helper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import UIKit

extension UIView {
public func rounded(with cornerRadius: CGFloat = Styles.cornerRadius) {
self.clipsToBounds = true
self.layer.masksToBounds = true
self.layer.cornerRadius = cornerRadius
}
jovaniks marked this conversation as resolved.
Show resolved Hide resolved
}
Loading