tv-anarchy/Tests/TVAnarchyCoreTests/SearchMatcherTests.swift
Natalie 4a2ceb9781 feat(offline): inline star-to-keep and trash-to-cull on cache rows
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>
2026-06-30 00:12:41 -04:00

64 lines
No EOL
3 KiB
Swift

import XCTest
@testable import TVAnarchyCore
final class SearchMatcherTests: XCTestCase {
func testTitlesOverlapBroadCity() {
XCTAssertTrue(SearchMatcher.titlesOverlap(
"Broad City S05 (360p re-webrip)",
"Broad City S00 (2010-) + S01-S04 (2014-)"
))
XCTAssertFalse(SearchMatcher.titlesOverlap(
"Broad City S05 (360p re-webrip)",
"South Park S26"
))
}
func testMisplacedBroadCityInSouthPark() {
let row = try! JSONDecoder().decode(TorrentRow.self, from: Data(#"""
{"id":1,"name":"Broad City S05 (360p re-webrip)","percentDone":1,"status":6,
"doneDate":1,"addedDate":1,"haveValid":1,"sizeWhenDone":1,"rateDownload":0,
"rateUpload":0,"uploadRatio":0,"eta":-1,
"downloadDir":"/bigdisk/_/media/cartoons/South Park [x265 repair]"}
"""#.utf8))
XCTAssertTrue(SearchMatcher.isMisplaced(row))
}
func testNotMisplacedWhenTitleInPath() {
let row = try! JSONDecoder().decode(TorrentRow.self, from: Data(#"""
{"id":2,"name":"Broad City S05 (360p re-webrip)","percentDone":1,"status":6,
"doneDate":1,"addedDate":1,"haveValid":1,"sizeWhenDone":1,"rateDownload":0,
"rateUpload":0,"uploadRatio":0,"eta":-1,
"downloadDir":"/bigdisk/_/media/tv/Broad City"}
"""#.utf8))
XCTAssertFalse(SearchMatcher.isMisplaced(row))
}
func testFiltersOverlappingTorrentResult() throws {
let result = try JSONDecoder().decode(TorrentResult.self, from: Data(#"""
{"filename":"Broad City Season 5 - threesixtyp","source":"thepiratebay.org",
"size":"860 MB","seeders":29,"leechers":1,"magnet":"magnet:?x"}
"""#.utf8))
let transfer = try! JSONDecoder().decode(TorrentRow.self, from: Data(#"""
{"id":3,"name":"Broad City S05 (360p re-webrip)","percentDone":1,"status":6,
"doneDate":1,"addedDate":1,"haveValid":1,"sizeWhenDone":1,"rateDownload":0,
"rateUpload":0,"uploadRatio":0,"eta":-1}
"""#.utf8))
XCTAssertTrue(SearchMatcher.overlapsTransfer(result, transfers: [transfer]))
}
func testIndexedFoldersBackfill() {
let key = "tv-anarchy.indexed-content-folders"
let prior = UserDefaults.standard.stringArray(forKey: key)
defer { UserDefaults.standard.set(prior, forKey: key) }
UserDefaults.standard.set(["/already/indexed"], forKey: key)
let row = try! JSONDecoder().decode(TorrentRow.self, from: Data(#"""
{"id":4,"name":"Show.S01","percentDone":1,"status":6,"doneDate":1,"addedDate":1,
"haveValid":1,"sizeWhenDone":1,"rateDownload":0,"rateUpload":0,"uploadRatio":0,"eta":-1,
"downloadDir":"/bigdisk/_/media/tv"}
"""#.utf8))
let unmarked = IndexedFoldersStore.unmarkedFolders(in: [row])
XCTAssertEqual(unmarked, ["/bigdisk/_/media/tv/Show.S01"])
IndexedFoldersStore.mark(unmarked)
XCTAssertTrue(IndexedFoldersStore.unmarkedFolders(in: [row]).isEmpty)
}
}