Skip to content

Commit

Permalink
Add dark mode tests for PaymentSheet snapshots (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
porter-stripe authored Mar 9, 2022
1 parent 5cf53e9 commit aed6174
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
#if DEBUG
if CommandLine.arguments.contains("UITestingDarkModeEnabled") {
window?.overrideUserInterfaceStyle = .dark
}
#endif
guard let _ = (scene as? UIWindowScene) else { return }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,64 @@ class PaymentSheetSnapshotTests: FBSnapshotTestCase {
}

func testPaymentSheetStandardCardSnapshot() throws {
testCard()
}

// Test sepa to ensure the address section looks correct
func testPaymentSheetStandardSEPASnapshot() throws {
testSepa()
}

func testPaymentSheetCustomSnapshot() throws {
testCustom()
}

func testPaymentSheetStandardCardSnapshot_darkMode() throws {
launchInDarkMode()
testCard()
}

// Test sepa to ensure the address section looks correct
func testPaymentSheetStandardSEPASnapshot_darkMode() throws {
launchInDarkMode()
testSepa()
}

func testPaymentSheetCustomSnapshot_darkMode() throws {
launchInDarkMode()
testCustom()
}

private func testCard() {
app.staticTexts[
"PaymentSheet"
].tap()
let buyButton = app.staticTexts["Buy"]
XCTAssertTrue(buyButton.waitForExistence(timeout: 60.0))
buyButton.tap()

XCTAssertTrue(app.buttons["Pay €9.73"].waitForExistence(timeout: 60.0))
let screenshot = app.screenshot().image.removingStatusBar
let imageView = UIImageView(image: screenshot)

verify(imageView)
}

// Test sepa to ensure the address section looks correct
func testPaymentSheetStandardSEPASnapshot() throws {
private func testCustom() {
app.staticTexts["PaymentSheet (Custom)"].tap()
let paymentMethodButton = app.staticTexts["Apple Pay"]
XCTAssertTrue(paymentMethodButton.waitForExistence(timeout: 60.0))
paymentMethodButton.tap()

let addCardButton = app.buttons["+ Add"]
XCTAssertTrue(addCardButton.waitForExistence(timeout: 4.0))

let screenshot = app.screenshot().image.removingStatusBar
let imageView = UIImageView(image: screenshot)
verify(imageView)
}

private func testSepa() {
app.staticTexts[
"PaymentSheet"
].tap()
Expand All @@ -72,18 +114,10 @@ class PaymentSheetSnapshotTests: FBSnapshotTestCase {
verify(imageView)
}

func testPaymentSheetCustomSnapshot() throws {
app.staticTexts["PaymentSheet (Custom)"].tap()
let paymentMethodButton = app.staticTexts["Apple Pay"]
XCTAssertTrue(paymentMethodButton.waitForExistence(timeout: 60.0))
paymentMethodButton.tap()

let addCardButton = app.buttons["+ Add"]
XCTAssertTrue(addCardButton.waitForExistence(timeout: 4.0))

let screenshot = app.screenshot().image.removingStatusBar
let imageView = UIImageView(image: screenshot)
verify(imageView)
private func launchInDarkMode() {
app = XCUIApplication()
app.launchArguments.append("UITestingDarkModeEnabled")
app.launch()
}

func verify(
Expand Down
Binary file added ...heetSnapshotTests/[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.
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 aed6174

Please sign in to comment.