changeset 93:529feb1fc8d5

Added UI Tests for capture screenshots
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Tue, 03 Aug 2021 12:33:32 +0100
parents 8386dbf80047
children 507ed393a72c
files Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Simoleon.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme Simoleon/Conversion.swift Simoleon/Favorites.swift Simoleon/Helpers/ConversionBox.swift Simoleon/Helpers/CurrencySelector.swift Simoleon/Helpers/FavoriteButton.swift Simoleon/Settings.swift SimoleonUITests/SimoleonUITests.swift
diffstat 9 files changed, 74 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/Simoleon.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme	Tue Aug 03 10:10:14 2021 +0100
+++ b/Simoleon.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme	Tue Aug 03 12:33:32 2021 +0100
@@ -22,7 +22,7 @@
          </BuildActionEntry>
          <BuildActionEntry
             buildForTesting = "YES"
-            buildForRunning = "NO"
+            buildForRunning = "YES"
             buildForProfiling = "NO"
             buildForArchiving = "NO"
             buildForAnalyzing = "NO">
--- a/Simoleon/Conversion.swift	Tue Aug 03 10:10:14 2021 +0100
+++ b/Simoleon/Conversion.swift	Tue Aug 03 12:33:32 2021 +0100
@@ -33,6 +33,7 @@
                                     .padding(.horizontal)
                             )
                     }
+                    .accessibilityIdentifier("CurrencySelector")
                     
                     FavoriteButton(currencyPair: currencyPair)
                 }
--- a/Simoleon/Favorites.swift	Tue Aug 03 10:10:14 2021 +0100
+++ b/Simoleon/Favorites.swift	Tue Aug 03 12:33:32 2021 +0100
@@ -46,6 +46,7 @@
         .if(UIDevice.current.userInterfaceIdiom == .phone) { content in
             NavigationView { content }
         }
+        .onAppear(perform: generateFavoritesToScreenshots)
     }
     
     private func removeFromFavorites(offsets: IndexSet) {
@@ -60,11 +61,34 @@
             }
         }
     }
+    
+    private func generateFavoritesToScreenshots() {
+        #if DEBUG
+        if favorite.isEmpty {
+            let favoriteCurrencies = [
+                "EUR/USD", "BTC/USD", "USD/HKD", "USD/JPY", "AUD/USD", "XAU/GBP", "DASH/ETH", "EUR/USD",
+                "XAG/CAD", "XRP/RUB"
+            ]
+            
+            for favoriteCurrency in favoriteCurrencies {
+                let favorite = Favorite(context: viewContext)
+                favorite.currencyPair = favoriteCurrency
+                
+                do {
+                    try viewContext.save()
+                } catch {
+                    let nsError = error as NSError
+                    fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
+                }
+            }
+        }
+        #endif
+    }
 }
 
 struct Favorites_Previews: PreviewProvider {
     static var previews: some View {
         Favorites()
-//            .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
+            .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
     }
 }
--- a/Simoleon/Helpers/ConversionBox.swift	Tue Aug 03 10:10:14 2021 +0100
+++ b/Simoleon/Helpers/ConversionBox.swift	Tue Aug 03 12:33:32 2021 +0100
@@ -41,6 +41,7 @@
                 .font(Font.title.weight(.semibold))
                 .lineLimit(1)
                 .padding(.bottom, 10)
+                .accessibilityIdentifier("ConversionTextfield")
             }
             
             Divider()
--- a/Simoleon/Helpers/CurrencySelector.swift	Tue Aug 03 10:10:14 2021 +0100
+++ b/Simoleon/Helpers/CurrencySelector.swift	Tue Aug 03 12:33:32 2021 +0100
@@ -40,6 +40,7 @@
             VStack {
                 SearchBar(placeholder: "Search...", text: $searchCurrency)
                     .padding()
+                    .accessibilityIdentifier("SearchBar")
                 
                 if entitlementIsActive {
                     List(searchResults, id: \.self) { currencyPair in
@@ -49,6 +50,7 @@
                         }) {
                             CurrencyRow(currencyPairName: currencyPair.name)
                         }
+                        .accessibilityIdentifier("CurrencyRow")
                     }
                     .listStyle()
                 } else {
@@ -96,6 +98,9 @@
     
     // Check if user subscription is active
     private func checkEntitlement() {
+        #if DEBUG
+        entitlementIsActive = true
+        #else
         Purchases.shared.purchaserInfo { (purchaserInfo, error) in
             if purchaserInfo?.entitlements["all"]?.isActive == true {
                 entitlementIsActive = true
@@ -107,6 +112,7 @@
                 showingAlert = true
             }
         }
+        #endif
     }
 }
 extension View {
--- a/Simoleon/Helpers/FavoriteButton.swift	Tue Aug 03 10:10:14 2021 +0100
+++ b/Simoleon/Helpers/FavoriteButton.swift	Tue Aug 03 12:33:32 2021 +0100
@@ -27,6 +27,7 @@
                         .foregroundColor(Color(.systemYellow))
                 )
         }
+        .accessibilityIdentifier("FavoriteButton")
     }
     
     /*
--- a/Simoleon/Settings.swift	Tue Aug 03 10:10:14 2021 +0100
+++ b/Simoleon/Settings.swift	Tue Aug 03 12:33:32 2021 +0100
@@ -150,6 +150,9 @@
     
     // Check if user subscription is active
     private func checkEntitlement() {
+        #if DEBUG
+        entitlementIsActive = true
+        #else
         Purchases.shared.purchaserInfo { (purchaserInfo, error) in
             if purchaserInfo?.entitlements["all"]?.isActive == true {
                 entitlementIsActive = true
@@ -161,6 +164,7 @@
                 showingAlert = true
             }
         }
+        #endif
     }
 }
 
--- a/SimoleonUITests/SimoleonUITests.swift	Tue Aug 03 10:10:14 2021 +0100
+++ b/SimoleonUITests/SimoleonUITests.swift	Tue Aug 03 12:33:32 2021 +0100
@@ -11,6 +11,7 @@
 
     override func setUpWithError() throws {
         // Put setup code here. This method is called before the invocation of each test method in the class.
+        
 
         // In UI tests it is usually best to stop immediately when a failure occurs.
         continueAfterFailure = false
@@ -22,13 +23,44 @@
         // Put teardown code here. This method is called after the invocation of each test method in the class.
     }
     
-    // MARK: - Tab View
-    func testExample() throws {
+    // MARK: - Automate screenshots
+    func testScreenshots() throws {
         let app = XCUIApplication()
         setupSnapshot(app)
+        
+        // MARK: - Launch
         app.launch()
-        snapshot("01LoginScreen")
+        snapshot("0-Launch")
         
+        // MARK: - Remove 100 from conversion textfield and type custom amount
+        let conversionTextfield = app.textFields["ConversionTextfield"]
+        conversionTextfield.tap()
+        for _ in (0..<4) {
+            conversionTextfield.typeText(XCUIKeyboardKey.delete.rawValue)
+        }
+        conversionTextfield.typeText("1470.10")
+        snapshot("1-Convert")
+
+        // Remove custom amount and type again 1000
+        for _ in (0..<7) {
+            conversionTextfield.typeText(XCUIKeyboardKey.delete.rawValue)
+        }
+        conversionTextfield.typeText("1000\n")
+
+        // MARK: - Open currency selector, search BTC, and select first row
+        app.buttons["CurrencySelector"].tap()
+        snapshot("2-CurrencySelector")
+
+        let searchBar = app.textFields["SearchBar"]
+        searchBar.tap()
+        searchBar.typeText("BTC")
+        app.buttons["CurrencyRow"].firstMatch.tap()
+        snapshot("3-Bitcoin")
+
+        // MARK: - Go to favorites
+        conversionTextfield.typeText("\n")  // Dismiss keyboard
+        app.tabBars.buttons.element(boundBy: 1).tap()
+        snapshot("4-Favorites")
     }
 
     func testLaunchPerformance() throws {