|
| 1 | +// |
| 2 | +// IterableInAppNotificationTests.swift |
| 3 | +// swift-sdk-swift-tests |
| 4 | + |
| 5 | +// Created by David Truong on 10/3/17. |
| 6 | +// Migrated to Swift by Tapash Majumder on 7/10/18. |
| 7 | +// Copyright © 2018 Iterable. All rights reserved. |
| 8 | +// |
| 9 | + |
| 10 | +import XCTest |
| 11 | + |
| 12 | +@testable import IterableSDK |
| 13 | + |
| 14 | +class IterableInAppNotificationTests: XCTestCase { |
| 15 | + |
| 16 | + override func setUp() { |
| 17 | + super.setUp() |
| 18 | + // Put setup code here. This method is called before the invocation of each test method in the class. |
| 19 | + } |
| 20 | + |
| 21 | + override func tearDown() { |
| 22 | + // Put teardown code here. This method is called after the invocation of each test method in the class. |
| 23 | + super.tearDown() |
| 24 | + } |
| 25 | + |
| 26 | + func testGetNextNotificationNil() { |
| 27 | + let message = IterableInAppManager.getNextMessageFromPayload(nil) |
| 28 | + XCTAssertNil(message) |
| 29 | + } |
| 30 | + |
| 31 | + func testGetNextNotificationEmpty() { |
| 32 | + let message = IterableInAppManager.getNextMessageFromPayload([:]) |
| 33 | + XCTAssertNil(message) |
| 34 | + } |
| 35 | + |
| 36 | + func testNotificationCreation() { |
| 37 | + //call showIterableNotificationHTML with fake data |
| 38 | + //Check the top level dialog |
| 39 | + |
| 40 | + let htmlString = "<a href=\"http://www.iterable.com\" target=\"http://www.iterable.com\">test</a>" |
| 41 | + let baseNotification = IterableInAppHTMLViewController(data: htmlString) |
| 42 | + let html = baseNotification.getHtml() |
| 43 | + XCTAssertEqual(html, htmlString) |
| 44 | + } |
| 45 | + |
| 46 | + func testGetPaddingInvalid() { |
| 47 | + let insets = IterableInAppManager.getPaddingFromPayload([:]) |
| 48 | + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(insets, UIEdgeInsets.zero)) |
| 49 | + } |
| 50 | + |
| 51 | + func testGetPaddingFull() { |
| 52 | + let payload: [AnyHashable : Any] = [ |
| 53 | + "top" : ["percentage" : "0"], |
| 54 | + "left" : ["percentage" : "0"], |
| 55 | + "bottom" : ["percentage" : "0"], |
| 56 | + "right" : ["right" : "0"], |
| 57 | + ] |
| 58 | + |
| 59 | + let insets = IterableInAppManager.getPaddingFromPayload(payload) |
| 60 | + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(insets, UIEdgeInsets.zero)) |
| 61 | + |
| 62 | + var padding = UIEdgeInsets.zero |
| 63 | + padding.top = CGFloat(IterableInAppManager.decodePadding(payload["top"])) |
| 64 | + padding.left = CGFloat(IterableInAppManager.decodePadding(payload["left"])) |
| 65 | + padding.bottom = CGFloat(IterableInAppManager.decodePadding(payload["bottom"])) |
| 66 | + padding.right = CGFloat(IterableInAppManager.decodePadding(payload["right"])) |
| 67 | + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(padding, UIEdgeInsets.zero)) |
| 68 | + } |
| 69 | + |
| 70 | + func testGetPaddingCenter() { |
| 71 | + let payload: [AnyHashable : Any] = [ |
| 72 | + "top" : ["displayOption" : "AutoExpand"], |
| 73 | + "left" : ["percentage" : "0"], |
| 74 | + "bottom" : ["displayOption" : "AutoExpand"], |
| 75 | + "right" : ["right" : "0"], |
| 76 | + ] |
| 77 | + |
| 78 | + let insets = IterableInAppManager.getPaddingFromPayload(payload) |
| 79 | + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(insets, UIEdgeInsets(top: -1, left: 0, bottom: -1, right: 0))) |
| 80 | + |
| 81 | + var padding = UIEdgeInsets.zero |
| 82 | + padding.top = CGFloat(IterableInAppManager.decodePadding(payload["top"])) |
| 83 | + padding.left = CGFloat(IterableInAppManager.decodePadding(payload["left"])) |
| 84 | + padding.bottom = CGFloat(IterableInAppManager.decodePadding(payload["bottom"])) |
| 85 | + padding.right = CGFloat(IterableInAppManager.decodePadding(payload["right"])) |
| 86 | + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(padding, UIEdgeInsets(top: -1, left: 0, bottom: -1, right: 0))) |
| 87 | + } |
| 88 | + |
| 89 | + func testGetPaddingTop() { |
| 90 | + let payload: [AnyHashable : Any] = [ |
| 91 | + "top" : ["percentage" : "0"], |
| 92 | + "left" : ["percentage" : "0"], |
| 93 | + "bottom" : ["displayOption" : "AutoExpand"], |
| 94 | + "right" : ["right" : "0"], |
| 95 | + ] |
| 96 | + |
| 97 | + let insets = IterableInAppManager.getPaddingFromPayload(payload) |
| 98 | + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(insets, UIEdgeInsets(top: 0, left: 0, bottom: -1, right: 0))) |
| 99 | + |
| 100 | + var padding = UIEdgeInsets.zero |
| 101 | + padding.top = CGFloat(IterableInAppManager.decodePadding(payload["top"])) |
| 102 | + padding.left = CGFloat(IterableInAppManager.decodePadding(payload["left"])) |
| 103 | + padding.bottom = CGFloat(IterableInAppManager.decodePadding(payload["bottom"])) |
| 104 | + padding.right = CGFloat(IterableInAppManager.decodePadding(payload["right"])) |
| 105 | + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(padding, UIEdgeInsets(top: 0, left: 0, bottom: -1, right: 0))) |
| 106 | + } |
| 107 | + |
| 108 | + func testGetPaddingBottom() { |
| 109 | + let payload: [AnyHashable : Any] = [ |
| 110 | + "top" : ["displayOption" : "AutoExpand"], |
| 111 | + "left" : ["percentage" : "0"], |
| 112 | + "bottom" : ["percentage" : "0"], |
| 113 | + "right" : ["right" : "0"], |
| 114 | + ] |
| 115 | + |
| 116 | + let insets = IterableInAppManager.getPaddingFromPayload(payload) |
| 117 | + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(insets, UIEdgeInsets(top: -1, left: 0, bottom: 0, right: 0))) |
| 118 | + |
| 119 | + var padding = UIEdgeInsets.zero |
| 120 | + padding.top = CGFloat(IterableInAppManager.decodePadding(payload["top"])) |
| 121 | + padding.left = CGFloat(IterableInAppManager.decodePadding(payload["left"])) |
| 122 | + padding.bottom = CGFloat(IterableInAppManager.decodePadding(payload["bottom"])) |
| 123 | + padding.right = CGFloat(IterableInAppManager.decodePadding(payload["right"])) |
| 124 | + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(padding, UIEdgeInsets(top: -1, left: 0, bottom: 0, right: 0))) |
| 125 | + } |
| 126 | + |
| 127 | + func testNotificationPaddingFull() { |
| 128 | + let notificationType = IterableInAppHTMLViewController.setLocation(UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)) |
| 129 | + XCTAssertEqual(notificationType, .full) |
| 130 | + } |
| 131 | + |
| 132 | + func testNotificationPaddingTop() { |
| 133 | + let notificationType = IterableInAppHTMLViewController.setLocation(UIEdgeInsets(top: 0, left: 0, bottom: -1, right: 0)) |
| 134 | + XCTAssertEqual(notificationType, .top) |
| 135 | + } |
| 136 | + |
| 137 | + func testNotificationPaddingBottom() { |
| 138 | + let notificationType = IterableInAppHTMLViewController.setLocation(UIEdgeInsets(top: -1, left: 0, bottom: 0, right: 0)) |
| 139 | + XCTAssertEqual(notificationType, .bottom) |
| 140 | + } |
| 141 | + |
| 142 | + func testNotificationPaddingCenter() { |
| 143 | + let notificationType = IterableInAppHTMLViewController.setLocation(UIEdgeInsets(top: -1, left: 0, bottom: -1, right: 0)) |
| 144 | + XCTAssertEqual(notificationType, .center) |
| 145 | + } |
| 146 | + |
| 147 | + func testNotificationPaddingDefault() { |
| 148 | + let notificationType = IterableInAppHTMLViewController.setLocation(UIEdgeInsets(top: 10, left: 0, bottom: 20, right: 0)) |
| 149 | + XCTAssertEqual(notificationType, .center) |
| 150 | + } |
| 151 | +} |
0 commit comments