Surface the existing pin (keep-from-cull) and per-file delete actions as visible inline buttons on each offline cache row instead of context-menu-only: a star toggles protection from auto-cull (and restore-if-missing), a trash culls that file early. Aligns wording/icons to the star metaphor. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
47 lines
No EOL
2.1 KiB
Swift
47 lines
No EOL
2.1 KiB
Swift
import XCTest
|
|
@testable import TVAnarchyCore
|
|
|
|
final class StreamabilityTests: XCTestCase {
|
|
func testStreamPolicyCapsBufferAtHalfEpisode() {
|
|
let policy = StreamPolicy(bufferSeconds: 900)
|
|
XCTAssertEqual(policy.effectiveBufferSeconds(episodeDuration: 1200), 600)
|
|
XCTAssertEqual(policy.effectiveBufferSeconds(episodeDuration: 2400), 900)
|
|
XCTAssertEqual(policy.sliderMax(episodeDuration: 1200), 600)
|
|
}
|
|
|
|
func testStreamPolicyDefaultsWhenEpisodeUnknown() {
|
|
let policy = StreamPolicy.defaults
|
|
XCTAssertEqual(policy.effectiveBufferSeconds(episodeDuration: nil), 120)
|
|
XCTAssertEqual(policy.sliderMax(episodeDuration: nil),
|
|
Int(Double(StreamPolicy.typicalEpisodeSeconds) / 2))
|
|
}
|
|
|
|
func testAssessorLevels() {
|
|
XCTAssertEqual(StreamabilityAssessor.assess(pingMs: 40, bandwidthKBps: 2000, requiredKBps: 500),
|
|
.good)
|
|
XCTAssertEqual(StreamabilityAssessor.assess(pingMs: 40, bandwidthKBps: 600, requiredKBps: 500),
|
|
.marginal)
|
|
XCTAssertEqual(StreamabilityAssessor.assess(pingMs: 40, bandwidthKBps: 200, requiredKBps: 500),
|
|
.poor)
|
|
XCTAssertEqual(StreamabilityAssessor.assess(pingMs: nil, bandwidthKBps: nil, requiredKBps: 500),
|
|
.unreachable)
|
|
}
|
|
|
|
func testRequiredKBpsFromFileSize() {
|
|
let kbps = StreamabilityAssessor.requiredKBps(bufferSeconds: 120, episodeSeconds: 1200,
|
|
fileBytes: 1_500_000_000)
|
|
// ~1.5 GiB / 20 min ≈ 1.3 MB/s
|
|
XCTAssertGreaterThan(kbps, 1000)
|
|
XCTAssertLessThan(kbps, 2000)
|
|
}
|
|
|
|
func testStreamPolicyDecodesWithDefaults() throws {
|
|
let json = #"""
|
|
{"devices":[{"id":"plum-vlc","name":"Plum","kind":"vlc","type":"laptop",
|
|
"services":{"stream":true},
|
|
"streamPolicy":{"bufferSeconds":180}}]}
|
|
"""#
|
|
let cfg = try JSONDecoder().decode(DevicesConfig.self, from: Data(json.utf8))
|
|
XCTAssertEqual(cfg.devices[0].resolvedStreamPolicy().bufferSeconds, 180)
|
|
}
|
|
} |