Skip to content

Commit 0172e23

Browse files
authored
add confirm message test (#345)
1 parent e112918 commit 0172e23

File tree

4 files changed

+72
-21
lines changed

4 files changed

+72
-21
lines changed

Example/Leanplum-SDK.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
A84527FD215C3035001FA20D /* LPRequestTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A84527FC215C3035001FA20D /* LPRequestTest.m */; };
104104
A86C8CF42405E271003F5E4E /* LPAlertMessageSnapshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A86C8CF32405E271003F5E4E /* LPAlertMessageSnapshotTest.m */; };
105105
A86C8CF624072814003F5E4E /* LPOpenUrlMessageTemplateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A86C8CF524072814003F5E4E /* LPOpenUrlMessageTemplateTest.m */; };
106+
A86C8CF924084263003F5E4E /* LPConfirmMessageSnapshotTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A86C8CF724084236003F5E4E /* LPConfirmMessageSnapshotTest.m */; };
106107
A8CB8A36227276A400E1001D /* LeanplumRequestTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A8CB8A35227276A400E1001D /* LeanplumRequestTest.m */; };
107108
A8EEA1AB20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
108109
A8EEA1AC20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
@@ -212,6 +213,7 @@
212213
A84527FC215C3035001FA20D /* LPRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPRequestTest.m; sourceTree = "<group>"; };
213214
A86C8CF32405E271003F5E4E /* LPAlertMessageSnapshotTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPAlertMessageSnapshotTest.m; sourceTree = "<group>"; };
214215
A86C8CF524072814003F5E4E /* LPOpenUrlMessageTemplateTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPOpenUrlMessageTemplateTest.m; sourceTree = "<group>"; };
216+
A86C8CF724084236003F5E4E /* LPConfirmMessageSnapshotTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPConfirmMessageSnapshotTest.m; sourceTree = "<group>"; };
215217
A8CB8A35227276A400E1001D /* LeanplumRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LeanplumRequestTest.m; sourceTree = "<group>"; };
216218
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>"; };
217219
A8F5D58623F3483E00313C98 /* LPBaseInterstitialMessageTemplateTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPBaseInterstitialMessageTemplateTest.m; sourceTree = "<group>"; };
@@ -482,6 +484,7 @@
482484
isa = PBXGroup;
483485
children = (
484486
A86C8CF32405E271003F5E4E /* LPAlertMessageSnapshotTest.m */,
487+
A86C8CF724084236003F5E4E /* LPConfirmMessageSnapshotTest.m */,
485488
);
486489
path = "Snapshot Tests";
487490
sourceTree = "<group>";
@@ -786,6 +789,7 @@
786789
07E5C8B21F052B7800A4B092 /* LPNetworkOperation+Category.m in Sources */,
787790
65E53E982148786C00A05040 /* LPCountAggregatorTest.m in Sources */,
788791
07E5C8B91F052B7800A4B092 /* LPMessageTemplatesClassTest.m in Sources */,
792+
A86C8CF924084263003F5E4E /* LPConfirmMessageSnapshotTest.m in Sources */,
789793
A8F5D58A23F34AD400313C98 /* LPBasePushMessageTemplateTest.m in Sources */,
790794
07E5C8B11F052B7800A4B092 /* LPNetworkEngine+Category.m in Sources */,
791795
07E5C8B61F052B7800A4B092 /* LeanplumTest.m in Sources */,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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/LPConfirmMessageTemplate.h>
12+
13+
@interface LPConfirmMessageTemplate()
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 LPConfirmMessageSnapshotTest : FBSnapshotTestCase
28+
29+
@end
30+
31+
@implementation LPConfirmMessageSnapshotTest
32+
33+
- (void)setUp {
34+
[super setUp];
35+
// self.recordMode = YES;
36+
}
37+
38+
- (void)tearDown {
39+
[super tearDown];
40+
}
41+
42+
- (void)testView {
43+
LPConfirmMessageTemplate *template = [[LPConfirmMessageTemplate alloc] init];
44+
LPActionContext *context = [LPActionContext actionContextWithName:LPMT_CONFIRM_NAME args:@{
45+
LPMT_ARG_TITLE: APP_NAME,
46+
LPMT_ARG_MESSAGE: LPMT_DEFAULT_CONFIRM_MESSAGE,
47+
LPMT_ARG_ACCEPT_TEXT: LPMT_DEFAULT_YES_BUTTON_TEXT,
48+
LPMT_ARG_CANCEL_TEXT: LPMT_DEFAULT_NO_BUTTON_TEXT,
49+
} messageId:0];
50+
51+
UIViewController* viewController = [template viewControllerWithContext:context];
52+
FBSnapshotVerifyView(viewController.view, nil);
53+
}
54+
55+
@end
15.1 KB
Loading

Leanplum-SDK/Classes/MessageTemplates/LPConfirmMessageTemplate.m

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,9 @@ -(void)defineActionWithContexts:(NSMutableArray *)contexts {
2525
]
2626
withResponder:^BOOL(LPActionContext *context) {
2727
@try {
28-
if (NSClassFromString(@"UIAlertController")) {
29-
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil) message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil) preferredStyle:UIAlertControllerStyleAlert];
30-
UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_CANCEL_TEXT], nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
31-
[self alertDismissedWithButtonIndex:0];
32-
}];
33-
[alert addAction:cancel];
34-
UIAlertAction *accept = [UIAlertAction actionWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_ACCEPT_TEXT], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
35-
[self alertDismissedWithButtonIndex:1];
36-
}];
37-
[alert addAction:accept];
3828

3929
[[self visibleViewController]
40-
presentViewController:alert animated:YES completion:nil];
41-
} else
42-
{
43-
UIAlertView *alert = [[UIAlertView alloc]
44-
initWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil)
45-
message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil)
46-
delegate:self
47-
cancelButtonTitle:NSLocalizedString([context stringNamed:LPMT_ARG_CANCEL_TEXT], nil)
48-
otherButtonTitles:NSLocalizedString([context stringNamed:LPMT_ARG_ACCEPT_TEXT], nil),nil];
49-
[alert show];
50-
}
30+
presentViewController:[self viewControllerWithContext:context] animated:YES completion:nil];
5131
[self.contexts addObject:context];
5232
return YES;
5333
}
@@ -59,4 +39,16 @@ -(void)defineActionWithContexts:(NSMutableArray *)contexts {
5939

6040
}
6141

42+
-(UIViewController *)viewControllerWithContext:(LPActionContext *)context {
43+
UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_TITLE], nil) message:NSLocalizedString([context stringNamed:LPMT_ARG_MESSAGE], nil) preferredStyle:UIAlertControllerStyleAlert];
44+
UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_CANCEL_TEXT], nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
45+
[self alertDismissedWithButtonIndex:0];
46+
}];
47+
[alert addAction:cancel];
48+
UIAlertAction *accept = [UIAlertAction actionWithTitle:NSLocalizedString([context stringNamed:LPMT_ARG_ACCEPT_TEXT], nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
49+
[self alertDismissedWithButtonIndex:1];
50+
}];
51+
[alert addAction:accept];
52+
return alert;
53+
}
6254
@end

0 commit comments

Comments
 (0)