|
| 1 | +// |
| 2 | +// LPBaseInterstitialMessageTemplateTest.m |
| 3 | +// Leanplum-SDK |
| 4 | +// |
| 5 | +// Created by Mayank Sanganeria on 2/1/20. |
| 6 | +// Copyright © 2020 Leanplum. All rights reserved. |
| 7 | +// |
| 8 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 9 | +// or more contributor license agreements. See the NOTICE file |
| 10 | +// distributed with this work for additional information |
| 11 | +// regarding copyright ownership. The ASF licenses this file |
| 12 | +// to you under the Apache License, Version 2.0 (the "License"); |
| 13 | +// you may not use this file except in compliance with the License. |
| 14 | +// You may obtain a copy of the License at |
| 15 | +// |
| 16 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | +// |
| 18 | +// Unless required by applicable law or agreed to in writing, |
| 19 | +// software distributed under the License is distributed on an |
| 20 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 21 | +// KIND, either express or implied. See the License for the |
| 22 | +// specific language governing permissions and limitations |
| 23 | +// under the License. |
| 24 | + |
| 25 | + |
| 26 | +#import <XCTest/XCTest.h> |
| 27 | +#import <OHHTTPStubs/HTTPStubs.h> |
| 28 | +#import <OHHTTPStubs/HTTPStubsPathHelpers.h> |
| 29 | +#import "LeanplumHelper.h" |
| 30 | +#import "LPBaseInterstitialMessageTemplate.h" |
| 31 | + |
| 32 | +@interface LPBaseInterstitialMessageTemplate (Test) |
| 33 | +- (UIImage *)imageFromColor:(UIColor *)color; |
| 34 | +- (UIImage *)dismissImage:(UIColor *)color withSize:(int)size; |
| 35 | +- (NSString *)urlEncodedStringFromString:(NSString *)urlString; |
| 36 | + |
| 37 | +- (void)setupPopupLayout:(BOOL)isFullscreen isPushAskToAsk:(BOOL)isPushAskToAsk; |
| 38 | +- (void)updatePopupLayout; |
| 39 | +- (void)showPopup; |
| 40 | + |
| 41 | +@end |
| 42 | + |
| 43 | + |
| 44 | +@interface LPBaseInterstitialMessageTemplateTest : XCTestCase |
| 45 | + |
| 46 | +@end |
| 47 | + |
| 48 | +@implementation LPBaseInterstitialMessageTemplateTest |
| 49 | + |
| 50 | ++ (void)setUp |
| 51 | +{ |
| 52 | + [super setUp]; |
| 53 | + // Called only once to setup method swizzling. |
| 54 | + [LeanplumHelper setup_method_swizzling]; |
| 55 | +} |
| 56 | + |
| 57 | +- (void)setUp { |
| 58 | + [super setUp]; |
| 59 | +} |
| 60 | + |
| 61 | +- (void)tearDown { |
| 62 | + [super tearDown]; |
| 63 | + // Clean up after every test. |
| 64 | + [LeanplumHelper clean_up]; |
| 65 | + [HTTPStubs removeAllStubs]; |
| 66 | +} |
| 67 | + |
| 68 | +- (void)test_image_from_color |
| 69 | +{ |
| 70 | + LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init]; |
| 71 | + UIImage* image = [template imageFromColor:[UIColor blueColor]]; |
| 72 | + XCTAssertNotNil(image); |
| 73 | +} |
| 74 | + |
| 75 | +- (void)test_dismiss_image |
| 76 | +{ |
| 77 | + LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init]; |
| 78 | + UIImage* image = [template dismissImage:[UIColor blueColor] withSize:128]; |
| 79 | + XCTAssertNotNil(image); |
| 80 | +} |
| 81 | + |
| 82 | +- (void)test_popup_setup |
| 83 | +{ |
| 84 | + LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init]; |
| 85 | + // This stub have to be removed when start command is successfully executed. |
| 86 | + [HTTPStubs stubRequestsPassingTest: |
| 87 | + ^BOOL(NSURLRequest * _Nonnull request) { |
| 88 | + return [request.URL.host isEqualToString:API_HOST]; |
| 89 | + } withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) { |
| 90 | + NSString *response_file = OHPathForFile(@"simple_start_response.json", self.class); |
| 91 | + return [HTTPStubsResponse responseWithFileAtPath:response_file statusCode:200 |
| 92 | + headers:@{@"Content-Type":@"application/json"}]; |
| 93 | + }]; |
| 94 | + |
| 95 | + XCTAssertTrue([LeanplumHelper start_development_test]); |
| 96 | + |
| 97 | + [template setupPopupLayout:YES isPushAskToAsk:NO]; |
| 98 | + [template updatePopupLayout]; |
| 99 | + [template showPopup]; |
| 100 | + id acceptButton = [template valueForKey:@"_acceptButton"]; |
| 101 | + XCTAssertNotNil(acceptButton); |
| 102 | +} |
| 103 | + |
| 104 | +- (void)test_push_popup_setup |
| 105 | +{ |
| 106 | + |
| 107 | + LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init]; |
| 108 | + // This stub have to be removed when start command is successfully executed. |
| 109 | + [HTTPStubs stubRequestsPassingTest: |
| 110 | + ^BOOL(NSURLRequest * _Nonnull request) { |
| 111 | + return [request.URL.host isEqualToString:API_HOST]; |
| 112 | + } withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) { |
| 113 | + NSString *response_file = OHPathForFile(@"simple_start_response.json", self.class); |
| 114 | + return [HTTPStubsResponse responseWithFileAtPath:response_file statusCode:200 |
| 115 | + headers:@{@"Content-Type":@"application/json"}]; |
| 116 | + }]; |
| 117 | + |
| 118 | + XCTAssertTrue([LeanplumHelper start_development_test]); |
| 119 | + |
| 120 | + [template setupPopupLayout:YES isPushAskToAsk:YES]; |
| 121 | + [template updatePopupLayout]; |
| 122 | + [template showPopup]; |
| 123 | + id acceptButton = [template valueForKey:@"_acceptButton"]; |
| 124 | + XCTAssertNotNil(acceptButton); |
| 125 | + id cancelButton = [template valueForKey:@"_cancelButton"]; |
| 126 | + XCTAssertNotNil(cancelButton); |
| 127 | +} |
| 128 | + |
| 129 | +- (void)test_urlEncodedStringFromString { |
| 130 | + LPBaseInterstitialMessageTemplate *template = [[LPBaseInterstitialMessageTemplate alloc] init]; |
| 131 | + XCTAssertEqualObjects([template urlEncodedStringFromString:@"http://www.leanplum.com"], @"http://www.leanplum.com"); |
| 132 | + XCTAssertEqualObjects([template urlEncodedStringFromString:@"http://www.leanplum.com?q=simple_english1&test=2"], @"http://www.leanplum.com?q=simple_english1&test=2"); |
| 133 | + XCTAssertEqualObjects([template urlEncodedStringFromString:@"https://ramsey.tfaforms.net/356302?id={}"], @"https://ramsey.tfaforms.net/356302?id=%7B%7D"); |
| 134 | + XCTAssertEqualObjects([template urlEncodedStringFromString:@"lomotif://music/月亮"], @"lomotif://music/%E6%9C%88%E4%BA%AE"); |
| 135 | +} |
| 136 | + |
| 137 | +@end |
0 commit comments