diff options
Diffstat (limited to 'WordPress/src/androidTest/java/org/wordpress/android/ui/notifications')
3 files changed, 114 insertions, 0 deletions
diff --git a/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/GCMIntentServiceTest.java b/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/GCMIntentServiceTest.java new file mode 100644 index 000000000..ae2dd501f --- /dev/null +++ b/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/GCMIntentServiceTest.java @@ -0,0 +1,66 @@ +package org.wordpress.android.ui.notifications; + +import android.content.Context; +import android.os.Bundle; +import android.test.RenamingDelegatingContext; +import android.test.ServiceTestCase; + +import org.wordpress.android.FactoryUtils; +import org.wordpress.android.GCMMessageService; +import org.wordpress.android.TestUtils; +import org.wordpress.android.models.AccountHelper; + +public class GCMIntentServiceTest extends ServiceTestCase<GCMMessageService> { + protected Context mTargetContext; + + public GCMIntentServiceTest() { + super(GCMMessageService.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + FactoryUtils.initWithTestFactories(); + + mTargetContext = new RenamingDelegatingContext(getContext(), "test_"); + TestUtils.clearApplicationState(mTargetContext); + + setupService(); + } + + @Override + protected void tearDown() throws Exception { + FactoryUtils.clearFactories(); + super.tearDown(); + } + + public void testShouldCircularizeNoteIcon() { + GCMMessageService intentService = new GCMMessageService(); + + String type = "c"; + assertTrue(intentService.shouldCircularizeNoteIcon(type)); + + assertFalse(intentService.shouldCircularizeNoteIcon(null)); + + type = "invalidType"; + assertFalse(intentService.shouldCircularizeNoteIcon(type)); + } + + public void testOnMessageReceived() throws InterruptedException { + org.wordpress.android.models.Account account = AccountHelper.getDefaultAccount(); + account.setAccessToken("secret token"); + account.setUserId(1); + final Bundle bundle = new Bundle(); + bundle.putString("user", "1"); + for (int i = 0; i < 1000; i++) { + new Thread(new Runnable() { + @Override + public void run() { + getService().onMessageReceived("from", bundle); + } + }).start(); + } + + Thread.sleep(10000); + } +} diff --git a/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/NotesParseTest.java b/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/NotesParseTest.java new file mode 100644 index 000000000..0667ce023 --- /dev/null +++ b/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/NotesParseTest.java @@ -0,0 +1,29 @@ +package org.wordpress.android.ui.notifications; + +import android.text.Spanned; + +import junit.framework.TestCase; + +import org.wordpress.android.util.HtmlUtils; + +public class NotesParseTest extends TestCase { + public void testParagraphInListItem1() { + String text = "<li><p>Paragraph in li</p></li>"; + Spanned spanned = HtmlUtils.fromHtml(text); + // if this didn't throw a RuntimeException we're ok + assertNotNull(spanned); + } + + // Trying to reproduce https://github.com/wordpress-mobile/WordPress-Android/issues/900 + public void testSpanInListItem1() { + String text = "<ul><li><span>Current Record: </span><span>20</span></li><li><span>Old Record: </span><span>1</span></li></ul>"; + Spanned spanned = HtmlUtils.fromHtml(text); + assertEquals("Current Record: 20\nOld Record: 1\n", spanned.toString()); + } + + public void testSpanInListItemFullTest() { + String text = "<p>Au Mercredi 18 septembre 2013 vous avez pulvérisé votre précédent record de follows enregistrés en un seul jour, sur votre blog <a href=\"http://taliwutblog.wordpress.com\" title=\"taliwut & blog\" target=\"_blank\" notes-data-click=\"best_period_ever_feat\">taliwut & blog</a>. Super!</p><ul><li><span class=\"wpn-feat-current-record-title\">Current Record: </span><span class=\"wpn-feat-new-record-count\">20</span></li><li><span class=\"wpn-feat-old-record-title\">Old Record: </span><span class=\"wpn-feat-old-record-count\">1</span></li></ul>"; + Spanned spanned = HtmlUtils.fromHtml(text); + assertTrue(spanned.toString().contains("Current Record: 20\nOld Record: 1\n")); + } +}
\ No newline at end of file diff --git a/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/NotificationsUtilsTest.java b/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/NotificationsUtilsTest.java new file mode 100644 index 000000000..daef7f0ba --- /dev/null +++ b/WordPress/src/androidTest/java/org/wordpress/android/ui/notifications/NotificationsUtilsTest.java @@ -0,0 +1,19 @@ +package org.wordpress.android.ui.notifications; + +import android.test.AndroidTestCase; +import android.text.SpannableStringBuilder; + +import org.wordpress.android.ui.notifications.utils.NotificationsUtils; + +public class NotificationsUtilsTest extends AndroidTestCase { + public void testSpannableHasCharacterAtIndex() { + SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("This is only a test."); + + assertTrue(NotificationsUtils.spannableHasCharacterAtIndex(spannableStringBuilder, 's', 3)); + assertFalse(NotificationsUtils.spannableHasCharacterAtIndex(spannableStringBuilder, 's', 4)); + + // Test with bogus params + assertFalse(NotificationsUtils.spannableHasCharacterAtIndex(null, 'b', -1)); + } + +} |