Skip to content

Commit c6283a5

Browse files
committed
mock ui tests
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
1 parent 43bb828 commit c6283a5

29 files changed

+2480
-70
lines changed

App/KasetApp.swift

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,47 @@ struct KasetApp: App {
5454
let auth = AuthService()
5555
let webkit = WebKitManager.shared
5656
let player = PlayerService()
57-
let client = YTMusicClient(authService: auth, webKitManager: webkit)
57+
58+
// Use mock client in UI test mode, real client otherwise
59+
let realClient = YTMusicClient(authService: auth, webKitManager: webkit)
60+
let client: YTMusicClientProtocol = if UITestConfig.isUITestMode {
61+
MockUITestYTMusicClient()
62+
} else {
63+
realClient
64+
}
5865

5966
// Wire up dependencies
6067
player.setYTMusicClient(client)
6168

6269
_authService = State(initialValue: auth)
6370
_webKitManager = State(initialValue: webkit)
6471
_playerService = State(initialValue: player)
65-
_ytMusicClient = State(initialValue: client)
72+
_ytMusicClient = State(initialValue: UITestConfig.isUITestMode ? nil : realClient)
6673
_notificationService = State(initialValue: NotificationService(playerService: player))
74+
75+
if UITestConfig.isUITestMode {
76+
DiagnosticsLogger.ui.info("App launched in UI Test mode")
77+
}
6778
}
6879

6980
var body: some Scene {
7081
WindowGroup {
71-
MainWindow(navigationSelection: $navigationSelection)
72-
.environment(authService)
73-
.environment(webKitManager)
74-
.environment(playerService)
75-
.environment(\.searchFocusTrigger, $searchFocusTrigger)
76-
.environment(\.navigationSelection, $navigationSelection)
77-
.task {
78-
// Check if user is already logged in from previous session
79-
await authService.checkLoginStatus()
80-
}
82+
// Skip UI during unit tests to prevent window spam
83+
if UITestConfig.isRunningUnitTests && !UITestConfig.isUITestMode {
84+
Color.clear
85+
.frame(width: 1, height: 1)
86+
} else {
87+
MainWindow(navigationSelection: $navigationSelection)
88+
.environment(authService)
89+
.environment(webKitManager)
90+
.environment(playerService)
91+
.environment(\.searchFocusTrigger, $searchFocusTrigger)
92+
.environment(\.navigationSelection, $navigationSelection)
93+
.task {
94+
// Check if user is already logged in from previous session
95+
await authService.checkLoginStatus()
96+
}
97+
}
8198
}
8299
.commands {
83100
// App commands

Core/Models/SearchSuggestion.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Foundation
2+
3+
/// Represents a search suggestion from YouTube Music autocomplete.
4+
struct SearchSuggestion: Identifiable, Hashable, Sendable {
5+
/// Unique identifier for the suggestion.
6+
let id: String
7+
8+
/// The suggested search query text.
9+
let query: String
10+
11+
/// Creates a suggestion with auto-generated ID.
12+
init(query: String) {
13+
id = UUID().uuidString
14+
self.query = query
15+
}
16+
17+
/// Creates a suggestion with explicit ID.
18+
init(id: String, query: String) {
19+
self.id = id
20+
self.query = query
21+
}
22+
}

0 commit comments

Comments
 (0)