Skip to content

Commit

Permalink
Implement test cases for ProductView
Browse files Browse the repository at this point in the history
- Create the shared `FlareMock` package
- Implement snapshot tests
- Implement unit tests
  • Loading branch information
ns-vasilev committed Mar 2, 2024
1 parent 0a84939 commit ffa5df3
Show file tree
Hide file tree
Showing 57 changed files with 1,048 additions and 221 deletions.
1 change: 0 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
--enable redundantPattern
--enable redundantRawValues
--enable redundantReturn
--enable redundantSelf
--enable redundantVoidReturnType
--enable semicolons
--enable sortImports
Expand Down
130 changes: 0 additions & 130 deletions .swiftpm/xcode/xcshareddata/xcschemes/Flare-Package.xcscheme

This file was deleted.

15 changes: 13 additions & 2 deletions .swiftpm/xcode/xcshareddata/xcschemes/FlareUI.xcscheme
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1520"
version = "1.7">
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand All @@ -26,7 +26,18 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "FlareUI"
BuildableName = "FlareUI"
BlueprintName = "FlareUI"
ReferencedContainer = "container:">
</BuildableReference>
</CodeCoverageTargets>
<Testables>
<TestableReference
skipped = "NO">
Expand Down
18 changes: 18 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "e7b77228b34057041374ebef00c0fd7739d71a2b",
"version" : "1.15.3"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
}
}
],
"version" : 2
Expand Down
10 changes: 9 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ let package = Package(
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.1.0"),
.package(url: "https://github.com/space-code/log.git", .upToNextMajor(from: "1.1.0")),
.package(url: "https://github.com/space-code/atomic.git", .upToNextMajor(from: "1.0.0")),
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
from: "1.15.3"
),
],
targets: [
.target(
Expand All @@ -37,17 +41,21 @@ let package = Package(
swiftSettings: [visionOSSetting]
),
.target(name: "FlareUI", dependencies: ["Flare"]),
.target(name: "FlareMock", dependencies: ["Flare"]),
.testTarget(
name: "FlareTests",
dependencies: [
"Flare",
"FlareMock",
.product(name: "TestConcurrency", package: "concurrency"),
]
),
.testTarget(
name: "FlareUITests",
dependencies: [
"Flare",
"FlareUI",
"FlareMock",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),
]
Expand Down
10 changes: 9 additions & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ let package = Package(
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.1.0"),
.package(url: "https://github.com/space-code/log.git", .upToNextMajor(from: "1.1.0")),
.package(url: "https://github.com/space-code/atomic.git", .upToNextMajor(from: "1.0.0")),
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
from: "1.15.3"
),
],
targets: [
.target(
Expand All @@ -33,17 +37,21 @@ let package = Package(
resources: [.process("Resources")]
),
.target(name: "FlareUI", dependencies: ["Flare"]),
.target(name: "FlareMock", dependencies: ["Flare"]),
.testTarget(
name: "FlareTests",
dependencies: [
"Flare",
"FlareMock",
.product(name: "TestConcurrency", package: "concurrency"),
]
),
.testTarget(
name: "FlareUITests",
dependencies: [
"Flare",
"FlareUI",
"FlareMock",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),
]
Expand Down
10 changes: 9 additions & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ let package = Package(
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.1.0"),
.package(url: "https://github.com/space-code/log.git", .upToNextMajor(from: "1.1.0")),
.package(url: "https://github.com/space-code/atomic.git", .upToNextMajor(from: "1.0.0")),
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
from: "1.15.3"
),
],
targets: [
.target(
Expand All @@ -33,17 +37,21 @@ let package = Package(
resources: [.process("Resources")]
),
.target(name: "FlareUI", dependencies: ["Flare"]),
.target(name: "FlareMock", dependencies: ["Flare"]),
.testTarget(
name: "FlareTests",
dependencies: [
"Flare",
"FlareMock",
.product(name: "TestConcurrency", package: "concurrency"),
]
),
.testTarget(
name: "FlareUITests",
dependencies: [
"Flare",
"FlareUI",
"FlareMock",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// Flare
// Copyright © 2023 Space Code. All rights reserved.
// Copyright © 2024 Space Code. All rights reserved.
//

import Flare
import StoreKit

extension StoreProduct {
public extension StoreProduct {
static func fake(skProduct: SKProduct = ProductMock()) -> StoreProduct {
StoreProduct(skProduct: skProduct)
}
Expand Down
13 changes: 13 additions & 0 deletions Sources/FlareMock/Fakes/StoreTransaction+Fake.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Flare
// Copyright © 2024 Space Code. All rights reserved.
//

@testable import Flare
import Foundation

public extension StoreTransaction {
static func fake() -> StoreTransaction {
StoreTransaction(paymentTransaction: PaymentTransaction(PaymentTransactionMock()))
}
}
48 changes: 48 additions & 0 deletions Sources/FlareMock/Mocks/PaymentTransactionMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Flare
// Copyright © 2024 Space Code. All rights reserved.
//

import StoreKit

public final class PaymentTransactionMock: SKPaymentTransaction {
override public init() {}

public var invokedTransactionState = false
public var invokedTransactionStateCount = 0
public var stubbedTransactionState: SKPaymentTransactionState!

override public var transactionState: SKPaymentTransactionState {
stubbedTransactionState
}

public var invokedTransactionIndentifier = false
public var invokedTransactionIndentifierCount = 0
public var stubbedTransactionIndentifier: String?

override public var transactionIdentifier: String? {
invokedTransactionIndentifier = true
invokedTransactionStateCount += 1
return stubbedTransactionIndentifier
}

public var invokedPayment = false
public var invokedPaymentCount = 0
public var stubbedPayment: SKPayment!

override public var payment: SKPayment {
invokedPayment = true
invokedPaymentCount += 1
return stubbedPayment
}

public var stubbedOriginal: SKPaymentTransaction?
override public var original: SKPaymentTransaction? {
stubbedOriginal
}

public var stubbedError: Error?
override public var error: Error? {
stubbedError
}
}
Loading

0 comments on commit ffa5df3

Please sign in to comment.