Skip to content

Commit

Permalink
Address code review feedback
Browse files Browse the repository at this point in the history
- Rename `theme` to `appearance`
- Add snapshot with long bank name
- Make `text` nullable
  • Loading branch information
tillh-stripe committed Dec 18, 2024
1 parent 35230e0 commit 67a917d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ class BankAccountInfoView: UIView {

init(
frame: CGRect,
theme: PaymentSheet.Appearance = .default,
appearance: PaymentSheet.Appearance = .default,
incentive: PaymentMethodIncentive? = nil
) {
self.appearance = theme
self.appearance = appearance
self.incentive = incentive
super.init(frame: frame)
addViewComponents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ final class InstantDebitsPaymentMethodElement: ContainerElement {
let theme = appearance.asElementsTheme

self.configuration = configuration
self.linkedBankInfoView = BankAccountInfoView(frame: .zero, theme: appearance, incentive: incentive)
self.linkedBankInfoView = BankAccountInfoView(frame: .zero, appearance: appearance, incentive: incentive)
self.linkedBankInfoSectionElement = SectionElement(
title: String.Localized.bank_account_sentence_case,
elements: [StaticElement(view: linkedBankInfoView)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ final class USBankAccountPaymentMethodElement: ContainerElement {

self.configuration = configuration
self.linkedBank = initialLinkedBank
self.bankInfoView = BankAccountInfoView(frame: .zero, theme: appearance)
self.bankInfoView = BankAccountInfoView(frame: .zero, appearance: appearance)
self.bankInfoSectionElement = SectionElement(title: String.Localized.bank_account_sentence_case,
elements: [StaticElement(view: bankInfoView)], theme: theme)
self.bankInfoSectionElement.view.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PromoBadgeView: UIView {

private var appearance: PaymentSheet.Appearance
private var cornerRadius: CGFloat?
private var text: String
private var text: String?
private var eligible: Bool

override var intrinsicContentSize: CGSize {
Expand All @@ -35,14 +35,14 @@ class PromoBadgeView: UIView {
self.appearance = appearance
self.cornerRadius = cornerRadius
self.eligible = true
self.text = text ?? ""
self.text = text
super.init(frame: .zero)

setupView(tinyMode: tinyMode)
updateAppearance()

if let text {
setText(text)
updateText(text)
}
}

Expand All @@ -62,15 +62,19 @@ class PromoBadgeView: UIView {

func setText(_ text: String) {
self.text = text
updateText()
updateText(text)
}

func setEligible(_ eligible: Bool) {
self.eligible = eligible
updateText()
updateText(text)
}

private func updateText() {
private func updateText(_ text: String?) {
guard let text else {
return
}

label.text = formatPromoText(text, eligible: eligible)
updateAppearance()
invalidateIntrinsicContentSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class BankAccountInfoViewSnapshotTests : STPSnapshotTestCase {
func test_noPromoBadge() {
let view = BankAccountInfoView(
frame: Self.frame,
theme: .default,
appearance: .default,
incentive: nil
)
view.setBankName(text: "Stripe Bank")
Expand All @@ -29,7 +29,7 @@ final class BankAccountInfoViewSnapshotTests : STPSnapshotTestCase {
func test_eligibleForPromo() {
let view = BankAccountInfoView(
frame: Self.frame,
theme: .default,
appearance: .default,
incentive: .init(identifier: "link_instant_debits", displayText: "$5")
)
view.setBankName(text: "Stripe Bank")
Expand All @@ -39,10 +39,23 @@ final class BankAccountInfoViewSnapshotTests : STPSnapshotTestCase {
verify(view)
}

func test_eligibleForPromo_longName() {
let view = BankAccountInfoView(
frame: Self.frame,
appearance: .default,
incentive: .init(identifier: "link_instant_debits", displayText: "$5")
)
view.setBankName(text: "The Official Stripe Bank")
view.setLastFourOfBank(text: "•••• 4242")
view.setIncentiveEligible(true)

verify(view)
}

func test_ineligibleForPromo() {
let view = BankAccountInfoView(
frame: Self.frame,
theme: .default,
appearance: .default,
incentive: .init(identifier: "link_instant_debits", displayText: "$5")
)
view.setBankName(text: "Stripe Bank")
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 67a917d

Please sign in to comment.