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>
45 lines
No EOL
2.1 KiB
Swift
45 lines
No EOL
2.1 KiB
Swift
import XCTest
|
|
@testable import TVAnarchyCore
|
|
|
|
final class AppLocalAPITests: XCTestCase {
|
|
func testListCachedFilesFindsVideos() throws {
|
|
let tmp = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
|
.appendingPathComponent("offline-\(UUID().uuidString)", isDirectory: true)
|
|
try FileManager.default.createDirectory(at: tmp, withIntermediateDirectories: true)
|
|
defer { try? FileManager.default.removeItem(at: tmp) }
|
|
let f = tmp.appendingPathComponent("show").appendingPathComponent("ep1.mkv")
|
|
try FileManager.default.createDirectory(at: f.deletingLastPathComponent(), withIntermediateDirectories: true)
|
|
try Data([0x00]).write(to: f)
|
|
|
|
var policy = OfflineCachePolicy.defaults
|
|
policy.cacheDir = tmp.path
|
|
let files = AppLocalAPI.listCachedFiles(policy: policy)
|
|
XCTAssertEqual(files.count, 1)
|
|
XCTAssertEqual(files[0].name, "ep1.mkv")
|
|
}
|
|
|
|
func testHTTPParserParsesGet() {
|
|
let raw = "GET /offline/status HTTP/1.1\r\nHost: localhost\r\n\r\n"
|
|
let req = HTTPParser.parse(Data(raw.utf8))
|
|
XCTAssertEqual(req?.method, "GET")
|
|
XCTAssertEqual(req?.path, "/offline/status")
|
|
}
|
|
|
|
func testHTTPParserParsesPatchWithBody() {
|
|
let body = #"{"episodesAhead":2}"#
|
|
let raw = "PATCH /devices/plum-vlc/offline-policy HTTP/1.1\r\nContent-Length: \(body.utf8.count)\r\n\r\n\(body)"
|
|
let req = HTTPParser.parse(Data(raw.utf8))
|
|
XCTAssertEqual(req?.method, "PATCH")
|
|
XCTAssertEqual(req?.path, "/devices/plum-vlc/offline-policy")
|
|
XCTAssertEqual(String(data: req?.body ?? Data(), encoding: .utf8), body)
|
|
}
|
|
|
|
func testHTTPParserParsesSettingsPatch() {
|
|
let body = #"{"hoverPreviews":true}"#
|
|
let raw = "PATCH /settings HTTP/1.1\r\nContent-Length: \(body.utf8.count)\r\n\r\n\(body)"
|
|
let req = HTTPParser.parse(Data(raw.utf8))
|
|
XCTAssertEqual(req?.method, "PATCH")
|
|
XCTAssertEqual(req?.path, "/settings")
|
|
XCTAssertEqual(String(data: req?.body ?? Data(), encoding: .utf8), body)
|
|
}
|
|
} |