Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit 9f1c6ba4 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

fix: show "N/A" user rating in search results with 0 rating apps

Centralize app user rating formatting in AppUserRatingFormatter so Compose and non-Compose UI use the same raw rating rules.

Remove the old wrapper/viewmodel pass-through methods and cover the shared formatter with tests.
parent 4d7bbae5
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -53,7 +53,6 @@ import foundation.e.apps.ui.compose.state.InstallButtonAction
import foundation.e.apps.ui.compose.state.InstallButtonState
import foundation.e.apps.ui.compose.theme.AppTheme
import foundation.e.apps.ui.search.v2.SearchTabType
import java.util.Locale

@RunWith(AndroidJUnit4::class)
class SearchResultsContentTest {
@@ -137,8 +136,8 @@ class SearchResultsContentTest {
    fun applicationMapping_setsAuthorRatingAndPrimaryAction() {
        val notAvailable = composeRule.activity.getString(R.string.not_available)
        val openLabel = composeRule.activity.getString(R.string.open)
        val expectedRating = String.format(Locale.getDefault(), "%.1f", 4.4)
        val unexpectedRating = String.format(Locale.getDefault(), "%.1f", 4.9)
        val expectedRating = "4"
        val hiddenRating = "4.9"

        renderSearchResults(
            tabs = listOf(SearchTabType.OPEN_SOURCE),
@@ -150,7 +149,7 @@ class SearchResultsContentTest {
                        author = "",
                        package_name = "com.example.rated",
                        source = Source.PLAY_STORE,
                        ratings = Ratings(usageQualityScore = 4.4),
                        ratings = Ratings(usageQualityScore = 4.0),
                        status = Status.INSTALLED,
                    ),
                    Application(
@@ -184,7 +183,7 @@ class SearchResultsContentTest {
        composeRule.onNodeWithText(expectedRating).assertIsDisplayed()
        composeRule.onNodeWithText(openLabel).assertIsDisplayed()
        composeRule.onNodeWithText(notAvailable).assertIsDisplayed()
        composeRule.onAllNodesWithText(unexpectedRating).assertCountEquals(0)
        composeRule.onAllNodesWithText(hiddenRating).assertCountEquals(0)
    }

    @Test
+0 −2
Original line number Diff line number Diff line
@@ -37,6 +37,4 @@ object Constants {
        "${BuildConfig.PACKAGE_NAME_PARENTAL_CONTROL}.action.APP_LOUNGE_LOGIN"

    const val REQUEST_GPLAY_LOGIN = "request_gplay_login"

    const val MIN_VALID_RATING = 0.1
}
+0 −1
Original line number Diff line number Diff line
@@ -19,6 +19,5 @@
package foundation.e.apps.data.application.data

data class Ratings(
    val privacyScore: Double = -1.0,
    val usageQualityScore: Double = -1.0
)
+0 −13
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.content.Context
import androidx.lifecycle.LiveData
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.OpenForTesting
import foundation.e.apps.data.Constants.MIN_VALID_RATING
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.fdroid.FDroidRepository
import foundation.e.apps.data.install.download.data.DownloadProgress
@@ -171,18 +170,6 @@ class AppManagerWrapper @Inject constructor(
        return percent
    }

    fun handleRatingFormat(rating: Double): String? {
        return if (rating >= MIN_VALID_RATING) {
            if (rating % 1 == 0.0) {
                rating.toInt().toString()
            } else {
                rating.toString()
            }
        } else {
            null
        }
    }

    suspend fun getCalculateProgressWithTotalSize(
        application: Application?,
        progress: DownloadProgress
+0 −4
Original line number Diff line number Diff line
@@ -397,8 +397,4 @@ class MainActivityViewModel @Inject constructor(
    fun launchPwa(homeApp: ApplicationDomain) {
        launchPwa(homeApp.toApplication())
    }

    fun handleRatingFormat(rating: Double): String? {
        return appManagerWrapper.handleRatingFormat(rating)
    }
}
Loading