Skip to content

Commit

Permalink
Add screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Nov 21, 2024
1 parent 735c43c commit 4630b6f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
C28450436BDA52BE9BE3BDC3 /* PaymentSheetConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E83494558F0C93C5B05A1DFB /* PaymentSheetConfigurationTests.swift */; };
C346B534D57A952D4415ADFD /* Intent+Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04C8047FD8994D3FAA3D1A7A /* Intent+Link.swift */; };
C5E3750BBCA700CF364F7578 /* PaymentSheetFormFactory+OXXO.swift in Sources */ = {isa = PBXBuildFile; fileRef = F20379AE078D68A0AC83A6C5 /* PaymentSheetFormFactory+OXXO.swift */; };
CB225E962CEF80DC00054262 /* PaymentMethodTypeCollectionViewCellSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB225E952CEF80DC00054262 /* PaymentMethodTypeCollectionViewCellSnapshotTests.swift */; };
CB46EF4B2CED1BDA00E9A7F2 /* PromoBadgeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB46EF4A2CED1BDA00E9A7F2 /* PromoBadgeView.swift */; };
CD19725E26DBDB9960D828CB /* BottomSheetPresentationAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8F09CF961C943E36D76860F /* BottomSheetPresentationAnimator.swift */; };
CF2AD2C7F761C46AE559E563 /* SavedPaymentOptionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B3ECDF6CF9AABD573F86CA2 /* SavedPaymentOptionsViewController.swift */; };
Expand Down Expand Up @@ -752,6 +753,7 @@
C90A2636C2A577AF36FB793B /* PaymentSheetLoaderTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentSheetLoaderTest.swift; sourceTree = "<group>"; };
C94104A367EAF6C8785C17A1 /* FormSpecProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormSpecProvider.swift; sourceTree = "<group>"; };
C9726902C985C99F69E6880C /* CustomerSheet+PaymentMethodAvailability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CustomerSheet+PaymentMethodAvailability.swift"; sourceTree = "<group>"; };
CB225E952CEF80DC00054262 /* PaymentMethodTypeCollectionViewCellSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentMethodTypeCollectionViewCellSnapshotTests.swift; sourceTree = "<group>"; };
CB46EF4A2CED1BDA00E9A7F2 /* PromoBadgeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromoBadgeView.swift; sourceTree = "<group>"; };
CBCFE3D39D670C3C77C59722 /* cs-CZ */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "cs-CZ"; path = "cs-CZ.lproj/Localizable.strings"; sourceTree = "<group>"; };
CC3498CF4AEAA8F169616CDF /* STPCardBrandChoice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = STPCardBrandChoice.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1643,6 +1645,7 @@
C830FEC205E7162FF4D414BE /* PaymentMethodMessagingViewFunctionalTest.swift */,
5BA7BFC43DB3EFD38A460EB9 /* PaymentMethodMessagingViewSnapshotTests.swift */,
619AF0842BF56C5E00D1C981 /* PaymentMethodRowButtonSnapshotTests.swift */,
CB225E952CEF80DC00054262 /* PaymentMethodTypeCollectionViewCellSnapshotTests.swift */,
8A0B7F6E25D93C0C0ACE3B3D /* PaymentSheet+APITest.swift */,
82C21D5722BDEB8BAA71F69F /* PaymentSheet+DashboardConfirmParamsTest.swift */,
AA8F7F2824DFC78268ED6459 /* PaymentSheet+DeferredAPITest.swift */,
Expand Down Expand Up @@ -1951,6 +1954,7 @@
31CC9B812CB5F69600E84A38 /* LinkInstantDebitMandateViewSnapshotTests.swift in Sources */,
31CC9B822CB5F69600E84A38 /* LinkURLGeneratorTests.swift in Sources */,
31CC9B852CB5F69600E84A38 /* LinkBadgeViewSnapshotTest.swift in Sources */,
CB225E962CEF80DC00054262 /* PaymentMethodTypeCollectionViewCellSnapshotTests.swift in Sources */,
B65FE7092BED33EA009A73FC /* VerticalPaymentMethodListViewControllerSnapshotTest.swift in Sources */,
37F750E1C99D6257E845A66E /* BacsDDMandateViewSnapshotTests.swift in Sources */,
694A3B36AC19FC1F87EF0CB1 /* CustomerSheetPaymentMethodAvailabilityTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ class PaymentMethodRowButtonSnapshotTests: STPSnapshotTestCase {
rowButton.state = .selected
verify(rowButton)
}

func testPaymentMethodRowButton_newPaymentMethod_unselected() {
let rowButton = RowButton.makeForPaymentMethodType(
paymentMethodType: .instantDebits,
promoText: "$5",
savedPaymentMethodType: nil,
appearance: .default,
shouldAnimateOnPress: false,
didTap: { _ in }
)
verify(rowButton)
}

func verify(
_ view: UIView,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// PaymentMethodTypeCollectionViewCellSnapshotTests.swift
// StripePaymentSheetTests
//
// Created by Till Hellmund on 11/21/24.
//

import Foundation
import StripeCoreTestUtils
import UIKit

@testable@_spi(STP) import StripePaymentSheet

class PaymentMethodTypeCollectionViewCellSnapshotTests: STPSnapshotTestCase {

func test_withPromoBadge() {
let cell = PaymentMethodTypeCollectionView.PaymentTypeCell()
cell.paymentMethodType = .instantDebits
cell.promoBadgeText = "$5"
verify(cell)
}

func verify(
_ cell: UICollectionViewCell,
identifier: String? = nil,
file: StaticString = #filePath,
line: UInt = #line
) {
let view = CellWrapperView(
cell: cell,
size: CGSize(width: 120, height: PaymentMethodTypeCollectionView.cellHeight)
)
STPSnapshotVerifyView(view, identifier: identifier, file: file, line: line)
}
}

private class CellWrapperView: UIView {
init(cell: UICollectionViewCell, size: CGSize) {
super.init(frame: CGRect(origin: .zero, size: size))
cell.frame = self.bounds
addSubview(cell)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Binary file added ...ttonSnapshotTests/[email protected]
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.

0 comments on commit 4630b6f

Please sign in to comment.