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

Commit 38e2e506 authored by Hasib Prince's avatar Hasib Prince
Browse files

fixed: unit test and minor refactor

parent 6ae3b10c
Loading
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -103,11 +103,10 @@ class HomeViewModel @Inject constructor(
    private fun postHomeResult(homeResult: ResultSupreme<List<Home>>) {
        if (shouldUpdateResult(homeResult)) {
            homeScreenData.value = homeResult
            currentHomes = homeResult.data?.map { home -> home.copy() }
            currentHomes = homeResult.data
            return
        }

        // homeResult is success, but not change is found
        homeScreenData.value = ResultSupreme.Error("No change is found in homepage")
    }

@@ -122,7 +121,7 @@ class HomeViewModel @Inject constructor(
    )

    private fun compareWithNewData(newHomes: List<Home>): Boolean {
        currentHomes!!.forEach {
        currentHomes?.forEach {
            val fusedHome = newHomes[currentHomes!!.indexOf(it)]

            if (!it.title.contentEquals(fusedHome.title) || !it.id.contentEquals(fusedHome.id)
+6 −6
Original line number Diff line number Diff line
@@ -48,9 +48,9 @@ class HomeViewModelTest {
        val newAppList = mutableListOf(Application("123"), Application("124"))

        val oldHomeData =
            listOf(Home("Top Free Apps", oldAppList), Home("Top Free Games", oldAppList))
            listOf(Home("Top Free Apps", oldAppList, id = "123"), Home("Top Free Games", oldAppList, id = "124"))
        var newHomeData =
            listOf(Home("Top Free Apps", newAppList), Home("Top Free Games", newAppList))
            listOf(Home("Top Free Apps", newAppList, id = "123"), Home("Top Free Games", newAppList, id = "124"))

        homeViewModel.currentHomes = oldHomeData

@@ -64,9 +64,9 @@ class HomeViewModelTest {
        val newAppList = mutableListOf(Application("123"), Application("124"), Application("125"))

        val oldHomeData =
            listOf(Home("Top Free Apps", oldAppList), Home("Top Free Games", oldAppList))
            listOf(Home("Top Free Apps", oldAppList, id = "123"), Home("Top Free Games", oldAppList, id = "124"))
        var newHomeData =
            listOf(Home("Top Free Apps", newAppList), Home("Top Free Games", newAppList))
            listOf(Home("Top Free Apps", newAppList, id = "123"), Home("Top Free Games", newAppList, id = "124"))

        homeViewModel.currentHomes = oldHomeData

@@ -80,9 +80,9 @@ class HomeViewModelTest {
        val newAppList = mutableListOf(Application("123"), Application("124", status = Status.INSTALLED), Application("125"))

        val oldHomeData =
            listOf(Home("Top Free Apps", oldAppList), Home("Top Free Games", oldAppList))
            listOf(Home("Top Free Apps", oldAppList, id = "123"), Home("Top Free Games", oldAppList, id = "124"))
        var newHomeData =
            listOf(Home("Top Free Apps", newAppList), Home("Top Free Games", newAppList))
            listOf(Home("Top Free Apps", newAppList, id = "123"), Home("Top Free Games", newAppList, id = "124"))

        homeViewModel.currentHomes = oldHomeData