diff options
Diffstat (limited to 'SoraTests')
| -rw-r--r-- | SoraTests/ViewDerivedDataTests.swift | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/SoraTests/ViewDerivedDataTests.swift b/SoraTests/ViewDerivedDataTests.swift index eb426f7..a97465d 100644 --- a/SoraTests/ViewDerivedDataTests.swift +++ b/SoraTests/ViewDerivedDataTests.swift @@ -127,6 +127,70 @@ final class ViewDerivedDataTests: XCTestCase { } } + func testSearchSuggestionsCacheIsBuiltFromItemsChanges() 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"#, + in: normalizedSource + ) + let itemsMapCount = tokenCount( + matching: #"\bcachedTags\s*=\s*items\s*\.\s*map"#, + in: normalizedSource + ) + let itemsChangeObserverCount = tokenCount( + matching: #"\.onChange\s*\(\s*of:\s*itemsCacheKey\s*\)"#, + in: normalizedSource + ) + + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + stateCacheCount, + 0, + "Search suggestions should keep preprocessed tags in view state." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + itemsMapCount, + 0, + "Search suggestions should build cached tags from items." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + itemsChangeObserverCount, + 0, + "Search suggestions should refresh cached tags only when items change." + ) + } + + func testPostDetailsImageActionsUseAsyncCachedImageLoading() throws { + let source = try loadSource(at: "Sora/Views/Post/Details/PostDetailsImageView.swift") + let normalizedSource = strippingCommentsAndStrings(from: source) + + let synchronousLoadCount = tokenCount( + matching: #"\bNSData\s*\(\s*contentsOf:"#, + in: normalizedSource + ) + let cachedLoaderCount = tokenCount( + matching: #"\bImageCacheManager\s*\.\s*shared\s*\.\s*loadImageData\s*\("#, + in: normalizedSource + ) + + // swiftlint:disable:next prefer_nimble + XCTAssertEqual( + synchronousLoadCount, + 0, + "Post details image actions should avoid synchronous NSData file or network loads." + ) + // swiftlint:disable:next prefer_nimble + XCTAssertGreaterThan( + cachedLoaderCount, + 0, + "Post details image actions should use cache-backed async image loading." + ) + } + private func referenceCount(for symbol: String, in source: String) -> Int { let totalMatches = tokenCount( matching: #"\b\#(symbol)\b"#, |