Skip to content

Commit

Permalink
Add tests, update deployment target
Browse files Browse the repository at this point in the history
  • Loading branch information
markmur committed Mar 4, 2024
1 parent 96b267f commit 8e7bd87
Show file tree
Hide file tree
Showing 16 changed files with 438 additions and 281 deletions.
313 changes: 112 additions & 201 deletions Samples/SwiftUIExample/SwiftUIExample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Shopify/mobile-buy-sdk-ios",
"state" : {
"revision" : "e6e85dcf8f9eb95baaa8336ad3d7967ea8c36ade",
"revision" : "3a6ecdce6b9e8f356078fbdc2b738ac32cd18153",
"version" : "11.3.0"
}
},
{
"identity" : "swiftlintplugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/lukepistrol/SwiftLintPlugin",
"state" : {
"revision" : "ea6d3ca895b49910f790e98e4b4ca658e0fe490e",
"version" : "0.54.0"
}
}
],
"version" : 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6A2DBC1C2B90ECBA00761222"
BuildableName = "SwiftUIExampleUITests.xctest"
BlueprintName = "SwiftUIExampleUITests"
ReferencedContainer = "container:SwiftUIExample.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "86C569CE2B15DA2D00F26028"
BuildableName = "SwiftUIExampleTests.xctest"
BlueprintName = "SwiftUIExampleTests"
ReferencedContainer = "container:SwiftUIExample.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
5 changes: 4 additions & 1 deletion Samples/SwiftUIExample/SwiftUIExample/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct RootTabView: View {
CatalogView(cartManager: cartManager, checkoutURL: $checkoutURL, cart: $cartManager.cart)
.tabItem {
SwiftUI.Image(systemName: "storefront")
.accessibilityIdentifier("catalogTabIcon")
Text("Catalog")
}

Expand All @@ -69,8 +70,10 @@ struct RootTabView: View {
}
}
}
}.tabItem {
}
.tabItem {
SwiftUI.Image(systemName: "cart")
.accessibilityIdentifier("cartTabIcon")
Text("Cart")
}
}
Expand Down
36 changes: 19 additions & 17 deletions Samples/SwiftUIExample/SwiftUIExample/CartView.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/*
MIT License
MIT License

Copyright 2023 - Present, Shopify Inc.
Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import Buy
import SwiftUI
Expand All @@ -45,6 +45,7 @@ struct CartView: View {
}, label: {
Text("Checkout")
})
.accessibilityIdentifier("checkoutButton")
.padding()
.frame(maxWidth: .infinity)
.background(Color.blue)
Expand Down Expand Up @@ -75,6 +76,7 @@ struct CartView: View {
print(error)
}
.edgesIgnoringSafeArea(.all)
.accessibility(identifier: "CheckoutSheet")
}
}
.padding(.top, 20)
Expand Down
2 changes: 2 additions & 0 deletions Samples/SwiftUIExample/SwiftUIExample/CatalogView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct CatalogView: View {
.font(.headline)
}
})
.accessibilityIdentifier("addToCartButton")
.padding()
.frame(maxWidth: 400)
.background(Color.blue)
Expand Down Expand Up @@ -131,6 +132,7 @@ struct CatalogView: View {
BadgeButton(badgeCount: Int(cartManager.cart?.totalQuantity ?? 0), action: {
isShowingCart = true
})
.accessibilityIdentifier("cartIcon")

Button(action: {
onAppear()
Expand Down
42 changes: 21 additions & 21 deletions Samples/SwiftUIExample/SwiftUIExample/ProductViewModel.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/*
MIT License
MIT License

Copyright 2023 - Present, Shopify Inc.
Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import Buy
import Combine
Expand Down Expand Up @@ -47,10 +47,10 @@ public class CartManager: ObservableObject {
func addItem(variant: GraphQL.ID, completionHandler: ((Storefront.Cart?) -> Void)?) {
performCartLinesAdd(item: variant) { result in
switch result {
case .success(let cart):
self.cart = cart
case .failure(let error):
print(error)
case .success(let cart):
self.cart = cart
case .failure(let error):
print(error)
}
completionHandler?(self.cart)
}
Expand Down
42 changes: 21 additions & 21 deletions Samples/SwiftUIExample/SwiftUIExample/StorefrontClient.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import Buy
import Foundation
Expand Down
30 changes: 30 additions & 0 deletions Samples/SwiftUIExample/SwiftUIExampleTests/AppTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import XCTest

class AppTests: XCTestCase {

var app: XCUIApplication!

override func setUp() {
super.setUp()
continueAfterFailure = false
app = XCUIApplication()
app.launch()
}

func testCheckoutSheetTitle() {
// Wait for the "Add to Cart" button to become available
let addToCartButton = app.buttons["addToCartButton"]
let exists = NSPredicate(format: "exists == true")
expectation(for: exists, evaluatedWith: addToCartButton, handler: nil)
waitForExpectations(timeout: 5, handler: nil)

// Tap the "Add to Cart" button
addToCartButton.tap()

// Find the "Checkout" title
let checkoutTitle = app.navigationBars["CheckoutSheet"]

// Check if the title exists
XCTAssertTrue(checkoutTitle.exists)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// CheckoutSheetTests.swift
// SwiftUIExample
//
// Created by Mark Murray on 29/02/2024.
//

import XCTest

final class CheckoutSheetTests: XCTestCase {

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

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launch()

// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testLaunchPerformance() throws {
if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
// This measures how long it takes to launch your application.
measure(metrics: [XCTApplicationLaunchMetric()]) {
XCUIApplication().launch()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

Loading

0 comments on commit 8e7bd87

Please sign in to comment.