-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathFBSnapshotTestCaseDemoTests.m
More file actions
96 lines (78 loc) · 3.74 KB
/
FBSnapshotTestCaseDemoTests.m
File metadata and controls
96 lines (78 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (c) 2017-2018, Uber Technologies, Inc.
* Copyright (c) 2013-2018, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
#import <FBSnapshotTestCase/FBSnapshotTestCase.h>
@interface FBSnapshotTestCaseDemoTests : FBSnapshotTestCase
@end
@implementation FBSnapshotTestCaseDemoTests
- (void)setUp
{
[super setUp];
// Flip this to YES to record images in the reference image directory.
// You need to do this the first time you create a test and whenever you change the snapshotted views.
// Tests running in record mode will always fail so that you know that you have to do something here before you commit.
self.recordMode = NO;
}
- (void)testViewSnapshot
{
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
redView.backgroundColor = [UIColor redColor];
FBSnapshotVerifyView(redView, nil);
FBSnapshotVerifyLayer(redView.layer, nil);
}
/// Disabled due to incompatibility with github actions runner simulator?
- (void)_testViewSnapshotWithVisualEffects
{
if ([UIVisualEffect class]) {
UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 40)];
redView.backgroundColor = [UIColor redColor];
visualEffectView.frame = CGRectMake(0, 0, 40, 40);
UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
parentView.backgroundColor = [UIColor whiteColor];
[parentView addSubview:redView];
[parentView addSubview:visualEffectView];
self.usesDrawViewHierarchyInRect = YES;
FBSnapshotVerifyViewWithPixelOptions(parentView, nil, FBSnapshotTestCaseDefaultSuffixes(), 0.09, 0); // lowest perPixelTolerance for iPhone X is 0.04, but for iPhone 7 is 0.09
}
}
- (void)testViewSnapshotWithUIAppearance
{
[[UISwitch appearance] setOnTintColor:[UIColor blueColor]];
[[UISwitch appearance] setThumbTintColor:[UIColor lightGrayColor]];
UISwitch *control = [[UISwitch alloc] init];
control.on = YES;
self.usesDrawViewHierarchyInRect = YES;
FBSnapshotVerifyViewWithPixelOptions(control, nil, FBSnapshotTestCaseDefaultSuffixes(), 0.65, 0);
}
- (void)testViewSnapshotWithUIAppearanceResizing
{
[[UIButton appearance] setContentEdgeInsets:UIEdgeInsetsMake(15, 15, 15, 15)];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:@"Click me!" forState:UIControlStateNormal];
button.translatesAutoresizingMaskIntoConstraints = NO;
[button addConstraint:[NSLayoutConstraint constraintWithItem:button
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:0
constant:65]];
[button sizeToFit];
self.usesDrawViewHierarchyInRect = YES;
FBSnapshotVerifyViewWithPixelOptions(button, nil, FBSnapshotTestCaseDefaultSuffixes(), 0.25, 0);
}
- (void)testViewSnapshotWithDifferentBackgroundColorPerArchitecture
{
UIColor *color = FBSnapshotTestCaseIs64Bit() ? [UIColor magentaColor] : [UIColor cyanColor];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
view.backgroundColor = color;
FBSnapshotVerifyView(view, nil);
}
@end