Skip to content

Commit e7be4a6

Browse files
SttApolloStypox
authored andcommitted
Convert CommentSectionErrorIntegrationTest to unit test
- Moved from androidTest to test directory - Removed Android test runner dependencies - Renamed to CommentSectionErrorTest - Addresses PR feedback until Compose testing is in place
1 parent ede45aa commit e7be4a6

4 files changed

Lines changed: 62 additions & 122 deletions

File tree

app/src/androidTest/java/org/schabi/newpipe/ui/components/video/comment/CommentSectionErrorIntegrationTest.kt

Lines changed: 0 additions & 119 deletions
This file was deleted.

app/src/main/java/org/schabi/newpipe/paging/CommentsSource.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import org.schabi.newpipe.extractor.Page
99
import org.schabi.newpipe.extractor.comments.CommentsInfo
1010
import org.schabi.newpipe.extractor.comments.CommentsInfoItem
1111
import org.schabi.newpipe.ui.components.video.comment.CommentInfo
12-
import java.io.IOException
1312

1413
class CommentsSource(private val commentInfo: CommentInfo) : PagingSource<Page, CommentsInfoItem>() {
1514
private val service = NewPipe.getService(commentInfo.serviceId)

app/src/main/java/org/schabi/newpipe/ui/components/common/ErrorPanel.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import org.schabi.newpipe.error.ErrorUtil
2121
import org.schabi.newpipe.error.ReCaptchaActivity
2222
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
2323
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
24-
import org.schabi.newpipe.extractor.timeago.patterns.it
2524
import org.schabi.newpipe.ui.theme.AppTheme
2625
import org.schabi.newpipe.ui.theme.SizeTokens.SpacingExtraLarge
2726
import org.schabi.newpipe.ui.theme.SizeTokens.SpacingMedium
@@ -48,8 +47,8 @@ fun determineErrorAction(errorInfo: ErrorInfo): ErrorAction {
4847
@Composable
4948
fun ErrorPanel(
5049
errorInfo: ErrorInfo,
50+
modifier: Modifier = Modifier,
5151
onRetry: (() -> Unit)? = null,
52-
modifier: Modifier = Modifier
5352

5453
) {
5554
val explanation = errorInfo.getExplanation()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.schabi.newpipe.ui.components.common
2+
3+
import androidx.paging.LoadState
4+
import org.junit.Assert
5+
import org.junit.Test
6+
import org.schabi.newpipe.error.ErrorInfo
7+
import org.schabi.newpipe.error.UserAction
8+
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
9+
import java.io.IOException
10+
import java.net.SocketTimeoutException
11+
12+
class CommentSectionErrorTest {
13+
14+
// Test 1: Network error on initial load (Resource.Error)
15+
@Test
16+
fun testInitialCommentNetworkError() {
17+
val expectedMessage = "Connection timeout"
18+
val networkError = SocketTimeoutException(expectedMessage)
19+
20+
val errorInfo = ErrorInfo(
21+
throwable = networkError,
22+
userAction = UserAction.REQUESTED_COMMENTS,
23+
request = "comments"
24+
)
25+
Assert.assertEquals(networkError, errorInfo.throwable)
26+
Assert.assertEquals(ErrorAction.REPORT, determineErrorAction(errorInfo))
27+
Assert.assertEquals(expectedMessage, errorInfo.getExplanation())
28+
}
29+
30+
// Test 2: Network error on paging (LoadState.Error)
31+
@Test
32+
fun testPagingNetworkError() {
33+
val expectedMessage = "Paging failed"
34+
val pagingError = IOException(expectedMessage)
35+
val loadStateError = LoadState.Error(pagingError)
36+
37+
val errorInfo = ErrorInfo(
38+
throwable = loadStateError.error,
39+
userAction = UserAction.REQUESTED_COMMENTS,
40+
request = "comments"
41+
)
42+
Assert.assertEquals(pagingError, errorInfo.throwable)
43+
Assert.assertEquals(ErrorAction.REPORT, determineErrorAction(errorInfo))
44+
Assert.assertEquals(expectedMessage, errorInfo.getExplanation())
45+
}
46+
47+
// Test 3: ReCaptcha during comments load
48+
@Test
49+
fun testReCaptchaDuringComments() {
50+
val url = "https://www.google.com/recaptcha/api/fallback?k=test"
51+
val expectedMessage = "ReCaptcha needed"
52+
val captcha = ReCaptchaException(expectedMessage, url)
53+
val errorInfo = ErrorInfo(
54+
throwable = captcha,
55+
userAction = UserAction.REQUESTED_COMMENTS,
56+
request = "comments"
57+
)
58+
Assert.assertEquals(ErrorAction.SOLVE_CAPTCHA, determineErrorAction(errorInfo))
59+
Assert.assertEquals(expectedMessage, errorInfo.getExplanation())
60+
}
61+
}

0 commit comments

Comments
 (0)