Skip to content

Commit 7afb997

Browse files
authored
Merge pull request #446 from akitikkx/feature/add-tests-for-showdetailrepository
Add tests for showdetailrepository
2 parents 675499a + 207068a commit 7afb997

File tree

12 files changed

+686
-36
lines changed

12 files changed

+686
-36
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ MIT License
4+
~
5+
~ Copyright (c) 2022 Ahmed Tikiwa
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
~
9+
~ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10+
~
11+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
-->
13+
14+
<journey name="Dashboard Journey">
15+
<description>A Journey that tests the user flow on the dashboard screen</description>
16+
<actions>
17+
<action>Click on the Explore menu item, which can either be on the bottom of the screen (for
18+
compact window size classes) or on the left (on medium and expanded window size classes)</action>
19+
<action>If the Explore screen is displayed, keep waiting until there are visible posters
20+
with images for the Popular Shows and "Trending Shows" headings displayed on the screen</action>
21+
<action>If the Explore screen is displayed, verify that there is a list of poster images
22+
under a heading "Trending Shows".</action>
23+
<action>If the Explore screen is displayed, click on the first poster displayed under the
24+
"Trending Shows" heading</action>
25+
<action>Verify that clicking on the poster image under the "Trending Shows" heading results
26+
in the detail page for that same show title being displayed.</action>
27+
<action>If the detail page is being loaded, keep waiting until two images are fully
28+
displayed</action>
29+
<action>If the detail page is displayed, verify that the name of the show appears in the top
30+
bar as well as above the poster.</action>
31+
<action>If the detail page is displayed, click on the back arrow at the top of the detail
32+
screen</action>
33+
<action>Verify that clicking on the back arrow from the detail page for the selected show
34+
dismisses the detail page for that selected show</action>
35+
<action>If the Explore screen is displayed, scroll to the "Popular Shows" heading. Verify
36+
that there are a list of posters displayed under the "Popular Shows" heading</action>
37+
<action>If on the Explore screen, click on one of the shows under the "Popular Shows"
38+
heading</action>
39+
<action>Verify that clicking on the poster image under the "Popular Shows" heading results
40+
in the detail page for that same show title being displayed.</action>
41+
<action>If the detail page is being loaded, keep waiting until two images are fully
42+
displayed
43+
</action>
44+
<action>If the detail page is displayed, verify that the name of the show appears in the top
45+
bar as well as above the poster.
46+
</action>
47+
<action>If the detail page is displayed, click on the back arrow at the top of the detail
48+
screen
49+
</action>
50+
<action>If the Explore screen is displayed, scroll to the bottom of the screen "Most
51+
Anticipated Shows" heading
52+
</action>
53+
<action>Verify that there is a heading with "Most Anticipated Shows" text displayed with a
54+
list of poster images underneath it
55+
</action>
56+
<action>Click the back arrow at the top of the screen</action>
57+
</actions>
58+
</journey>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 Ahmed Tikiwa
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
*
8+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11+
*/
12+
13+
package com.theupnextapp.common
14+
15+
interface CrashlyticsHelper {
16+
fun recordException(e: Throwable)
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2022 Ahmed Tikiwa
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
*
8+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11+
*/
12+
13+
package com.theupnextapp.di
14+
15+
import com.google.firebase.crashlytics.FirebaseCrashlytics
16+
import com.theupnextapp.common.CrashlyticsHelper
17+
import javax.inject.Inject
18+
19+
class AppCrashlyticsHelper @Inject constructor(
20+
private val firebaseCrashlytics: FirebaseCrashlytics
21+
) : CrashlyticsHelper {
22+
23+
override fun recordException(e: Throwable) {
24+
firebaseCrashlytics.recordException(e)
25+
}
26+
}

app/src/main/java/com/theupnextapp/di/FirebaseCrashlyticsModule.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
package com.theupnextapp.di
2323

2424
import com.google.firebase.crashlytics.FirebaseCrashlytics
25+
import com.theupnextapp.common.CrashlyticsHelper
26+
import dagger.Binds
2527
import dagger.Module
2628
import dagger.Provides
2729
import dagger.hilt.InstallIn
@@ -30,11 +32,20 @@ import javax.inject.Singleton
3032

3133
@InstallIn(SingletonComponent::class)
3234
@Module
33-
class FirebaseCrashlyticsModule {
35+
abstract class FirebaseCrashlyticsModule {
3436

37+
@Binds
3538
@Singleton
36-
@Provides
37-
fun provideFirebaseCrashlytics(): FirebaseCrashlytics {
38-
return FirebaseCrashlytics.getInstance()
39+
abstract fun bindCrashlyticsHelper(
40+
appCrashlyticsHelper: AppCrashlyticsHelper
41+
): CrashlyticsHelper
42+
43+
companion object {
44+
@Singleton
45+
@Provides
46+
fun provideFirebaseCrashlytics(): FirebaseCrashlytics {
47+
return FirebaseCrashlytics.getInstance()
48+
}
3949
}
50+
4051
}

app/src/main/java/com/theupnextapp/di/RepositoryModule.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package com.theupnextapp.di
2323

2424
import com.google.firebase.crashlytics.FirebaseCrashlytics
2525
import com.squareup.moshi.Moshi
26+
import com.theupnextapp.common.CrashlyticsHelper // Added
2627
import com.theupnextapp.database.TraktDao
2728
import com.theupnextapp.database.TvMazeDao
2829
import com.theupnextapp.database.UpnextDao
@@ -48,12 +49,12 @@ object RepositoryModule {
4849
fun provideShowDetailRepository(
4950
upnextDao: UpnextDao,
5051
tvMazeService: TvMazeService,
51-
firebaseCrashlytics: FirebaseCrashlytics
52+
crashlyticsHelper: CrashlyticsHelper // Changed
5253
): ShowDetailRepository {
5354
return ShowDetailRepository(
5455
upnextDao = upnextDao,
5556
tvMazeService = tvMazeService,
56-
firebaseCrashlytics = firebaseCrashlytics
57+
crashlytics = crashlyticsHelper // Changed
5758
)
5859
}
5960

app/src/main/java/com/theupnextapp/domain/Result.kt

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
package com.theupnextapp.domain
2323

24-
import android.util.Log
2524
import com.squareup.moshi.Moshi
2625
import kotlinx.coroutines.CoroutineDispatcher
2726
import kotlinx.coroutines.withContext
@@ -31,15 +30,10 @@ import java.io.IOException
3130

3231
sealed class Result<out T> {
3332
data class Success<out T>(val data: T) : Result<T>()
34-
data class GenericError(val code: Int? = null, val error: ErrorResponse? = null) :
35-
Result<Nothing>()
36-
37-
object NetworkError : Result<Nothing>()
38-
data class Loading(val status: Boolean) :
39-
Result<Nothing>() // If you intend to emit loading states from here
40-
41-
data class Error(val exception: Throwable? = null, val message: String? = null) :
42-
Result<Nothing>()
33+
data class GenericError(val code: Int? = null, val error: ErrorResponse? = null, val exception: HttpException) : Result<Nothing>() // Modified
34+
data class NetworkError(val exception: IOException) : Result<Nothing>() // Modified
35+
data class Loading(val status: Boolean) : Result<Nothing>()
36+
data class Error(val exception: Throwable? = null, val message: String? = null) : Result<Nothing>()
4337
}
4438

4539
suspend fun <T> safeApiCall(dispatcher: CoroutineDispatcher, apiCall: suspend () -> T): Result<T> {
@@ -48,15 +42,13 @@ suspend fun <T> safeApiCall(dispatcher: CoroutineDispatcher, apiCall: suspend ()
4842
Result.Success(apiCall.invoke())
4943
} catch (throwable: Throwable) {
5044
when (throwable) {
51-
is IOException -> Result.NetworkError
45+
is IOException -> Result.NetworkError(throwable) // Modified
5246
is HttpException -> {
5347
val code = throwable.code()
5448
val errorResponse = parseHttpException(throwable)
55-
Result.GenericError(code, errorResponse)
49+
Result.GenericError(code, errorResponse, throwable) // Modified
5650
}
57-
5851
else -> {
59-
// Log the unexpected error for debugging purposes
6052
Timber.tag("SafeApiCall")
6153
.e(throwable, "Unexpected API call failure: ${throwable.localizedMessage}")
6254
Result.Error(

0 commit comments

Comments
 (0)