Skip to content

Commit c762669

Browse files
Migrate tests to Swift. Objc tests fail because some methods are not exposed to Objc.
1 parent d6371be commit c762669

File tree

6 files changed

+177
-192
lines changed

6 files changed

+177
-192
lines changed

Tests/swift-sdk-objc-tests/IterableInAppNotificationTests.m

-168
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
}

swift-sdk.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
AC347B6720E699FA003449CF /* IterableAppExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = AC347B6620E699D8003449CF /* IterableAppExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; };
2222
AC6FDD8820F4372E005D811E /* IterableAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC6FDD8720F4372E005D811E /* IterableAPI.swift */; };
2323
AC6FDD8A20F55D13005D811E /* IterableAPI+Internal.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC6FDD8920F55D13005D811E /* IterableAPI+Internal.swift */; };
24+
AC6FDD8C20F56309005D811E /* IterableInAppNotificationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC6FDD8B20F56309005D811E /* IterableInAppNotificationTests.swift */; };
2425
AC7125EF20D4579E0043BBC1 /* IterableConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7125EE20D4579E0043BBC1 /* IterableConfig.swift */; };
2526
AC72A0B520CF4C49004D7997 /* IterableConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = AC72A0B120CF4C32004D7997 /* IterableConstants.h */; settings = {ATTRIBUTES = (Public, ); }; };
2627
AC72A0B620CF4C53004D7997 /* IterableConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = AC72A0B420CF4C32004D7997 /* IterableConstants.m */; };
@@ -45,7 +46,6 @@
4546
AC7B145120D038C400877BFE /* IterableAPIResponseTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AC7B144920D038C400877BFE /* IterableAPIResponseTests.m */; };
4647
AC7B145220D038C400877BFE /* IterableNotificationMetadataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AC7B144A20D038C400877BFE /* IterableNotificationMetadataTests.m */; };
4748
AC7B145320D038C400877BFE /* IterableAPIImplementationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AC7B144B20D038C400877BFE /* IterableAPIImplementationTests.m */; };
48-
AC7B145420D038C400877BFE /* IterableInAppNotificationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AC7B144C20D038C400877BFE /* IterableInAppNotificationTests.m */; };
4949
AC90C4CD20D8632E00EECA5D /* IterableAppExtensions.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AC90C4C420D8632D00EECA5D /* IterableAppExtensions.framework */; };
5050
AC90C4E220D8639E00EECA5D /* ITBNotificationServiceExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC90C4E120D8639E00EECA5D /* ITBNotificationServiceExtension.swift */; };
5151
AC90C4E320D863B700EECA5D /* ITBConsts.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC72A0BE20CF4CB8004D7997 /* ITBConsts.swift */; };
@@ -124,6 +124,7 @@
124124
AC431DF320D18E9000BFAFD1 /* swift-sdk-objc-tests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "swift-sdk-objc-tests-Bridging-Header.h"; sourceTree = "<group>"; };
125125
AC6FDD8720F4372E005D811E /* IterableAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterableAPI.swift; sourceTree = "<group>"; };
126126
AC6FDD8920F55D13005D811E /* IterableAPI+Internal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IterableAPI+Internal.swift"; sourceTree = "<group>"; };
127+
AC6FDD8B20F56309005D811E /* IterableInAppNotificationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterableInAppNotificationTests.swift; sourceTree = "<group>"; };
127128
AC7125EE20D4579E0043BBC1 /* IterableConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterableConfig.swift; sourceTree = "<group>"; };
128129
AC72A0AA20CF4BEB004D7997 /* IterableInAppManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterableInAppManager.swift; sourceTree = "<group>"; };
129130
AC72A0AB20CF4BEB004D7997 /* IterableInAppHTMLViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IterableInAppHTMLViewController.swift; sourceTree = "<group>"; };
@@ -150,7 +151,6 @@
150151
AC7B144920D038C400877BFE /* IterableAPIResponseTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IterableAPIResponseTests.m; sourceTree = "<group>"; };
151152
AC7B144A20D038C400877BFE /* IterableNotificationMetadataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IterableNotificationMetadataTests.m; sourceTree = "<group>"; };
152153
AC7B144B20D038C400877BFE /* IterableAPIImplementationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IterableAPIImplementationTests.m; sourceTree = "<group>"; };
153-
AC7B144C20D038C400877BFE /* IterableInAppNotificationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IterableInAppNotificationTests.m; sourceTree = "<group>"; };
154154
AC90C4C420D8632D00EECA5D /* IterableAppExtensions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = IterableAppExtensions.framework; sourceTree = BUILT_PRODUCTS_DIR; };
155155
AC90C4C720D8632E00EECA5D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
156156
AC90C4CC20D8632E00EECA5D /* notification-extension-tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "notification-extension-tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -356,6 +356,7 @@
356356
AC2C668320D3370600D46CC9 /* Mocks.swift */,
357357
AC2C667F20D31B1F00D46CC9 /* IterableNotificationResponseTests.swift */,
358358
AC2C668620D3435700D46CC9 /* IterableActionRunnerTests.swift */,
359+
AC6FDD8B20F56309005D811E /* IterableInAppNotificationTests.swift */,
359360
);
360361
path = "swift-sdk-swift-tests";
361362
sourceTree = "<group>";
@@ -368,7 +369,6 @@
368369
AC7B144920D038C400877BFE /* IterableAPIResponseTests.m */,
369370
AC7B144720D038C400877BFE /* CommerceItemTests.m */,
370371
AC7B144A20D038C400877BFE /* IterableNotificationMetadataTests.m */,
371-
AC7B144C20D038C400877BFE /* IterableInAppNotificationTests.m */,
372372
);
373373
path = "swift-sdk-objc-tests";
374374
sourceTree = "<group>";
@@ -765,6 +765,7 @@
765765
buildActionMask = 2147483647;
766766
files = (
767767
AC2C668720D3435700D46CC9 /* IterableActionRunnerTests.swift in Sources */,
768+
AC6FDD8C20F56309005D811E /* IterableInAppNotificationTests.swift in Sources */,
768769
AC2C668020D31B1F00D46CC9 /* IterableNotificationResponseTests.swift in Sources */,
769770
AC2C668420D3370600D46CC9 /* Mocks.swift in Sources */,
770771
);
@@ -779,7 +780,6 @@
779780
AC7B145120D038C400877BFE /* IterableAPIResponseTests.m in Sources */,
780781
ACFCA72720EAEC3200BFB277 /* Mocks.swift in Sources */,
781782
AC7B144F20D038C400877BFE /* CommerceItemTests.m in Sources */,
782-
AC7B145420D038C400877BFE /* IterableInAppNotificationTests.m in Sources */,
783783
);
784784
runOnlyForDeploymentPostprocessing = 0;
785785
};

0 commit comments

Comments
 (0)