Skip to content

Commit 7d637a5

Browse files
authored
add snapshot library (#342)
1 parent 351b1d9 commit 7d637a5

File tree

6 files changed

+104
-34
lines changed

6 files changed

+104
-34
lines changed

Example/Leanplum-SDK.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
9CD04D941F8EE7E30033AB4A /* variables_with_newsfeed_response.json in Resources */ = {isa = PBXBuildFile; fileRef = 9CD04D931F8EB6190033AB4A /* variables_with_newsfeed_response.json */; };
102102
9CD04D951F8EE7E30033AB4A /* variables_with_newsfeed_response.json in Resources */ = {isa = PBXBuildFile; fileRef = 9CD04D931F8EB6190033AB4A /* variables_with_newsfeed_response.json */; };
103103
A84527FD215C3035001FA20D /* LPRequestTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A84527FC215C3035001FA20D /* LPRequestTest.m */; };
104+
A86C8CF42405E271003F5E4E /* LPAlertMessageSnapshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A86C8CF32405E271003F5E4E /* LPAlertMessageSnapshotTest.m */; };
104105
A8CB8A36227276A400E1001D /* LeanplumRequestTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A8CB8A35227276A400E1001D /* LeanplumRequestTest.m */; };
105106
A8EEA1AB20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
106107
A8EEA1AC20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
@@ -208,6 +209,7 @@
208209
9CD04D931F8EB6190033AB4A /* variables_with_newsfeed_response.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = variables_with_newsfeed_response.json; sourceTree = "<group>"; };
209210
A54ACCFCB36AE8C874708A7F /* libPods-Leanplum-SDK_Example-Leanplum-SDK_Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Leanplum-SDK_Example-Leanplum-SDK_Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
210211
A84527FC215C3035001FA20D /* LPRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPRequestTest.m; sourceTree = "<group>"; };
212+
A86C8CF32405E271003F5E4E /* LPAlertMessageSnapshotTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPAlertMessageSnapshotTest.m; sourceTree = "<group>"; };
211213
A8CB8A35227276A400E1001D /* LeanplumRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LeanplumRequestTest.m; sourceTree = "<group>"; };
212214
A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = start_with_variant_debug_info_response.json; sourceTree = "<group>"; };
213215
A8F5D58623F3483E00313C98 /* LPBaseInterstitialMessageTemplateTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPBaseInterstitialMessageTemplateTest.m; sourceTree = "<group>"; };
@@ -255,6 +257,7 @@
255257
07E5C86A1F052B7800A4B092 /* Classes */ = {
256258
isa = PBXGroup;
257259
children = (
260+
A86C8CF22405E23E003F5E4E /* Snapshot Tests */,
258261
07E5C86F1F052B7800A4B092 /* Extensions */,
259262
07E5C8841F052B7800A4B092 /* Utilities */,
260263
07E5C86B1F052B7800A4B092 /* LPActionManagerTest.m */,
@@ -472,6 +475,14 @@
472475
name = "Podspec Metadata";
473476
sourceTree = "<group>";
474477
};
478+
A86C8CF22405E23E003F5E4E /* Snapshot Tests */ = {
479+
isa = PBXGroup;
480+
children = (
481+
A86C8CF32405E271003F5E4E /* LPAlertMessageSnapshotTest.m */,
482+
);
483+
path = "Snapshot Tests";
484+
sourceTree = "<group>";
485+
};
475486
B5CCCA2A1D74B64D005ADEE1 /* Leanplum-tvOS-SDK_Example */ = {
476487
isa = PBXGroup;
477488
children = (
@@ -733,12 +744,14 @@
733744
"${BUILT_PRODUCTS_DIR}/Leanplum-iOS-SDK/Leanplum.framework",
734745
"${BUILT_PRODUCTS_DIR}/OCMock/OCMock.framework",
735746
"${BUILT_PRODUCTS_DIR}/OHHTTPStubs/OHHTTPStubs.framework",
747+
"${BUILT_PRODUCTS_DIR}/iOSSnapshotTestCase/FBSnapshotTestCase.framework",
736748
);
737749
name = "[CP] Embed Pods Frameworks";
738750
outputPaths = (
739751
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Leanplum.framework",
740752
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMock.framework",
741753
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OHHTTPStubs.framework",
754+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBSnapshotTestCase.framework",
742755
);
743756
runOnlyForDeploymentPostprocessing = 0;
744757
shellPath = /bin/sh;
@@ -773,6 +786,7 @@
773786
A8F5D58A23F34AD400313C98 /* LPBasePushMessageTemplateTest.m in Sources */,
774787
07E5C8B11F052B7800A4B092 /* LPNetworkEngine+Category.m in Sources */,
775788
07E5C8B61F052B7800A4B092 /* LeanplumTest.m in Sources */,
789+
A86C8CF42405E271003F5E4E /* LPAlertMessageSnapshotTest.m in Sources */,
776790
65E189C6216BDB82005E6B93 /* LPRequestFactoryTest.m in Sources */,
777791
07E5C8AD1F052B7800A4B092 /* LPEventDataManagerTest.m in Sources */,
778792
65E189C421643631005E6B93 /* LPRequestSenderTest.m in Sources */,

Example/Leanplum-SDK.xcodeproj/xcshareddata/xcschemes/Leanplum-SDK-Example.xcscheme

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
codeCoverageEnabled = "YES"
30-
shouldUseLaunchSchemeArgsEnv = "YES">
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES">
31+
<MacroExpansion>
32+
<BuildableReference
33+
BuildableIdentifier = "primary"
34+
BlueprintIdentifier = "6003F589195388D20070C39A"
35+
BuildableName = "Leanplum-SDK_Example.app"
36+
BlueprintName = "Leanplum-SDK_Example"
37+
ReferencedContainer = "container:Leanplum-SDK.xcodeproj">
38+
</BuildableReference>
39+
</MacroExpansion>
3140
<Testables>
3241
<TestableReference
3342
skipped = "NO">
@@ -40,17 +49,6 @@
4049
</BuildableReference>
4150
</TestableReference>
4251
</Testables>
43-
<MacroExpansion>
44-
<BuildableReference
45-
BuildableIdentifier = "primary"
46-
BlueprintIdentifier = "6003F589195388D20070C39A"
47-
BuildableName = "Leanplum-SDK_Example.app"
48-
BlueprintName = "Leanplum-SDK_Example"
49-
ReferencedContainer = "container:Leanplum-SDK.xcodeproj">
50-
</BuildableReference>
51-
</MacroExpansion>
52-
<AdditionalOptions>
53-
</AdditionalOptions>
5452
</TestAction>
5553
<LaunchAction
5654
buildConfiguration = "Debug"
@@ -72,8 +70,18 @@
7270
ReferencedContainer = "container:Leanplum-SDK.xcodeproj">
7371
</BuildableReference>
7472
</BuildableProductRunnable>
75-
<AdditionalOptions>
76-
</AdditionalOptions>
73+
<EnvironmentVariables>
74+
<EnvironmentVariable
75+
key = "FB_REFERENCE_IMAGE_DIR"
76+
value = "$(SOURCE_ROOT)/Tests/ReferenceImages"
77+
isEnabled = "YES">
78+
</EnvironmentVariable>
79+
<EnvironmentVariable
80+
key = "IMAGE_DIFF_DIR"
81+
value = "$(SOURCE_ROOT)/Tests/FailureDiffs"
82+
isEnabled = "YES">
83+
</EnvironmentVariable>
84+
</EnvironmentVariables>
7785
</LaunchAction>
7886
<ProfileAction
7987
buildConfiguration = "Release"

Example/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ target 'Leanplum-SDK_Example' do
2121
pod 'Leanplum-iOS-SDK', :path => '../'
2222
pod 'OCMock', '~> 3.3.1'
2323
pod 'OHHTTPStubs', '~> 9.0.0'
24+
pod 'iOSSnapshotTestCase/Core'
2425
end
2526
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// LPAlertMessageSnapshotTest.m
3+
// Leanplum-SDK_Tests
4+
//
5+
// Created by Mayank Sanganeria on 2/25/20.
6+
// Copyright © 2020 Leanplum. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import <FBSnapshotTestCase/FBSnapshotTestCase.h>
11+
#import <Leanplum/LPAlertMessageTemplate.h>
12+
13+
@interface LPAlertMessageTemplate()
14+
15+
-(UIViewController *)viewControllerWithContext:(LPActionContext *)context;
16+
17+
@end
18+
19+
@interface LPActionContext(UnitTest)
20+
21+
+ (LPActionContext *)actionContextWithName:(NSString *)name
22+
args:(NSDictionary *)args
23+
messageId:(NSString *)messageId;
24+
25+
@end
26+
27+
@interface LPAlertMessageSnapshotTest : FBSnapshotTestCase
28+
29+
@end
30+
31+
@implementation LPAlertMessageSnapshotTest
32+
33+
- (void)setUp {
34+
// Put setup code here. This method is called before the invocation of each test method in the class.
35+
[super setUp];
36+
// self.recordMode = YES;
37+
}
38+
39+
- (void)tearDown {
40+
// Put teardown code here. This method is called after the invocation of each test method in the class.
41+
[super tearDown];
42+
}
43+
44+
- (void)testView {
45+
LPAlertMessageTemplate *template = [[LPAlertMessageTemplate alloc] init];
46+
LPActionContext *context = [LPActionContext actionContextWithName:LPMT_ALERT_NAME args:@{
47+
LPMT_ARG_TITLE:APP_NAME,
48+
LPMT_ARG_MESSAGE:LPMT_DEFAULT_ALERT_MESSAGE,
49+
LPMT_ARG_DISMISS_TEXT:LPMT_DEFAULT_OK_BUTTON_TEXT,
50+
} messageId:0];
51+
52+
UIViewController* viewController = [template viewControllerWithContext:context];
53+
FBSnapshotVerifyView(viewController.view, nil);
54+
}
55+
56+
@end
11.4 KB
Loading

Leanplum-SDK/Classes/MessageTemplates/LPAlertMessageTemplate.m

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,7 @@ -(void)defineActionWithContexts:(NSMutableArray *)contexts {
2323
]
2424
withResponder:^BOOL(LPActionContext *context) {
2525
@try {
26-
if (NSClassFromString(@"UIAlertController")) {
27-
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil) message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil) preferredStyle:UIAlertControllerStyleAlert];
28-
UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_DISMISS_TEXT], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
29-
[self alertDismissedWithButtonIndex:0];
30-
}];
31-
[alert addAction:action];
32-
33-
[[self visibleViewController] presentViewController:alert animated:YES completion:nil];
34-
} else
35-
{
36-
UIAlertView *alert = [[UIAlertView alloc]
37-
initWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil)
38-
message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil)
39-
delegate:self
40-
cancelButtonTitle:NSLocalizedString([context stringNamed:LPMT_ARG_DISMISS_TEXT], nil)
41-
otherButtonTitles:nil];
42-
[alert show];
43-
}
44-
26+
[[self visibleViewController] presentViewController:[self viewControllerWithContext:context] animated:YES completion:nil];
4527
[self.contexts addObject:context];
4628
return YES;
4729
}
@@ -53,4 +35,13 @@ -(void)defineActionWithContexts:(NSMutableArray *)contexts {
5335

5436
}
5537

38+
-(UIViewController *)viewControllerWithContext:(LPActionContext *)context {
39+
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil) message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil) preferredStyle:UIAlertControllerStyleAlert];
40+
UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_DISMISS_TEXT], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
41+
[self alertDismissedWithButtonIndex:0];
42+
}];
43+
[alert addAction:action];
44+
return alert;
45+
}
46+
5647
@end

0 commit comments

Comments
 (0)