Live Activities, nudging, unit tests
This commit is contained in:
@@ -82,9 +82,9 @@ struct FavoriteURICollectionTests {
|
||||
@Test("Collects URIs of items marked as favorite")
|
||||
func collectsFavoriteURIs() throws {
|
||||
let items: [MAMediaItem] = try [
|
||||
"""{"uri":"spotify://1","name":"A","favorite":true}""",
|
||||
"""{"uri":"spotify://2","name":"B","favorite":false}""",
|
||||
"""{"uri":"spotify://3","name":"C","favorite":true}""",
|
||||
#"{"uri":"spotify://1","name":"A","favorite":true}"#,
|
||||
#"{"uri":"spotify://2","name":"B","favorite":false}"#,
|
||||
#"{"uri":"spotify://3","name":"C","favorite":true}"#,
|
||||
].map {
|
||||
try JSONDecoder().decode(MAMediaItem.self, from: Data($0.utf8))
|
||||
}
|
||||
@@ -96,8 +96,8 @@ struct FavoriteURICollectionTests {
|
||||
@Test("Returns empty set when no items are favorite")
|
||||
func emptyWhenNoFavorites() throws {
|
||||
let items: [MAMediaItem] = try [
|
||||
"""{"uri":"x://1","name":"A","favorite":false}""",
|
||||
"""{"uri":"x://2","name":"B"}""",
|
||||
#"{"uri":"x://1","name":"A","favorite":false}"#,
|
||||
#"{"uri":"x://2","name":"B"}"#,
|
||||
].map {
|
||||
try JSONDecoder().decode(MAMediaItem.self, from: Data($0.utf8))
|
||||
}
|
||||
@@ -108,7 +108,7 @@ struct FavoriteURICollectionTests {
|
||||
|
||||
@Test("isFavorite check on MALibraryManager respects favoriteURIs set")
|
||||
func isFavoriteCheck() {
|
||||
let manager = MALibraryManager()
|
||||
let manager = MALibraryManager(service: nil)
|
||||
// Initially no favorites
|
||||
#expect(manager.isFavorite(uri: "spotify://track/1") == false)
|
||||
}
|
||||
@@ -121,22 +121,22 @@ struct LibraryManagerInitialStateTests {
|
||||
|
||||
@Test("Artists collection starts empty")
|
||||
func artistsStartEmpty() {
|
||||
#expect(MALibraryManager().artists.isEmpty)
|
||||
#expect(MALibraryManager(service: nil).artists.isEmpty)
|
||||
}
|
||||
|
||||
@Test("Albums collection starts empty")
|
||||
func albumsStartEmpty() {
|
||||
#expect(MALibraryManager().albums.isEmpty)
|
||||
#expect(MALibraryManager(service: nil).albums.isEmpty)
|
||||
}
|
||||
|
||||
@Test("Playlists collection starts empty")
|
||||
func playlistsStartEmpty() {
|
||||
#expect(MALibraryManager().playlists.isEmpty)
|
||||
#expect(MALibraryManager(service: nil).playlists.isEmpty)
|
||||
}
|
||||
|
||||
@Test("Loading flags start as false")
|
||||
func loadingFlagsStartFalse() {
|
||||
let m = MALibraryManager()
|
||||
let m = MALibraryManager(service: nil)
|
||||
#expect(m.isLoadingArtists == false)
|
||||
#expect(m.isLoadingAlbums == false)
|
||||
#expect(m.isLoadingPlaylists == false)
|
||||
@@ -144,6 +144,6 @@ struct LibraryManagerInitialStateTests {
|
||||
|
||||
@Test("favoriteURIs starts empty")
|
||||
func favoriteURIsStartEmpty() {
|
||||
#expect(MALibraryManager().favoriteURIs.isEmpty)
|
||||
#expect(MALibraryManager(service: nil).favoriteURIs.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ struct MAPlayerDecodingTests {
|
||||
#expect(player.available == true)
|
||||
}
|
||||
|
||||
@Test("Defaults powered and available when missing")
|
||||
@Test("powered defaults to false when missing; available defaults to true when missing")
|
||||
func defaultsMissingBooleans() throws {
|
||||
let json = """
|
||||
{"player_id": "x", "name": "Test", "state": "idle"}
|
||||
"""
|
||||
let player = try decode(json)
|
||||
#expect(player.powered == false)
|
||||
#expect(player.available == false)
|
||||
#expect(player.available == true)
|
||||
}
|
||||
|
||||
@Test("Unknown state falls back to idle")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Testing
|
||||
import Foundation
|
||||
import UIKit
|
||||
@testable import Mobile_Music_Assistant
|
||||
|
||||
// MARK: - Live Activity Player Selection
|
||||
|
||||
@@ -5,6 +5,7 @@ import Foundation
|
||||
// MARK: - MAStoreManager Nudge Logic
|
||||
|
||||
@Suite("MAStoreManager – Nudge Logic")
|
||||
@MainActor
|
||||
struct MAStoreManagerNudgeTests {
|
||||
|
||||
// Use isolated UserDefaults to avoid polluting real app state
|
||||
|
||||
@@ -148,9 +148,9 @@ struct AnyCodableTests {
|
||||
|
||||
@Test("Dictionary decodes keys correctly")
|
||||
func dictRoundTrip() throws {
|
||||
let dict = AnyCodable(["key": AnyCodable("value")])
|
||||
let encoded = try JSONEncoder().encode(dict)
|
||||
let decoded = try JSONDecoder().decode(AnyCodable.self, from: encoded)
|
||||
// Build the AnyCodable from raw JSON to avoid double-wrapping issues
|
||||
let json = #"{"key":"value"}"#
|
||||
let decoded = try JSONDecoder().decode(AnyCodable.self, from: Data(json.utf8))
|
||||
let map = try decoded.decode(as: [String: AnyCodable].self)
|
||||
#expect(try map["key"]?.decode(as: String.self) == "value")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user