[337] Set up Snapshot Testing (#350)
- snapshot package added - welcome snapshot taken [337] Set up Snapshot Testing - iPhone 8 Plus welcome screen references [337] Set up Snapshot Testing - snapshot references removed - snapshots only recorded, no comparison [337] Set up Snapshot Testing - isRecording removed [337] Set up Snapshot Testing - iPhone 8 Plus, iOS 15.4 screenshots [337] Set up Snapshot Testing - lowering the precision to 0.999 [337] Set up Snapshot Testing - attempts to get it pass the test [337] Set up Snapshot Testing - frame set up [337] Set up Snapshot Testing - resized image [337] Set up Snapshot Testing - many different snapshot tests [337] Set up Snapshot Testing - low precision test [337] Set up Snapshot Testing - updated pngs [337] Set up Snapshot Testing - another set of pngs [337] Set up Snapshot Testing - precision 0.99 [337] Set up Snapshot Testing - XCTAttachments [337] Set up Snapshot Testing - typo fixed [337] Set up Snapshot Testing - reference images [337] Set up Snapshot Testing - no precision set [337] Set up Snapshot Testing - screenshot names added - precision so low it passes all the time [337] Set up Snapshot Testing (350) - cleanup [337] Set up Snapshot Testing (350) - removed snapshot library completely [337] Set up Snapshot Testing (350) - code simplification and cleanup [337] Set up Snapshot Testing (350) - adding attachments refactored to simplify the code even more [337] Set up Snapshot Testing (350) - last simplification to wrap both light and dark under the hood [337] Set up Snapshot Testing (350) - addAttachments method to follow the same XCTestCase terminology [337] Set up Snapshot Testing (350) - attachments name fix
This commit is contained in:
parent
901ca6c2ab
commit
d7c651b522
|
@ -20,7 +20,6 @@
|
|||
0D4E7A0D26B364180058B01E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0D4E7A0C26B364180058B01E /* Assets.xcassets */; };
|
||||
0D4E7A1026B364180058B01E /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0D4E7A0F26B364180058B01E /* Preview Assets.xcassets */; };
|
||||
0D4E7A1B26B364180058B01E /* secantTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D4E7A1A26B364180058B01E /* secantTests.swift */; };
|
||||
0D4E7A2626B364180058B01E /* secantUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D4E7A2526B364180058B01E /* secantUITests.swift */; };
|
||||
0D535FDE271F4214009A9E3E /* Rubik-Italic-VariableFont_wght.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0D535FDC271F4214009A9E3E /* Rubik-Italic-VariableFont_wght.ttf */; };
|
||||
0D535FDF271F4214009A9E3E /* Rubik-VariableFont_wght.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 0D535FDD271F4214009A9E3E /* Rubik-VariableFont_wght.ttf */; };
|
||||
0D535FE2271F9476009A9E3E /* EnumeratedChip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D535FE1271F9476009A9E3E /* EnumeratedChip.swift */; };
|
||||
|
@ -110,6 +109,8 @@
|
|||
9E39114B2848EEB90073DD9A /* ZCashSDKEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E3911452848EEB90073DD9A /* ZCashSDKEnvironment.swift */; };
|
||||
9E39114C2848EEB90073DD9A /* DatabaseFiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E3911462848EEB90073DD9A /* DatabaseFiles.swift */; };
|
||||
9E39114D2848EEB90073DD9A /* WalletStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E3911472848EEB90073DD9A /* WalletStorage.swift */; };
|
||||
9E39115E284E3E350073DD9A /* secantUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D4E7A2526B364180058B01E /* secantUITests.swift */; };
|
||||
9E391165284E3EEA0073DD9A /* WelcomeSnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E391164284E3EEA0073DD9A /* WelcomeSnapshotTests.swift */; };
|
||||
9E4DC6E027C409A100E657F4 /* NeumorphicDesignModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E4DC6DF27C409A100E657F4 /* NeumorphicDesignModifier.swift */; };
|
||||
9E4DC6E227C4C6B700E657F4 /* SecantButtonStyles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E4DC6E127C4C6B700E657F4 /* SecantButtonStyles.swift */; };
|
||||
9E5BF63F2819542C00BA3F17 /* TransactionHistoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E5BF63E2819542C00BA3F17 /* TransactionHistoryTests.swift */; };
|
||||
|
@ -135,6 +136,7 @@
|
|||
9E7FE0F628327F6F00C374E8 /* ScanUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E7FE0F528327F6F00C374E8 /* ScanUIView.swift */; };
|
||||
9E7FE0F92832824C00C374E8 /* QRCodeScanView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E7FE0F82832824C00C374E8 /* QRCodeScanView.swift */; };
|
||||
9E87ADF128363DE400122FCC /* WrappedAudioServices.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E87ADF028363DE400122FCC /* WrappedAudioServices.swift */; };
|
||||
9E92AF0828530EBF007367AD /* View+UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E92AF0728530EBF007367AD /* View+UIImage.swift */; };
|
||||
9EAFEB822805793200199FC9 /* AppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EAFEB812805793200199FC9 /* AppTests.swift */; };
|
||||
9EAFEB84280597B700199FC9 /* WrappedSecItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EAFEB83280597B700199FC9 /* WrappedSecItem.swift */; };
|
||||
9EAFEB862805A23100199FC9 /* WrappedSecItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EAFEB852805A23100199FC9 /* WrappedSecItemTests.swift */; };
|
||||
|
@ -305,6 +307,7 @@
|
|||
9E3911452848EEB90073DD9A /* ZCashSDKEnvironment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZCashSDKEnvironment.swift; sourceTree = "<group>"; };
|
||||
9E3911462848EEB90073DD9A /* DatabaseFiles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseFiles.swift; sourceTree = "<group>"; };
|
||||
9E3911472848EEB90073DD9A /* WalletStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletStorage.swift; sourceTree = "<group>"; };
|
||||
9E391164284E3EEA0073DD9A /* WelcomeSnapshotTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeSnapshotTests.swift; sourceTree = "<group>"; };
|
||||
9E4DC6DF27C409A100E657F4 /* NeumorphicDesignModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NeumorphicDesignModifier.swift; sourceTree = "<group>"; };
|
||||
9E4DC6E127C4C6B700E657F4 /* SecantButtonStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecantButtonStyles.swift; sourceTree = "<group>"; };
|
||||
9E5BF63B2818305D00BA3F17 /* TransactionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionState.swift; sourceTree = "<group>"; };
|
||||
|
@ -330,6 +333,7 @@
|
|||
9E7FE0F528327F6F00C374E8 /* ScanUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanUIView.swift; sourceTree = "<group>"; };
|
||||
9E7FE0F82832824C00C374E8 /* QRCodeScanView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeScanView.swift; sourceTree = "<group>"; };
|
||||
9E87ADF028363DE400122FCC /* WrappedAudioServices.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappedAudioServices.swift; sourceTree = "<group>"; };
|
||||
9E92AF0728530EBF007367AD /* View+UIImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+UIImage.swift"; sourceTree = "<group>"; };
|
||||
9EAFEB812805793200199FC9 /* AppTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppTests.swift; sourceTree = "<group>"; };
|
||||
9EAFEB83280597B700199FC9 /* WrappedSecItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappedSecItem.swift; sourceTree = "<group>"; };
|
||||
9EAFEB852805A23100199FC9 /* WrappedSecItemTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappedSecItemTests.swift; sourceTree = "<group>"; };
|
||||
|
@ -488,6 +492,7 @@
|
|||
0D4E7A1926B364180058B01E /* secantTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9E391162284E3ECF0073DD9A /* SnapshotTests */,
|
||||
9E3911372848AD3A0073DD9A /* HomeTests */,
|
||||
9E391122283E4C970073DD9A /* ImportWalletTests */,
|
||||
9E01F8262833CD84000EFC57 /* ScanTests */,
|
||||
|
@ -778,6 +783,23 @@
|
|||
path = HomeTests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9E391162284E3ECF0073DD9A /* SnapshotTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9E391163284E3EDE0073DD9A /* WelcomeSnapshotTests */,
|
||||
9E92AF0728530EBF007367AD /* View+UIImage.swift */,
|
||||
);
|
||||
path = SnapshotTests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9E391163284E3EDE0073DD9A /* WelcomeSnapshotTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9E391164284E3EEA0073DD9A /* WelcomeSnapshotTests.swift */,
|
||||
);
|
||||
path = WelcomeSnapshotTests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9E5BF63D281953F900BA3F17 /* TransactionHistoryTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -1127,6 +1149,8 @@
|
|||
0D4E7A1826B364180058B01E /* PBXTargetDependency */,
|
||||
);
|
||||
name = secantTests;
|
||||
packageProductDependencies = (
|
||||
);
|
||||
productName = secantTests;
|
||||
productReference = 0D4E7A1626B364180058B01E /* secantTests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
|
@ -1427,6 +1451,7 @@
|
|||
9EDDEAA22829610D00B4100C /* CurrencySelectionTests.swift in Sources */,
|
||||
9E01F8282833CDA0000EFC57 /* ScanTests.swift in Sources */,
|
||||
9EDDEAA42829610D00B4100C /* TransactionAddressInputTests.swift in Sources */,
|
||||
9E92AF0828530EBF007367AD /* View+UIImage.swift in Sources */,
|
||||
6654C7442715A4AC00901167 /* OnboardingStoreTests.swift in Sources */,
|
||||
9E39112E283F91600073DD9A /* ZatoshiTests.swift in Sources */,
|
||||
9EDDEAA32829610D00B4100C /* TransactionAmountInputTests.swift in Sources */,
|
||||
|
@ -1437,6 +1462,7 @@
|
|||
9E391132284644580073DD9A /* AppInitializationTests.swift in Sources */,
|
||||
9E391124283E4CAC0073DD9A /* ImportWalletTests.swift in Sources */,
|
||||
9E5BF63F2819542C00BA3F17 /* TransactionHistoryTests.swift in Sources */,
|
||||
9E391165284E3EEA0073DD9A /* WelcomeSnapshotTests.swift in Sources */,
|
||||
0D4E7A1B26B364180058B01E /* secantTests.swift in Sources */,
|
||||
0DFE93E6272CB6F7000FCCA5 /* RecoveryPhraseValidationTests.swift in Sources */,
|
||||
9E3911392848AD500073DD9A /* HomeTests.swift in Sources */,
|
||||
|
@ -1450,7 +1476,7 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
0D4E7A2626B364180058B01E /* secantUITests.swift in Sources */,
|
||||
9E39115E284E3E350073DD9A /* secantUITests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// View+UIImage.swift
|
||||
// secantTests
|
||||
//
|
||||
// Created by Lukáš Korba on 10.06.2022.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import SwiftUI
|
||||
|
||||
extension XCTestCase {
|
||||
func addAttachments<Content: View>(name: String = #function, _ view: Content) {
|
||||
view.attachments(name).forEach { add($0) }
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func attachments(_ name: String) -> [XCTAttachment] {
|
||||
[attachment(name), attachment(name, .dark)]
|
||||
}
|
||||
|
||||
func attachment(_ fileName: String, _ colorScheme: ColorScheme = .light) -> XCTAttachment {
|
||||
let colorSchemePostfix = colorScheme == .light ? "\(fileName)_light" : "\(fileName)_dark"
|
||||
let trimTest = colorSchemePostfix.replacingOccurrences(of: "test", with: "")
|
||||
let imageName = trimTest.replacingOccurrences(of: "()", with: "")
|
||||
let rect = UIScreen.main.bounds
|
||||
|
||||
let viewHelper = self
|
||||
.environment(\.colorScheme, colorScheme)
|
||||
.frame(width: rect.width, height: rect.height, alignment: .center)
|
||||
|
||||
guard let image = viewHelper.asUiImage() else {
|
||||
return XCTAttachment(string: "\(imageName)_SnapshotFailed")
|
||||
}
|
||||
|
||||
let attachment = XCTAttachment(image: image)
|
||||
attachment.name = imageName
|
||||
attachment.lifetime = .keepAlways
|
||||
return attachment
|
||||
}
|
||||
|
||||
func asUiImage() -> UIImage? {
|
||||
let controller = UIHostingController(rootView: self)
|
||||
|
||||
if let view = controller.view {
|
||||
let contentSize = view.intrinsicContentSize
|
||||
view.bounds = CGRect(origin: .zero, size: contentSize)
|
||||
view.backgroundColor = .clear
|
||||
|
||||
let renderer = UIGraphicsImageRenderer(size: contentSize)
|
||||
let uiImage = renderer.image { _ in
|
||||
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
|
||||
}
|
||||
return uiImage
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// WelcomeSnapshotTests.swift
|
||||
// secantTests
|
||||
//
|
||||
// Created by Lukáš Korba on 06.06.2022.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import secant_testnet
|
||||
import ComposableArchitecture
|
||||
|
||||
class WelcomeSnapshotTests: XCTestCase {
|
||||
func testWelcomeSnapshot() throws {
|
||||
let store = Store(
|
||||
initialState: .placeholder,
|
||||
reducer: WelcomeReducer.default,
|
||||
environment: WelcomeEnvironment()
|
||||
)
|
||||
|
||||
addAttachments(WelcomeView(store: store))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue