Skip to content

Commit 75ec50a

Browse files
committed
Create a new demo app
1 parent db38b20 commit 75ec50a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+361
-923
lines changed

Demo/.swiftlint.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 140 additions & 419 deletions
Large diffs are not rendered by default.

Demo/Demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

Lines changed: 0 additions & 8 deletions
This file was deleted.

Demo/Demo.xcodeproj/xcuserdata/danielsaidi.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44
<dict>
55
<key>SchemeUserState</key>
66
<dict>
7-
<key>Demo (iOS).xcscheme_^#shared#^_</key>
7+
<key>Demo.xcscheme_^#shared#^_</key>
88
<dict>
99
<key>orderHint</key>
1010
<integer>0</integer>
1111
</dict>
12-
<key>Demo (macOS).xcscheme_^#shared#^_</key>
13-
<dict>
14-
<key>orderHint</key>
15-
<integer>1</integer>
16-
</dict>
1712
</dict>
1813
</dict>
1914
</plist>

Demo/Demo/ContentView.swift

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//
2+
// ContentView.swift
3+
// Demo
4+
//
5+
// Created by Daniel Saidi on 2020-12-07.
6+
// Copyright © 2020 Daniel Saidi. All rights reserved.
7+
//
8+
9+
import MockingKit
10+
import SwiftUI
11+
12+
struct ContentView: View {
13+
14+
private let mock = TestMockable()
15+
private let matchCount = 5
16+
17+
@State private var hasCalled = false
18+
@State private var hasCalledCount = 0
19+
@State private var hasCalledMatch = false
20+
@State private var hasCalledWithArgs = false
21+
@State private var hasCalledWithArgsCount = 0
22+
@State private var hasCalledWithArgsName = ""
23+
@State private var hasCalledWithArgsAge = 0
24+
25+
var body: some View {
26+
NavigationStack {
27+
DemoList("Mockable") {
28+
Section("About") {
29+
Text("This demo uses a test mock to show how to trigger funcs and inspect the resulting calls.")
30+
}
31+
32+
Section("doStuff") {
33+
listItem("Has been called?", "\(hasCalled ? "Yes" : "No")")
34+
listItem("Call count", "\(hasCalledCount) times")
35+
listItem("Has called \(matchCount) times?", "\(hasCalledMatch ? "Yes" : "No")")
36+
Button(action: doStuff) {
37+
Text("Trigger").frame(maxWidth: .infinity)
38+
}
39+
}
40+
41+
42+
Section("doStuffWithArguments") {
43+
listItem("Has been called?", "\(hasCalledWithArgs ? "Yes" : "No")")
44+
listItem("Call Count", "\(hasCalledWithArgsCount) times")
45+
if hasCalledWithArgs {
46+
listItem("Last name:", "\(hasCalledWithArgsName)")
47+
listItem("Last age:", "\(hasCalledWithArgsAge)")
48+
}
49+
Button(action: doStuffWithArgs) {
50+
Text("Trigger").frame(maxWidth: .infinity)
51+
}
52+
}
53+
}
54+
.buttonStyle(.borderedProminent)
55+
}
56+
}
57+
}
58+
59+
private extension ContentView {
60+
61+
func listItem(_ title: String, _ text: String) -> some View {
62+
LabeledContent(title, value: text)
63+
}
64+
}
65+
66+
private extension ContentView {
67+
68+
func doStuff() {
69+
mock.doStuff()
70+
hasCalled = mock.hasCalled(mock.doStuffRef)
71+
hasCalledCount = mock.calls(to: mock.doStuffRef).count
72+
hasCalledMatch = mock.hasCalled(mock.doStuffRef, numberOfTimes: matchCount)
73+
}
74+
75+
func doStuffWithArgs() {
76+
let name = "Member #\(Int.random(in: 1_000...9_999))"
77+
let age = Int.random(in: 18...100)
78+
mock.doStuffWithArgs(name: name, age: age)
79+
let calls = mock.calls(to: mock.doStuffWithArgsRef)
80+
hasCalledWithArgs = mock.hasCalled(mock.doStuffWithArgsRef)
81+
hasCalledWithArgsCount = calls.count
82+
hasCalledWithArgsName = calls.last?.arguments.0 ?? ""
83+
hasCalledWithArgsAge = calls.last?.arguments.1 ?? -1
84+
}
85+
}
86+
87+
#Preview {
88+
ContentView()
89+
}

Demo/Shared/Demo/DemoApp.swift renamed to Demo/Demo/DemoApp.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
//
22
// DemoApp.swift
3-
// Shared
3+
// Demo
44
//
5-
// Created by Daniel Saidi on 2020-12-07.
6-
// Copyright © 2020 Daniel Saidi. All rights reserved.
5+
// Created by Daniel Saidi on 2025-10-17.
76
//
87

98
import SwiftUI
109

1110
@main
1211
struct DemoApp: App {
13-
1412
var body: some Scene {
1513
WindowGroup {
1614
ContentView()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)