Skip to content

Commit

Permalink
Add UI tests for the security code component
Browse files Browse the repository at this point in the history
  • Loading branch information
okhan-okbay-cko committed Oct 23, 2023
1 parent 0c2e6d3 commit 0b349fd
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 24 deletions.
4 changes: 4 additions & 0 deletions Source/Core/Constants/AccessibilityIdentifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ public enum AccessibilityIdentifiers {
static public let phoneNumber = "PhoneNumberInput"
}

public enum SecurityCodeComponent {
/// Identify security code component text field
static public let textField = "SecurityCodeTextField"
}
}
4 changes: 2 additions & 2 deletions Source/UI/SecurityCodeComponent/SecurityCodeComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension SecurityCodeComponent {

let view = SecurityCodeView(viewModel: viewModel)
view.update(style: DefaultSecurityCodeFormStyle(securityCodeComponentStyle: configuration.style))
view.accessibilityIdentifier = AccessibilityIdentifiers.PaymentForm.cardSecurityCode
view.accessibilityIdentifier = AccessibilityIdentifiers.SecurityCodeComponent.textField
view.delegate = self

view.frame = bounds
Expand All @@ -52,7 +52,7 @@ extension SecurityCodeComponent {

extension SecurityCodeComponent: SecurityCodeViewDelegate {
func update(securityCode: String) {
guard securityCode.count > 0 else {
guard securityCode.isEmpty else {
isSecurityCodeValid(false)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let tokenableTestCards: [TestCard] = [
]

/**
These are luhn numbers that are just 1 character less with the least character count of the relevant card schemes
These are luhn numbers that are just 1 character less than the min character count of the relevant card schemes
For example, Visa cards must be at least 13 characters and must start with 44.
So, we needed a luhn number that starts with 4 and is 12 digits.
To see that we check the character count beyond the luhn verifications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
16857B742A65F15F005CAE39 /* CardTypeTokenCreationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16857B732A65F15F005CAE39 /* CardTypeTokenCreationTests.swift */; };
16857B7E2A65F3F3005CAE39 /* XCUIApplication+TestHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16857B7D2A65F3F3005CAE39 /* XCUIApplication+TestHelpers.swift */; };
168CEC952AC5C71700BB52B0 /* SecurityCodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 168CEC942AC5C71700BB52B0 /* SecurityCodeViewController.swift */; };
16900D412AE2FAB3009A7CE9 /* Frames in Frameworks */ = {isa = PBXBuildFile; productRef = 16900D402AE2FAB3009A7CE9 /* Frames */; };
16900D442AE6BA38009A7CE9 /* SecurityCodeComponentUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16900D432AE6BA38009A7CE9 /* SecurityCodeComponentUITests.swift */; };
16900D4B2AE70F90009A7CE9 /* Frames in Frameworks */ = {isa = PBXBuildFile; productRef = 16900D4A2AE70F90009A7CE9 /* Frames */; };
169DF1482A7BFB1B00891DF0 /* CardSchemeFormatSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 169DF1472A7BFB1B00891DF0 /* CardSchemeFormatSnapshotTests.swift */; };
16C3F8402A7927ED00690639 /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 16C3F83F2A7927ED00690639 /* SnapshotTesting */; };
16C3F8422A7956EA00690639 /* CardValidationSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16C3F8412A7956EA00690639 /* CardValidationSnapshotTests.swift */; };
Expand Down Expand Up @@ -129,6 +130,7 @@
16857B732A65F15F005CAE39 /* CardTypeTokenCreationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardTypeTokenCreationTests.swift; sourceTree = "<group>"; };
16857B7D2A65F3F3005CAE39 /* XCUIApplication+TestHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCUIApplication+TestHelpers.swift"; sourceTree = "<group>"; };
168CEC942AC5C71700BB52B0 /* SecurityCodeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecurityCodeViewController.swift; sourceTree = "<group>"; };
16900D432AE6BA38009A7CE9 /* SecurityCodeComponentUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecurityCodeComponentUITests.swift; sourceTree = "<group>"; };
169DF1472A7BFB1B00891DF0 /* CardSchemeFormatSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardSchemeFormatSnapshotTests.swift; sourceTree = "<group>"; };
16AE74C32A5C1EBB0031F794 /* iOS Example Frame.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "iOS Example Frame.app"; sourceTree = BUILT_PRODUCTS_DIR; };
16AE74C42A5C1EBB0031F794 /* iOS Example FrameUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "iOS Example FrameUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -219,7 +221,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
16900D412AE2FAB3009A7CE9 /* Frames in Frameworks */,
16900D4B2AE70F90009A7CE9 /* Frames in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -413,6 +415,7 @@
isa = PBXGroup;
children = (
0BD2ECBE28B65DA10041A942 /* FrameUITests.swift */,
16900D432AE6BA38009A7CE9 /* SecurityCodeComponentUITests.swift */,
0BD2ECC028B65EC20041A942 /* XCUIApplication+Extension.swift */,
);
name = "iOS Example FrameUITests";
Expand Down Expand Up @@ -508,7 +511,7 @@
);
name = "iOS Example Frame";
packageProductDependencies = (
16900D402AE2FAB3009A7CE9 /* Frames */,
16900D4A2AE70F90009A7CE9 /* Frames */,
);
productName = "iOS Example Frame";
productReference = 16AE74C32A5C1EBB0031F794 /* iOS Example Frame.app */;
Expand Down Expand Up @@ -557,7 +560,7 @@
mainGroup = E6646F8120CE6C0900D8353A;
packageReferences = (
16C3F83E2A7927ED00690639 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */,
16900D3F2AE2FAB3009A7CE9 /* XCRemoteSwiftPackageReference "frames-ios" */,
16900D492AE70F90009A7CE9 /* XCRemoteSwiftPackageReference "frames-ios" */,
);
productRefGroup = E6646F8120CE6C0900D8353A;
projectDirPath = "";
Expand Down Expand Up @@ -666,6 +669,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
16900D442AE6BA38009A7CE9 /* SecurityCodeComponentUITests.swift in Sources */,
0BD2ECBF28B65DA10041A942 /* FrameUITests.swift in Sources */,
0BD2ECC128B65EC20041A942 /* XCUIApplication+Extension.swift in Sources */,
);
Expand Down Expand Up @@ -1209,12 +1213,12 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
16900D3F2AE2FAB3009A7CE9 /* XCRemoteSwiftPackageReference "frames-ios" */ = {
16900D492AE70F90009A7CE9 /* XCRemoteSwiftPackageReference "frames-ios" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "file:///Users/okhanokbay/Documents/frames-ios";
repositoryURL = "https://github.com/checkout/frames-ios";
requirement = {
branch = "feature/cvv-component";
kind = branch;
kind = upToNextMajorVersion;
minimumVersion = 4.2.1;
};
};
16C3F83E2A7927ED00690639 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */ = {
Expand All @@ -1228,9 +1232,9 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
16900D402AE2FAB3009A7CE9 /* Frames */ = {
16900D4A2AE70F90009A7CE9 /* Frames */ = {
isa = XCSwiftPackageProductDependency;
package = 16900D3F2AE2FAB3009A7CE9 /* XCRemoteSwiftPackageReference "frames-ios" */;
package = 16900D492AE70F90009A7CE9 /* XCRemoteSwiftPackageReference "frames-ios" */;
productName = Frames;
};
16C3F83F2A7927ED00690639 /* SnapshotTesting */ = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="NL5-0J-36O">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="NL5-0J-36O">
<device id="retina6_0" orientation="portrait" appearance="light"/>
<dependencies>
<deployment version="5376" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -320,8 +320,8 @@
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kGZ-0T-Pev">
<rect key="frame" x="0.0" y="0.0" width="175" height="60"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="CVV Component" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="os2-7q-87l">
<rect key="frame" x="0.0" y="0.0" width="175" height="60"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Security Code Component" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="os2-7q-87l">
<rect key="frame" x="8" y="8" width="159" height="44"/>
<fontDescription key="fontDescription" name="HelveticaNeue-Bold" family="Helvetica Neue" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
Expand All @@ -340,12 +340,12 @@
<constraints>
<constraint firstItem="x3h-d8-bIl" firstAttribute="leading" secondItem="kGZ-0T-Pev" secondAttribute="leading" id="0CF-E7-4eD"/>
<constraint firstItem="x3h-d8-bIl" firstAttribute="top" secondItem="kGZ-0T-Pev" secondAttribute="top" id="5I5-xl-s1k"/>
<constraint firstItem="os2-7q-87l" firstAttribute="top" secondItem="kGZ-0T-Pev" secondAttribute="top" id="6gt-2g-rlG"/>
<constraint firstItem="os2-7q-87l" firstAttribute="leading" secondItem="kGZ-0T-Pev" secondAttribute="leading" id="80R-lB-YcQ"/>
<constraint firstAttribute="bottom" secondItem="os2-7q-87l" secondAttribute="bottom" id="AU5-pA-h8A"/>
<constraint firstItem="os2-7q-87l" firstAttribute="top" secondItem="kGZ-0T-Pev" secondAttribute="top" constant="8" id="6gt-2g-rlG"/>
<constraint firstItem="os2-7q-87l" firstAttribute="leading" secondItem="kGZ-0T-Pev" secondAttribute="leading" constant="8" id="80R-lB-YcQ"/>
<constraint firstAttribute="bottom" secondItem="os2-7q-87l" secondAttribute="bottom" constant="8" id="AU5-pA-h8A"/>
<constraint firstAttribute="bottom" secondItem="x3h-d8-bIl" secondAttribute="bottom" id="SHS-hn-JIW"/>
<constraint firstAttribute="trailing" secondItem="x3h-d8-bIl" secondAttribute="trailing" id="YNr-oG-Pt1"/>
<constraint firstAttribute="trailing" secondItem="os2-7q-87l" secondAttribute="trailing" id="mQH-i3-clK"/>
<constraint firstAttribute="trailing" secondItem="os2-7q-87l" secondAttribute="trailing" constant="8" id="mQH-i3-clK"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadiusV">
Expand Down Expand Up @@ -574,6 +574,7 @@
<connections>
<outlet property="defaultButton" destination="npI-wS-PHN" id="RZO-Tf-AdO"/>
<outlet property="scrollView" destination="yAX-V1-VAD" id="678-IM-Fpd"/>
<outlet property="securityCodeComponentButton" destination="x3h-d8-bIl" id="RXb-Dg-azD"/>
<outlet property="theme1Button" destination="Vy0-I7-Zjz" id="aqu-YN-W1n"/>
<outlet property="threeDSURLTextField" destination="nvN-3Z-pAr" id="frP-Bh-MKg"/>
</connections>
Expand Down Expand Up @@ -608,6 +609,7 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2E4-Rg-0ur" customClass="SecurityCodeComponent" customModule="Frames">
<rect key="frame" x="0.0" y="0.0" width="242" height="50"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<accessibility key="accessibilityConfiguration" identifier="DefaultSecurityCodeComponent"/>
</view>
<button opaque="NO" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="LGn-ND-Fe3">
<rect key="frame" x="258" y="8" width="100" height="34.333333333333336"/>
Expand Down Expand Up @@ -636,6 +638,7 @@
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="lrd-VP-5SD" customClass="SecurityCodeComponent" customModule="Frames">
<rect key="frame" x="0.0" y="0.0" width="242" height="50"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<accessibility key="accessibilityConfiguration" identifier="CustomSecurityCodeComponent"/>
</view>
<button opaque="NO" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="YBC-QF-Joq">
<rect key="frame" x="258" y="8" width="100" height="34.333333333333336"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class HomeViewController: UIViewController {
@IBOutlet private weak var threeDSURLTextField: UITextField!
@IBOutlet private weak var defaultButton: UIButton!
@IBOutlet private weak var theme1Button: UIButton!

@IBOutlet weak var securityCodeComponentButton: UIButton!

private var notificationCenter: NotificationCenter = .default
private lazy var checkoutAPIService = Frames.CheckoutAPIService(publicKey: Factory.apiKey, environment: .sandbox)

Expand All @@ -29,6 +30,7 @@ class HomeViewController: UIViewController {

defaultButton.accessibilityIdentifier = "UITestDefault"
theme1Button.accessibilityIdentifier = "UITestTheme1"
securityCodeComponentButton.accessibilityIdentifier = "UITestSecurityCode"
}

override func viewWillDisappear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ final class SecurityCodeViewController: UIViewController {
textAlignment: .natural,
textColor: .red,
tintColor: .red,
placeholder: "Enter the security code here")
placeholder: "Enter here")

configuration.cardScheme = Card.Scheme(rawValue: "AMERICAN EXPRESS")
configuration.style = style

customSecurityCodeComponent.backgroundColor = .green
customSecurityCodeComponent.layer.borderColor = UIColor.blue.cgColor
customSecurityCodeComponent.layer.borderWidth = 2
customSecurityCodeComponent.layer.cornerRadius = 8

customSecurityCodeComponent.configure(with: configuration) { [weak self] isSecurityCodeValid in
self?.customPayButton.isEnabled = isSecurityCodeValid
Expand All @@ -50,7 +51,11 @@ final class SecurityCodeViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()


defaultSecurityCodeComponent.accessibilityIdentifier = "DefaultSecurityCodeComponent"
defaultPayButton.accessibilityIdentifier = "DefaultPayButton"
customSecurityCodeComponent.accessibilityIdentifier = "CustomSecurityCodeComponent"
customPayButton.accessibilityIdentifier = "CustomPayButton"
setupNavigationBar()
}

Expand Down
Loading

0 comments on commit 0b349fd

Please sign in to comment.