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

chore Improve tintColor tests #1507

Merged
merged 9 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 17 additions & 7 deletions Tests/Card Tests/CardComponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,18 @@ class CardComponentTests: XCTestCase {
}

func testTintColorCustomization() throws {
guard #available(iOS 17.0, *) else {
throw XCTSkip("This test is unfortunately very flaky on macos-12 runners that are needed to test on older iOS versions - so we skip it")
}

var configuration = CardComponent.Configuration()

let tintColor: UIColor = .black
let titleColor: UIColor = .gray

configuration.style = {
var style = FormComponentStyle(tintColor: .systemYellow)
style.textField.title.color = .gray
var style = FormComponentStyle(tintColor: tintColor)
style.textField.title.color = titleColor
return style
}()

Expand All @@ -425,13 +431,16 @@ class CardComponentTests: XCTestCase {
let switchView: UISwitch = try XCTUnwrap(component.viewController.view.findView(with: "AdyenCard.CardComponent.storeDetailsItem.switch"))
let securityCodeItemView: FormTextItemView<FormCardSecurityCodeItem> = try XCTUnwrap(component.viewController.view.findView(with: "AdyenCard.CardComponent.securityCodeItem"))

XCTAssertEqual(securityCodeItemView.titleLabel.textColor, .gray)
wait(until: switchView, at: \.onTintColor, is: tintColor)

wait(until: securityCodeItemView, at: \.titleLabel.textColor, is: titleColor)

self.focus(textItemView: securityCodeItemView)
try withoutAnimation {
focus(textItemView: securityCodeItemView)
}

wait(until: switchView, at: \.onTintColor, is: .systemYellow)
wait(until: securityCodeItemView, at: \.titleLabel.textColor, is: .systemYellow)
wait(until: securityCodeItemView, at: \.separatorView.backgroundColor?.cgColor, is: UIColor.systemYellow.cgColor)
wait(until: securityCodeItemView, at: \.titleLabel.textColor, is: tintColor)
wait(until: securityCodeItemView, at: \.separatorView.backgroundColor, is: tintColor)
}

func testSuccessTintColorCustomization() throws {
Expand Down Expand Up @@ -2213,6 +2222,7 @@ class CardComponentTests: XCTestCase {

private func focus(textItemView: some FormTextItemView<some FormTextItem>) {
textItemView.textField.becomeFirstResponder()
wait(until: textItemView.textField, at: \.isFirstResponder, is: true)
}

private enum CardViewIdentifier {
Expand Down
9 changes: 4 additions & 5 deletions Tests/Card Tests/Utilities/ThrottlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import XCTest
class ThrottlerTests: XCTestCase {

func test() {
let sut = Throttler(minimumDelay: 1)
let sut = Throttler(minimumDelay: 0.3)

let lastBlockExpectation = expectation(description: "wait for last block execution")

Expand All @@ -29,12 +29,11 @@ class ThrottlerTests: XCTestCase {
}
}

wait(for: .milliseconds(100))
wait(for: .milliseconds(5))
}

waitForExpectations(timeout: 100, handler: nil)

XCTAssertEqual(counter, 1)
wait(for: [lastBlockExpectation], timeout: 100)
XCTAssertEqual(counter, 1) // Making sure the code was only executed once
}

}
17 changes: 14 additions & 3 deletions Tests/Helpers/XCTestCase+RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ extension DispatchTimeInterval {
extension XCTestCase {

enum TestAnimationSpeed: Float {
case paused = 0
case system = 1
case fast = 100
}
Expand All @@ -74,9 +73,21 @@ extension XCTestCase {
///
/// After the block the animation speed gets reset to the previous speed
func withAnimation(_ speed: TestAnimationSpeed, block: () throws -> Void) throws {
let speedBefore = UIApplication.shared.adyen.mainKeyWindow?.layer.speed ?? 1
let previousLayerSpeed = UIApplication.shared.adyen.mainKeyWindow?.layer.speed ?? 1

UIApplication.shared.adyen.mainKeyWindow?.layer.speed = speed.rawValue
try block()
UIApplication.shared.adyen.mainKeyWindow?.layer.speed = speedBefore
UIApplication.shared.adyen.mainKeyWindow?.layer.speed = previousLayerSpeed
}

/// Executes a block with UIView animations disabled
///
/// After the block the animation speed gets reset to the previous value
func withoutAnimation(block: () throws -> Void) throws {
let wereAnimationsEnabled = UIView.areAnimationsEnabled

UIView.setAnimationsEnabled(false)
try block()
UIView.setAnimationsEnabled(wereAnimationsEnabled)
}
}
2 changes: 1 addition & 1 deletion UITests/Components/BLIK/BLIKComponentUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ final class BLIKComponentUITests: XCTestCase {

let submitButton: SubmitButton! = sut.viewController.view.findView(with: "AdyenComponents.BLIKComponent.payButtonItem.button")

try withAnimation(.paused) {
try withoutAnimation {
// start loading
submitButton.showsActivityIndicator = true
wait(until: submitButton, at: \.showsActivityIndicator, is: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class OnlineBankingComponentUITests: XCTestCase {
sut.viewController.view.findView(with: "AdyenComponents.OnlineBankingComponent.continueButton.button")
)

try withAnimation(.paused) {
try withoutAnimation {
// start loading
button.showsActivityIndicator = true
wait(until: button, at: \.showsActivityIndicator, is: true)
Expand Down
Loading