Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Support for different Size Classes #92

Closed
martnst opened this issue Jun 18, 2015 · 10 comments
Closed

Support for different Size Classes #92

martnst opened this issue Jun 18, 2015 · 10 comments
Labels

Comments

@martnst
Copy link

martnst commented Jun 18, 2015

Hey *,

I am wondering if / how it is possible to test a view in different Size Classes as we different constants and even constraints.

@nscoding
Copy link
Contributor

Hello @maremmle

How do you run your tests now? If you run them on Xcode you can pick the device you want to build and test. If you run them on you CI tool, you will need specify on what device will the test run.

One solution would be to create your own macro for these cases. For example:

NS_INLINE NSOrderedSet *FBSnapshotTestCaseCustomSuffixes(void)
{
  NSMutableOrderedSet *suffixesSet = [[NSMutableOrderedSet alloc] init];
  NSString *suffix = @"";
  if (_iPhone5_) {
    suffix = @"_iPhone5";
  } else if (_iPhone6_) {
    suffix = @"_iPhone6";
  } else if (_iPad_) {
    suffix = @"_iPad";
  } else ...
  [suffixesSet addObject:suffix];
  return [suffixesSet copy];
}

#define FBSnapshotVerifyViewCustom(view__, identifier__) \
{ \
  FBSnapshotVerifyViewWithOptions(view__, identifier__, FBSnapshotTestCaseCustomSuffixes()); \
}

Once you have your custom macro FBSnapshotVerifyViewCustom you can use it to record and test different devices. Let me know if something is not clear enough.

@martnst
Copy link
Author

martnst commented Jun 18, 2015

Hi @nscoding,

thanks for your response. I was playing around in XCode … so I used the Simulator. I picked iPhone (compact width) but it did always rendered my view in regular width. The view itself is loaded from a XIB file via NSBundle -loadNibNamed:owner:options:.

@nscoding
Copy link
Contributor

@maremmle That's an interesting problem but I haven't worked much with interface builder, can you please provide me with a sample project (with a similar load of nibs and tests) to debug this further?

@martnst
Copy link
Author

martnst commented Jun 18, 2015

Sure … I will setup one up for you within the next days.

@nscoding
Copy link
Contributor

@maremmle thank you for your time, much appreciated.

@martnst
Copy link
Author

martnst commented Jun 20, 2015

@nscoding i have pushed a sampel app here https://github.com/maremmle/ios-snapshot-test-case_size_class_sample/. The Snapshots folder contains 2 images, a screenshot of the iPhone Simulator and a Snapshot from the test. As you can see on the Simulator's one the green box should be below on compact with. On regular width it should be next to the orange box as it is on the other Snapshot.

I hope that helps. Feel free to get in touch if I can help otherwise.

@nscoding
Copy link
Contributor

Hey @maremmle

Thank you so much for this it was very helpful. It's very similar to #91 and it requires a window to load things correctly. So something like this should work for your case:

  UIView *sampleView = [[NSBundle mainBundle] loadNibNamed:@"View" owner:self options:nil].firstObject;
  UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  [window addSubview:sampleView];
  sampleView.frame = window.bounds;
  FBSnapshotVerifyView(sampleView, nil);

Can you try it?

@nscoding nscoding added the bug label Jun 20, 2015
@martnst
Copy link
Author

martnst commented Jun 22, 2015

@nscoding thanks a lot for you help. It now works.

Since you labeled it as a bug I am actually wondering if the Testcase maybe should take care of embedding the view into a window. Just a quick idea ;)

@nscoding
Copy link
Contributor

@maremmle yes maybe the framework can control this but I am not yet sure, I'll keep the issue open.

@nscoding
Copy link
Contributor

#100 is addressing this issue, I will now close the issue but please reopen if you think otherwise.

Caiopia pushed a commit to Shopify/ios-snapshot-test-case that referenced this issue Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants