swift-snapshot-testing icon indicating copy to clipboard operation
swift-snapshot-testing copied to clipboard

Not possible to have device agnostic screenshots with iPad AND iPhone

Open haemi opened this issue 3 years ago • 1 comments

I would like to test my view on both, an iPad and iPhone. Let's assume a very simple view:

struct SimpleView: View {
    var body: some View {
        if UIDevice.current.userInterfaceIdiom == .pad {
            Text("iPad")
        } else {
            Text("iPhone")
        }
    }
}

which is tested like the following

assertSnapshot(matching: SimpleView(), as: .image(layout: .device(config: .iPhoneX)))
assertSnapshot(matching: SimpleView(), as: .image(layout: .device(config: .iPadMini(.landscape))))

Then it depends on the simulator that setup... when I set it to iPad, both snapshots are taken with "iPad" - and the same for iPhone.

It would be great if it's possible to have it in a way that the two snapshots read "iPhone" and "iPad".

haemi avatar Feb 02 '22 16:02 haemi

@haemi I believe better practice is to operate on SizeClasses rather than device type. https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/

mpawlo avatar Feb 11 '22 10:02 mpawlo