Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tinder-cfuller opened this issue Jul 27, 2023 · 1 comment

Comments

@tinder-cfuller
Copy link

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
@tinder-cfuller
Copy link
Author

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

Thank you @leohemanth!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant