pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.

Home Page:https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Left margin is not respected in view controller snapshot images on iPhone 8/SE in landscape

tinder-cfuller opened this issue · comments

Describe the bug

Left margin is not respected in view controller snapshot images on iPhone 8/SE in landscape even though the left margin is reflected in the recursive description (and respected when running the app in the simulator).

To Reproduce

Sample Project:

Sample.zip

View Controller:

class ViewController: UIViewController {

    let blueView: UIView = {
        let view = UIView()
        view.backgroundColor = .blue
        view.translatesAutoresizingMaskIntoConstraints = false
        return view
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .systemBackground
        view.addSubview(blueView)
        NSLayoutConstraint.activate([
            blueView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
            blueView.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
            blueView.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor),
            blueView.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor)
        ])
    }
}

Test:

final class SampleTests: XCTestCase {

    func testViewController() throws {
        let device: ViewImageConfig = .iPhone8(.landscape)
        let vc = ViewController()
        assertSnapshot(matching: vc, as: .recursiveDescription(on: device))
        assertSnapshot(matching: vc, as: .image(on: device))
    }
}

Recursive Description:

The left margin of 20 is reflected in the x of the frame.

<UIView; frame = (20 0; 627 375); backgroundColor = UIExtendedSRGBColorSpace 0 0 1 1; layer = <CALayer>>

Snapshot Image:

The left margin is incorrectly not respected.

testViewController 2

Expected behavior

The left margin should be correctly respected in view controller snapshot images on iPhone 8/SE in landscape.

For example, the left margin is respected when running the app in the simulator.

Simulator Screenshot:

Screenshot 2023-07-26 at 5 12 20 PM

Environment

  • swift-snapshot-testing version 1.11.1
  • Xcode 14.3.1
  • Swift 5.8
  • OS: iOS 16.4

I just tested the above ☝️ proposed fix in the sample app attached to this issue and it worked 👍

Thank you @leohemanth!