Created
January 18, 2019 19:29
-
-
Save quantcon/d15fedbf96cb08b6e4159b72372df465 to your computer and use it in GitHub Desktop.
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
import XCTest | |
import SnapshotTesting | |
class ImageProcessorSingleImageTests: XCTestCase { | |
func test1920x1280() { | |
let imageNameSets = [ | |
["1920x1280-1"], | |
["1280x1920-1"] | |
] | |
let paperSizes: [PaperSize] = [ | |
.fourBySix, | |
.fourBySixStrips, | |
.fiveBySeven, | |
.fiveBySevenStrips | |
] | |
for imageNames in imageNameSets { | |
for paperSize in paperSizes { | |
self.testPrint(imageNames, paperSize) | |
} | |
} | |
} | |
func testPrint(_ imageNames: [String], _ paperSize: PaperSize) { | |
let testID = String(format: "%@.%@", | |
imageNames.reduce("") { return $0.appending($1) }, | |
paperSize.description | |
) | |
let item = self.item(using: imageNames) | |
let expect = self.expect | |
self.processor.makePrintImage(forItem: item, withPaperSize: paperSize) { | |
(image) in | |
assertSnapshot(matching: image, as: .dump, named: testID) | |
if let image = image { | |
assertSnapshot(matching: image, as: .image, named: testID) | |
} else { | |
XCTAssert(false) | |
} | |
expect.fulfill() | |
} | |
wait(for: [expect], timeout: 1.0) | |
} | |
} | |
extension XCTestCase { | |
func item(using imageNames: [String] = []) -> FoboItem { | |
var item = ImageItem() | |
item.originals = imageNames.map { Overlay(name: $0, assetID: AssetID($0)) } | |
return item | |
} | |
open var expect: XCTestExpectation { | |
return XCTestExpectation(description: "Deliver result") | |
} | |
} | |
extension AssetStorage { | |
public static var mock: AssetStorage { | |
var once = AssetStorage() | |
once.assetsForIDs = { | |
assetIDs in | |
return assetIDs.map { PhotosAsset($0) } | |
} | |
once.requestImage = { | |
asset, targetSize, contentMode, options, completion in | |
completion(UIImage.testBundle(asset.localIdentifier), [:]) | |
return 0 | |
} | |
once.requestAVAsset = { | |
asset, options, completion in | |
return 0 | |
} | |
once.findOrCreateAlbum = { | |
albumName in | |
return nil | |
} | |
once.findAlbum = { | |
albumName in | |
return nil | |
} | |
return once | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment