Skip to content

Commit a9284a1

Browse files
committed
Added unit tests for in-app location
1 parent a653b1c commit a9284a1

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.iterable.iterableapi;
2+
3+
import android.app.Application;
4+
import android.graphics.Rect;
5+
import android.test.ApplicationTestCase;
6+
import android.view.Gravity;
7+
8+
/**
9+
* Tests
10+
* Created by David Truong [email protected].
11+
*/
12+
public class IterableInAppTest extends ApplicationTestCase<Application> {
13+
public IterableInAppTest() {
14+
super(Application.class);
15+
}
16+
17+
IterableInAppHTMLNotification notification;
18+
19+
public void setUp() throws Exception {
20+
super.setUp();
21+
22+
notification = IterableInAppHTMLNotification.createInstance(getContext().getApplicationContext(), "");
23+
}
24+
25+
public void testGetLocationFull() {
26+
Rect padding = new Rect(0,0,0,0);
27+
int verticalLocation = notification.getVerticalLocation(padding);
28+
assertEquals(Gravity.CENTER_VERTICAL, verticalLocation);
29+
}
30+
31+
public void testGetLocationTop() {
32+
Rect padding = new Rect(0,0,0,-1);
33+
int verticalLocation = notification.getVerticalLocation(padding);
34+
assertEquals(Gravity.TOP, verticalLocation);
35+
}
36+
37+
public void testGetLocationBottom() throws Exception {
38+
Rect padding = new Rect(0,-1,0,0);
39+
int verticalLocation = notification.getVerticalLocation(padding);
40+
assertEquals(Gravity.BOTTOM, verticalLocation);
41+
}
42+
43+
public void testGetLocationCenter() {
44+
Rect padding = new Rect(0,-1,0,-1);
45+
int verticalLocation = notification.getVerticalLocation(padding);
46+
assertEquals(Gravity.CENTER_VERTICAL, verticalLocation);
47+
}
48+
49+
public void testGetLocationRandom() {
50+
Rect padding = new Rect(0,20,0,30);
51+
int verticalLocation = notification.getVerticalLocation(padding);
52+
assertEquals(Gravity.CENTER_VERTICAL, verticalLocation);
53+
}
54+
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppHTMLNotification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void run() {
211211
//Set the window properties
212212
WindowManager.LayoutParams wlp = window.getAttributes();
213213
wlp.x = offset;
214-
wlp.gravity = getLocation(insetPadding);
214+
wlp.gravity = getVerticalLocation(insetPadding);
215215
wlp.dimAmount = (float) notification.backgroundAlpha;
216216
wlp.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
217217
window.setAttributes(wlp);
@@ -225,7 +225,7 @@ public void run() {
225225
* @param padding
226226
* @return
227227
*/
228-
int getLocation(Rect padding) {
228+
int getVerticalLocation(Rect padding) {
229229
int gravity = Gravity.CENTER_VERTICAL;
230230
if (padding.top == 0 && padding.bottom < 0) {
231231
gravity = Gravity.TOP;

0 commit comments

Comments
 (0)