Skip to content

Commit

Permalink
Test image scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
lunij committed Jun 14, 2024
1 parent 6bd1fbc commit 15a8741
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Tests/SnapshotTestingTests/SnapshotTestingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,18 @@ final class SnapshotTestingTests: XCTestCase {
let firstLine = message?.split(whereSeparator: \.isNewline).first

Check failure on line 1133 in Tests/SnapshotTestingTests/SnapshotTestingTests.swift

View workflow job for this annotation

GitHub Actions / iOS 16.4 (Xcode 14.3.1)

type of expression is ambiguous without more context

Check failure on line 1133 in Tests/SnapshotTestingTests/SnapshotTestingTests.swift

View workflow job for this annotation

GitHub Actions / macOS 13 (Xcode 14.3.1)

type of expression is ambiguous without more context
XCTAssertEqual(firstLine, "[\(platform)] Snapshot size (123.0, 123.0) is unequal to expected size (100.0, 100.0)")
}

func testSnapshotUnscaledByDefault() throws {
let size = CGSize(width: 100, height: 100)
let view = TestView(size: size)
view.backgroundColor = .cyan
assertSnapshot(of: view, as: .image)
let url = URL(fileURLWithPath: String(#file), isDirectory: false)
.deletingLastPathComponent()
.appendingPathComponent("__Snapshots__/SnapshotTestingTests/testSnapshotUnscaledByDefault.1.png")
let image = try XCTUnwrap(XImage(contentsOf: url))
XCTAssertEqual(image.size, size)
}
#endif

#if os(iOS)
Expand Down
31 changes: 31 additions & 0 deletions Tests/SnapshotTestingTests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,34 @@ let osVersion = ProcessInfo.processInfo.operatingSystemVersion
}
}
#endif

#if os(iOS) || os(macOS) || os(tvOS)
extension XImage {
convenience init?(contentsOf url: URL) {
#if os(iOS) || os(tvOS)
self.init(contentsOfFile: url.path)
#elseif os(macOS)
self.init(byReferencing: url)
#endif
}
}
#endif

class TestView: XView {
#if os(macOS)
var backgroundColor: NSColor? {
get {
guard let cgColor = layer?.backgroundColor else { return nil }
return NSColor(cgColor: cgColor)
}
set {
wantsLayer = true
layer?.backgroundColor = newValue?.cgColor
}
}
#endif

convenience init(size: CGSize) {
self.init(frame: .init(origin: .zero, size: size))
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 15a8741

Please sign in to comment.