diff options
| author | Fuwn <[email protected]> | 2026-03-22 14:13:12 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-22 14:13:12 +0000 |
| commit | 9d2235cc7f75cf82fa929269e5b0ac350c67fb62 (patch) | |
| tree | beb8fe41a201d5a6a6d0435d802fc0128d5230d4 /SoraTests/ViewDerivedDataTests.swift | |
| parent | fix: restore gelbooru tag suggestions (diff) | |
| download | sora-testing-9d2235cc7f75cf82fa929269e5b0ac350c67fb62.tar.xz sora-testing-9d2235cc7f75cf82fa929269e5b0ac350c67fb62.zip | |
fix: restore tag suggestion popup updates
Diffstat (limited to 'SoraTests/ViewDerivedDataTests.swift')
| -rw-r--r-- | SoraTests/ViewDerivedDataTests.swift | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/SoraTests/ViewDerivedDataTests.swift b/SoraTests/ViewDerivedDataTests.swift index 7c6e379..3270806 100644 --- a/SoraTests/ViewDerivedDataTests.swift +++ b/SoraTests/ViewDerivedDataTests.swift @@ -129,40 +129,83 @@ final class ViewDerivedDataTests: XCTestCase { // swiftlint:disable:this type_b } } - func testSearchSuggestionsCacheIsBuiltFromItemsChanges() throws { + func testSearchSuggestionsViewDerivesCachedTagsDirectlyFromItems() throws { let source = try loadSource(at: "Sora/Views/SearchSuggestionsView.swift") let normalizedSource = strippingCommentsAndStrings(from: source) - let stateCacheCount = tokenCount( - matching: #"\@State\s+private\s+var\s+cachedTags"#, + let computedCacheCount = tokenCount( + matching: #"\bprivate\s+var\s+cachedTags\s*:\s*\[CachedTag\]"#, in: normalizedSource ) let itemsMapCount = tokenCount( - matching: #"\bcachedTags\s*=\s*items\s*\.\s*map"#, + matching: #"\bitems\s*\.\s*map\s*\{"#, + in: normalizedSource + ) + let stateCacheCount = tokenCount( + matching: #"\@State\s+private\s+var\s+cachedTags"#, in: normalizedSource ) - let itemsChangeObserverCount = tokenCount( - matching: #"\.onChange\s*\(\s*of:\s*itemsCacheKey\s*\)"#, + let appearRefreshCount = tokenCount( + matching: #"\.onAppear\s*\{"#, in: normalizedSource ) // swiftlint:disable:next prefer_nimble XCTAssertGreaterThan( - stateCacheCount, + computedCacheCount, 0, - "Search suggestions should keep preprocessed tags in view state." + "Search suggestions should derive cached tags directly from current items." ) // swiftlint:disable:next prefer_nimble XCTAssertGreaterThan( itemsMapCount, 0, - "Search suggestions should build cached tags from items." + "Search suggestions should build cached tags directly from the current items." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertEqual( + stateCacheCount, + 0, + "Search suggestions should not depend on local state to derive popup content." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertEqual( + appearRefreshCount, + 0, + "Search suggestions should not depend on view-appearance hooks to populate popup content." + ) + } + + func testSearchSuggestionsViewShowsFetchedTagsWithoutClientSideRefiltering() throws { + let source = try loadSource(at: "Sora/Views/SearchSuggestionsView.swift") + let normalizedSource = strippingCommentsAndStrings(from: source) + + let fetchedTagDirectAppendCount = tokenCount( + matching: + #"case\s+\.left:\s*guard\s+let\s+name\s*=\s*tag\.names\.first,"# + + #"\s*seenTags\.insert\(name\)\.inserted\s*else\s*\{\s*continue\s*\}"# + + #"\s*matchingTags\.append\(tag\.original\)"#, + in: normalizedSource + ) + let historyContainsFilterCount = tokenCount( + matching: + #"case\s+\.right:\s*for\s+name\s+in\s+tag\.names\s*\{"# + + #"\s*if\s+name\.contains\(matchCandidateTag\),"# + + #"\s*seenTags\.insert\(name\)\.inserted"#, + in: normalizedSource + ) + + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + fetchedTagDirectAppendCount, + 0, + "Fetched provider tag suggestions should be displayed directly once returned." ) // swiftlint:disable:next prefer_nimble XCTAssertGreaterThan( - itemsChangeObserverCount, + historyContainsFilterCount, 0, - "Search suggestions should refresh cached tags only when items change." + "Search history suggestions should continue filtering against the active tag fragment locally." ) } |