This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add device agnostic tests & modify snapshot window fallback
Use UIApplication.keyWindow instead of a manually-created & installed window when snapshotting a view w/o a window. This prevents keyWindow from being `nil` when generating device-agnostic reference image filenames. Accessing keyWindow is done through a category, so as to always throw an assertion if it is nil, instructing developers to make sure their tests have a host application w/ a key window.
- Loading branch information
Showing
10 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
FBSnapshotTestCase/Categories/UIApplication+StrictKeyWindow.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIApplication (StrictKeyWindow) | ||
|
||
/** | ||
@return The recdeiver's @c keyWindow. Raises an assertion if @c nil. | ||
*/ | ||
- (UIWindow *)fb_strictKeyWindow; | ||
|
||
@end |
26 changes: 26 additions & 0 deletions
26
FBSnapshotTestCase/Categories/UIApplication+StrictKeyWindow.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
#import <FBSnapshotTestCase/UIApplication+StrictKeyWindow.h> | ||
|
||
@implementation UIApplication (StrictKeyWindow) | ||
|
||
- (UIWindow *)fb_strictKeyWindow { | ||
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow; | ||
if (!keyWindow) { | ||
[NSException raise:@"FBSnapshotTestCaseNilKeyWindowException" | ||
format:@"Snapshot tests must be hosted by an application with a key window. Please ensure your test" | ||
" host sets up a key window at launch (either via storyboards or programmatically) and doesn't" | ||
" do anything to remove it while snapshot tests are running."]; | ||
} | ||
return keyWindow; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
FBSnapshotTestCaseDemo/FBSnapshotTestCaseDemoTests/FBSnapshotTestCaseDeviceAgnosticTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2013, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
|
||
#import <FBSnapshotTestCase/FBSnapshotTestCase.h> | ||
|
||
@interface FBSnapshotTestCaseDeviceAgnosticTests : FBSnapshotTestCase | ||
|
||
@end | ||
|
||
@implementation FBSnapshotTestCaseDeviceAgnosticTests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
self.deviceAgnostic = YES; | ||
self.recordMode = NO; | ||
} | ||
|
||
- (void)testSuccessfulComparisonOfDeviceAgnosticReferenceImages | ||
{ | ||
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; | ||
redView.backgroundColor = [UIColor redColor]; | ||
FBSnapshotVerifyView(redView, nil); | ||
FBSnapshotVerifyLayer(redView.layer, nil); | ||
} | ||
|
||
@end |
Binary file added
BIN
+418 Bytes
...estSuccessfulComparisonOfDeviceAgnosticReferenceImages_iPhone9_0_320x480@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+418 Bytes
...estSuccessfulComparisonOfDeviceAgnosticReferenceImages_iPhone9_0_320x480@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.