-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/trunk' into merge/24.4-rc-2-to-t…
…runk
- Loading branch information
Showing
74 changed files
with
4,768 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
...s/src/androidTest/java/org/wordpress/android/ui/notifications/NotificationsUtilsTest.java
This file was deleted.
Oops, something went wrong.
118 changes: 118 additions & 0 deletions
118
...ess/src/androidTest/java/org/wordpress/android/ui/notifications/NotificationsUtilsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.wordpress.android.ui.notifications | ||
|
||
import android.text.SpannableStringBuilder | ||
import android.text.style.ClickableSpan | ||
import android.widget.TextView | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertFalse | ||
import junit.framework.TestCase.assertNotNull | ||
import junit.framework.TestCase.assertTrue | ||
import org.junit.Test | ||
import org.wordpress.android.fluxc.tools.FormattableContent | ||
import org.wordpress.android.fluxc.tools.FormattableRange | ||
import org.wordpress.android.ui.notifications.blocks.NoteBlockClickableSpan | ||
import org.wordpress.android.ui.notifications.utils.NotificationsUtils | ||
|
||
@HiltAndroidTest | ||
class NotificationsUtilsTest { | ||
@Test | ||
fun testSpannableHasCharacterAtIndex() { | ||
val spannableStringBuilder = 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)) | ||
} | ||
|
||
@Test | ||
fun testGetSpannableContentForRangesAndSkipInvalidUrls() { | ||
// Create a FormattableContent object | ||
val range1 = FormattableRange(indices = listOf(10, 14), url = "https://example.com", type = "a") | ||
val range2 = FormattableRange(indices = listOf(5, 20), url = "", type = "a") // invalid url to skip | ||
val formattableContent = FormattableContent( | ||
text = "This is a test content with a link", | ||
ranges = listOf(range1, range2) | ||
) | ||
|
||
// Create a TextView object | ||
val textView = TextView(InstrumentationRegistry.getInstrumentation().context) | ||
|
||
// Call the method with the created objects | ||
val result = NotificationsUtils.getSpannableContentForRanges(formattableContent, textView, false) {} | ||
|
||
// Check the result | ||
assertNotNull(result) | ||
assertEquals("This is a test content with a link", result.toString()) | ||
|
||
// Check if the link is correctly set | ||
val spans = result.getSpans(10, 14, ClickableSpan::class.java) | ||
assertTrue(spans.size == 1) | ||
assertEquals("https://example.com", (spans[0] as NoteBlockClickableSpan).formattableRange.url) | ||
} | ||
|
||
@Test | ||
fun testGetSpannableContentForRangesWithNoRanges() { | ||
// Create a FormattableContent object with no ranges | ||
val formattableContent = FormattableContent(text = "This is a test content with no link") | ||
|
||
// Create a TextView object | ||
val textView = TextView(InstrumentationRegistry.getInstrumentation().context) | ||
|
||
// Call the method with the created objects | ||
val result = NotificationsUtils.getSpannableContentForRanges(formattableContent, textView, false) {} | ||
|
||
// Check the result | ||
assertNotNull(result) | ||
assertEquals("This is a test content with no link", result.toString()) | ||
|
||
// Check if no ClickableSpan is set | ||
val spans = result.getSpans(0, result.length, ClickableSpan::class.java) | ||
assertTrue(spans.isEmpty()) | ||
} | ||
|
||
@Test | ||
fun testGetSpannableContentForRangesWithInvalidIndex() { | ||
// Create a FormattableContent object with a range with an invalid index | ||
val range = FormattableRange(indices = listOf(50, 54), url = "https://example.com", type = "a") | ||
val formattableContent = FormattableContent(text = "This is a test content", ranges = listOf(range)) | ||
|
||
// Create a TextView object | ||
val textView = TextView(InstrumentationRegistry.getInstrumentation().context) | ||
|
||
// Call the method with the created objects | ||
val result = NotificationsUtils.getSpannableContentForRanges(formattableContent, textView, false) {} | ||
|
||
// Check the result | ||
assertNotNull(result) | ||
assertEquals("This is a test content", result.toString()) | ||
|
||
// Check if no ClickableSpan is set | ||
val spans = result.getSpans(0, result.length, ClickableSpan::class.java) | ||
assertTrue(spans.isEmpty()) | ||
} | ||
|
||
@Test | ||
fun testGetSpannableContentForRangesWithNullUrl() { | ||
// Create a FormattableContent object with a range with a null URL | ||
val range = FormattableRange(indices = listOf(10, 14), url = null, type = "a") | ||
val formattableContent = FormattableContent(text = "This is a test content with a link", ranges = listOf(range)) | ||
|
||
// Create a TextView object | ||
val textView = TextView(InstrumentationRegistry.getInstrumentation().context) | ||
|
||
// Call the method with the created objects | ||
val result = NotificationsUtils.getSpannableContentForRanges(formattableContent, textView, false) {} | ||
|
||
// Check the result | ||
assertNotNull(result) | ||
assertEquals("This is a test content with a link", result.toString()) | ||
|
||
// Check if no ClickableSpan is set for the range with the null URL | ||
val spans = result.getSpans(10, 14, ClickableSpan::class.java) | ||
assertTrue(spans.isEmpty()) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
WordPress/src/main/java/org/wordpress/android/modules/PostModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.wordpress.android.modules | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.wordpress.android.ui.posts.IPostFreshnessChecker | ||
import org.wordpress.android.ui.posts.PostFreshnessCheckerImpl | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
class PostModule { | ||
@Singleton | ||
@Provides | ||
fun providePostFreshnessChecker(): IPostFreshnessChecker = PostFreshnessCheckerImpl() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.