From afca80f026d0989971537a3e88647456a9ae7dbc Mon Sep 17 00:00:00 2001 From: Lorenzo Stanco Date: Mon, 26 Oct 2020 20:09:24 +0100 Subject: [PATCH] Issue #8751: Added DAO method to update top site entries --- .../feature/top/sites/db/PinnedSiteDaoTest.kt | 24 +++++++++++++++++++ .../feature/top/sites/db/PinnedSiteDao.kt | 10 ++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/PinnedSiteDaoTest.kt b/components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/PinnedSiteDaoTest.kt index 367590fee5c..ec545ac31d0 100644 --- a/components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/PinnedSiteDaoTest.kt +++ b/components/feature/top-sites/src/androidTest/java/mozilla/components/feature/top/sites/db/PinnedSiteDaoTest.kt @@ -56,6 +56,30 @@ class PinnedSiteDaoTest { assertEquals(1, pinnedSites.size) assertEquals(topSite, pinnedSites[0]) } + + @Test + fun testUpdatingTopSite() { + val topSite = PinnedSiteEntity( + title = "Mozilla", + url = "https://www.mozilla.org", + isDefault = false, + createdAt = 200 + ).also { + it.id = pinnedSiteDao.insertPinnedSite(it) + } + + topSite.title = "Mozilla (IT)" + topSite.url = "https://www.mozilla.org/it" + pinnedSiteDao.updatePinnedSite(topSite) + + val pinnedSites = pinnedSiteDao.getPinnedSites() + + assertEquals(1, pinnedSites.size) + assertEquals(topSite, pinnedSites[0]) + assertEquals(topSite.title, pinnedSites[0].title) + assertEquals(topSite.url, pinnedSites[0].url) + + } @Test fun testRemovingTopSite() { diff --git a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/PinnedSiteDao.kt b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/PinnedSiteDao.kt index a3c920015d0..0546f369722 100644 --- a/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/PinnedSiteDao.kt +++ b/components/feature/top-sites/src/main/java/mozilla/components/feature/top/sites/db/PinnedSiteDao.kt @@ -5,11 +5,7 @@ package mozilla.components.feature.top.sites.db import androidx.annotation.WorkerThread -import androidx.room.Dao -import androidx.room.Delete -import androidx.room.Insert -import androidx.room.Query -import androidx.room.Transaction +import androidx.room.* /** * Internal DAO for accessing [PinnedSiteEntity] instances. @@ -20,6 +16,10 @@ internal interface PinnedSiteDao { @Insert fun insertPinnedSite(site: PinnedSiteEntity): Long + @WorkerThread + @Update + fun updatePinnedSite(site: PinnedSiteEntity) + @WorkerThread @Delete fun deletePinnedSite(site: PinnedSiteEntity)