-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some extra logic for using hardcoded favionURLs as cache keys. Ad…
…d some additional unit tests.
- Loading branch information
Showing
3 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
BrowserKit/Tests/SiteImageViewTests/SiteImageModelTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import XCTest | ||
@testable import SiteImageView | ||
|
||
class SiteImageModelTests: XCTestCase { | ||
let siteURL = URL(string: "https://www.mozilla.org")! | ||
let faviconURL = URL(string: "https://www.mozilla.org/media/img/favicons/mozilla/apple-touch-icon.8cbe9c835c00.png")! | ||
|
||
func testFaviconURL_isCacheKey_whenProvidedForFavicon() async { | ||
let model = SiteImageModel(id: UUID(), imageType: .favicon, siteURL: siteURL, resourceURL: faviconURL) | ||
|
||
XCTAssertEqual(model.cacheKey, faviconURL.absoluteString) | ||
} | ||
|
||
func testShortDomain_isCacheKey_forFavicon() async { | ||
let model = SiteImageModel(id: UUID(), imageType: .favicon, siteURL: siteURL) | ||
|
||
XCTAssertEqual(model.cacheKey, siteURL.shortDomain) | ||
} | ||
|
||
func testAbsolutePath_isCacheKey_forHeroImage() async { | ||
let model = SiteImageModel(id: UUID(), imageType: .heroImage, siteURL: siteURL) | ||
|
||
XCTAssertEqual(model.cacheKey, siteURL.absoluteString) | ||
} | ||
|
||
func testShortDomain_isCacheKey_whenResourceURLProvidedForHeroImage() async { | ||
let model = SiteImageModel(id: UUID(), imageType: .heroImage, siteURL: siteURL, resourceURL: faviconURL) | ||
|
||
XCTAssertEqual(model.cacheKey, siteURL.absoluteString) | ||
} | ||
|
||
// MARK: - Test generateCacheKey | ||
|
||
func testGenerateCacheKey_returnsShortDomain_forFavicon() async { | ||
let cacheKey = SiteImageModel.generateCacheKey(siteURL: siteURL, type: .favicon) | ||
|
||
XCTAssertEqual(cacheKey, siteURL.shortDomain) | ||
} | ||
|
||
func testGenerateCacheKey_returnsAbsolutePath_forHeroImage() async { | ||
let cacheKey = SiteImageModel.generateCacheKey(siteURL: siteURL, type: .heroImage) | ||
|
||
XCTAssertEqual(cacheKey, siteURL.absoluteString) | ||
} | ||
} |