-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding snapshot test with localisation testing (#12)
* Initial commit for adding snapshot test * Add Snapshots for happy and sad paths * Clean test file and make it readable * updating project.yml * adding test plan * edited test plan * new test plan added * testplan updated * updating command for test plan * new screenshots * adding old commit details * PR comments * PR comments * Update README.md --------- Co-authored-by: George Nyakundi <[email protected]> Co-authored-by: tibor-is-back <[email protected]>
- Loading branch information
1 parent
7c9c938
commit b3acab1
Showing
22 changed files
with
863 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"configurations" : [ | ||
{ | ||
"id" : "A4DFB22F-BBF3-44AB-80FC-C8EB3CF1C6E8", | ||
"name" : "English", | ||
"options" : { | ||
"environmentVariableEntries" : [ | ||
{ | ||
"key" : "TestPlanLanguage", | ||
"value" : "en" | ||
} | ||
], | ||
"language" : "en" | ||
} | ||
}, | ||
{ | ||
"id" : "5386E73E-FD0E-4777-8EA3-18AD2E3B1E4E", | ||
"name" : "Arabic", | ||
"options" : { | ||
"environmentVariableEntries" : [ | ||
{ | ||
"key" : "TestPlanLanguage", | ||
"value" : "ar" | ||
} | ||
], | ||
"language" : "IDELaunchSchemeLanguageRightToLeftLayoutDirection" | ||
} | ||
} | ||
], | ||
"defaultOptions" : { | ||
"testTimeoutsEnabled" : true | ||
}, | ||
"testTargets" : [ | ||
{ | ||
"target" : { | ||
"containerPath" : "container:ios-golden-sample-app.xcodeproj", | ||
"identifier" : "6BD16231F79DDFCBA9FB4B98", | ||
"name" : "SnapshotTests" | ||
} | ||
} | ||
], | ||
"version" : 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import XCTest | ||
import SnapshotTesting | ||
import Resolver | ||
@testable import GoldenAccountsUseCase | ||
@testable import AccountsJourney | ||
import AccessControlClient3Gen2 | ||
import ArrangementsClient2Gen2 | ||
import Backbase | ||
|
||
class AccountDetailsScreenSnapshotTests: XCTestCase { | ||
|
||
private var simulatorsForTestConfiguration: [Simulator] { | ||
guard let language = ProcessInfo.processInfo.environment["TestPlanLanguage"] else { fatalError("Missing environment variable from test plan")} | ||
print("language from config: \(language)") | ||
if language == "en" { | ||
return Simulator.leftToRightWithDarkMode | ||
} else { | ||
return Simulator.rightToLeftLightMode | ||
} | ||
} | ||
|
||
func testSuggestionsHappyPath() { | ||
|
||
Resolver.register { AccountsJourney.Configuration() } | ||
|
||
let viewModel = AccountDetailsViewModel() | ||
// Register the Mock | ||
Resolver.register { MockAccountDetailsUseCase() as AccountDetailsUseCase } | ||
|
||
let viewController = AccountDetailsViewController(viewModel: viewModel, arrangementId: "") | ||
|
||
// fire the event that fetches account details | ||
viewController.viewModel.onEvent(.getAccountDetails("")) | ||
|
||
let result = verifyViewSnapshot(with: viewController.view, testCases: simulatorsForTestConfiguration) | ||
XCTAssertTrue(result.isEmpty, "Failed in \(#function) snapshot test") | ||
} | ||
|
||
func testSuggestionsSadPath() { | ||
|
||
Resolver.register { AccountsJourney.Configuration() } | ||
|
||
let viewModel = AccountDetailsViewModel() | ||
// Register the Mock | ||
Resolver.register { MockAccountDetailsUseCase(shouldReturnError: true) as AccountDetailsUseCase } | ||
|
||
let viewController = AccountDetailsViewController(viewModel: viewModel, arrangementId: "") | ||
|
||
// fire the event that fetches account details | ||
viewController.viewModel.onEvent(.getAccountDetails("")) | ||
|
||
let result = verifyViewSnapshot(with: viewController.view, testCases: simulatorsForTestConfiguration) | ||
XCTAssertTrue(result.isEmpty, "Failed in \(#function) snapshot test") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Copyright © 2020 Backbase R&D B.V. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension Bundle { | ||
static var snapshot: Bundle? { | ||
return Bundle(for: BundleToken.self) | ||
} | ||
} | ||
|
||
private final class BundleToken {} | ||
|
||
extension Bundle { | ||
/// Helper function to return contents of a file in data format | ||
/// - Parameter path: path of the file | ||
/// - Returns: data format of the contents | ||
static func data(from path: String) -> Data { | ||
guard let filePath = Bundle(for: AccountDetailsScreenSnapshotTests.self).path(forResource: path, ofType: nil) else { | ||
fatalError("Failed to find file \(path)") | ||
} | ||
let fileUrl = URL(fileURLWithPath: filePath) | ||
do { | ||
let data = try Data(contentsOf: fileUrl, options: .uncached) | ||
return data | ||
} catch { | ||
fatalError("Failed to find file \(path)") | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
Tests/SnapshotTests/Extensions/SnapshotTesting+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// Created by Backbase on 7.12.2022. | ||
// | ||
|
||
import SnapshotTesting | ||
import UIKit | ||
|
||
extension UITraitCollection { | ||
|
||
static func getTraitCollection(_ orientation: ViewImageConfig.Orientation, | ||
_ layoutDirection: UITraitEnvironmentLayoutDirection, | ||
_ userInterfaceStyle: UIUserInterfaceStyle) -> UITraitCollection { | ||
let base: [UITraitCollection] = [ | ||
.init(forceTouchCapability: .available), | ||
.init(layoutDirection: layoutDirection), | ||
.init(preferredContentSizeCategory: .medium), | ||
.init(userInterfaceIdiom: .phone), | ||
.init(userInterfaceStyle: userInterfaceStyle) | ||
] | ||
|
||
switch orientation { | ||
case .landscape: | ||
return .init( | ||
traitsFrom: base + [ | ||
.init(horizontalSizeClass: .compact), | ||
.init(verticalSizeClass: .compact) | ||
] | ||
) | ||
case .portrait: | ||
return .init( | ||
traitsFrom: base + [ | ||
.init(horizontalSizeClass: .compact), | ||
.init(verticalSizeClass: .regular) | ||
] | ||
) | ||
} | ||
} | ||
} | ||
|
||
|
||
extension ViewImageConfig.Orientation: CustomStringConvertible { | ||
/// Description used for assembling the file name of a reference snapshot | ||
public var description: String { | ||
switch self { | ||
case .landscape: return "landscape" | ||
case .portrait: return "portrait" | ||
} | ||
} | ||
} | ||
|
||
extension UIUserInterfaceStyle: CustomStringConvertible { | ||
/// Description used for assembling the file name of a reference snapshot | ||
public var description: String { | ||
switch self { | ||
case .light: return "light" | ||
case .dark: return "dark" | ||
case .unspecified: return "unspecifiedInterfaceStyle" | ||
@unknown default: return "unknownInterfaceStyle" | ||
} | ||
} | ||
} | ||
|
||
extension UITraitEnvironmentLayoutDirection: CustomStringConvertible { | ||
/// Description used for assembling the file name of a reference snapshot | ||
public var description: String { | ||
switch self { | ||
case .leftToRight: return "LTR" | ||
case .rightToLeft: return "RTL" | ||
case .unspecified: return "unspecifiedLayoutDirection" | ||
@unknown default: return "unknownLayoutDirection" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// UIColor+DesignSystem.swift | ||
// BackbaseDesignSystemSnapshotTests | ||
// | ||
// Created by Backbase R&D B.V. on 09/02/2023. | ||
// Copyright © 2023 Backbase R&D B.V. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import BackbaseDesignSystem | ||
|
||
extension UIColor { | ||
|
||
static var designSystemColors: DesignSystem.Colors { | ||
DesignSystem.shared.colors | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Created by Backbase on 8.12.2022. | ||
// | ||
|
||
import UIKit | ||
import BackbaseDesignSystem | ||
|
||
extension UIView { | ||
|
||
func setSizeConstraints(size: CGSize) -> UIView { | ||
translatesAutoresizingMaskIntoConstraints = false | ||
|
||
NSLayoutConstraint.activate([ | ||
widthAnchor.constraint(equalToConstant: size.width), | ||
heightAnchor.constraint(equalToConstant: size.height) | ||
]) | ||
return self | ||
} | ||
|
||
func containerCenterAligned(size: CGSize = CGSize(width: 200, height: 100), | ||
backgroundColor: UIColor = DesignSystem.shared.colors.surfaceSecondary.default) -> UIView { | ||
translatesAutoresizingMaskIntoConstraints = false | ||
let view = containerView(size: size, backgroundColor: backgroundColor) | ||
NSLayoutConstraint.activate([ | ||
centerXAnchor.constraint(equalTo: view.centerXAnchor), | ||
centerYAnchor.constraint(equalTo: view.centerYAnchor) | ||
]) | ||
return view | ||
} | ||
|
||
func containerCornerAttached(size: CGSize = CGSize(width: 200, height: 100), | ||
backgroundColor: UIColor = DesignSystem.shared.colors.surfaceSecondary.default) -> UIView { | ||
translatesAutoresizingMaskIntoConstraints = false | ||
let view = containerView(size: size, backgroundColor: backgroundColor) | ||
NSLayoutConstraint.activate([ | ||
topAnchor.constraint(equalTo: view.topAnchor, constant: 16), | ||
bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -16), | ||
leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16), | ||
trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16) | ||
]) | ||
return view | ||
} | ||
|
||
private func containerView(size: CGSize, backgroundColor: UIColor) -> UIView { | ||
let containerView = UIView(frame: .init(origin: .zero, size: size)) | ||
containerView.backgroundColor = backgroundColor | ||
containerView.translatesAutoresizingMaskIntoConstraints = false | ||
containerView.layer.cornerRadius = 8.0 | ||
containerView.addSubview(self) | ||
return containerView | ||
} | ||
} |
Oops, something went wrong.