@ -16,7 +16,6 @@ import mozilla.components.concept.storage.VisitType
import org.junit.Assert.assertEquals
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Before
import org.junit.Test
import org.junit.Test
import org.mozilla.fenix.library.history.History
class PagedHistoryProviderTest {
class PagedHistoryProviderTest {
@ -92,7 +91,7 @@ class PagedHistoryProviderTest {
coEvery { storage . getDetailedVisits ( any ( ) , any ( ) , any ( ) ) } returns emptyList ( )
coEvery { storage . getDetailedVisits ( any ( ) , any ( ) , any ( ) ) } returns emptyList ( )
coEvery { storage . getHistoryMetadataSince ( any ( ) ) } returns listOf ( historyEntry1 , historyEntry2 , historyEntry3 )
coEvery { storage . getHistoryMetadataSince ( any ( ) ) } returns listOf ( historyEntry1 , historyEntry2 , historyEntry3 )
var actualResults : List < History > ? = null
var actualResults : List < History DB > ? = null
provider . getHistory ( 10 , 5 ) {
provider . getHistory ( 10 , 5 ) {
actualResults = it
actualResults = it
}
}
@ -114,19 +113,19 @@ class PagedHistoryProviderTest {
}
}
val results = listOf (
val results = listOf (
History . Group (
History DB . Group (
title = historyEntry1 . key . searchTerm !! ,
title = historyEntry1 . key . searchTerm !! ,
visitedAt = historyEntry1 . createdAt ,
visitedAt = historyEntry1 . createdAt ,
// Results are de-duped by URL and sorted descending by createdAt/visitedAt
// Results are de-duped by URL and sorted descending by createdAt/visitedAt
items = listOf (
items = listOf (
History . Metadata (
History DB . Metadata (
title = historyEntry1 . title !! ,
title = historyEntry1 . title !! ,
url = historyEntry1 . key . url ,
url = historyEntry1 . key . url ,
visitedAt = historyEntry1 . createdAt ,
visitedAt = historyEntry1 . createdAt ,
totalViewTime = historyEntry1 . totalViewTime ,
totalViewTime = historyEntry1 . totalViewTime ,
historyMetadataKey = historyMetadataKey1
historyMetadataKey = historyMetadataKey1
) ,
) ,
History . Metadata (
History DB . Metadata (
title = historyEntry3 . title !! ,
title = historyEntry3 . title !! ,
url = historyEntry3 . key . url ,
url = historyEntry3 . key . url ,
visitedAt = historyEntry3 . createdAt ,
visitedAt = historyEntry3 . createdAt ,
@ -135,7 +134,7 @@ class PagedHistoryProviderTest {
)
)
)
)
) ,
) ,
History . Regular (
History DB . Regular (
title = visitInfo3 . title !! ,
title = visitInfo3 . title !! ,
url = visitInfo3 . url ,
url = visitInfo3 . url ,
visitedAt = visitInfo3 . visitTime
visitedAt = visitInfo3 . visitTime
@ -175,7 +174,7 @@ class PagedHistoryProviderTest {
coEvery { storage . getDetailedVisits ( any ( ) , any ( ) , any ( ) ) } returns emptyList ( )
coEvery { storage . getDetailedVisits ( any ( ) , any ( ) , any ( ) ) } returns emptyList ( )
coEvery { storage . getHistoryMetadataSince ( any ( ) ) } returns listOf ( historyEntry1 )
coEvery { storage . getHistoryMetadataSince ( any ( ) ) } returns listOf ( historyEntry1 )
var actualResults : List < History > ? = null
var actualResults : List < History DB > ? = null
provider . getHistory ( 0 , 5 ) {
provider . getHistory ( 0 , 5 ) {
actualResults = it
actualResults = it
}
}
@ -197,12 +196,12 @@ class PagedHistoryProviderTest {
}
}
val results = listOf (
val results = listOf (
History . Group (
History DB . Group (
title = historyEntry1 . key . searchTerm !! ,
title = historyEntry1 . key . searchTerm !! ,
visitedAt = historyEntry1 . createdAt ,
visitedAt = historyEntry1 . createdAt ,
// Results are de-duped by URL and sorted descending by createdAt/visitedAt
// Results are de-duped by URL and sorted descending by createdAt/visitedAt
items = listOf (
items = listOf (
History . Metadata (
History DB . Metadata (
title = historyEntry1 . title !! ,
title = historyEntry1 . title !! ,
url = historyEntry1 . key . url ,
url = historyEntry1 . key . url ,
visitedAt = historyEntry1 . createdAt ,
visitedAt = historyEntry1 . createdAt ,
@ -247,7 +246,7 @@ class PagedHistoryProviderTest {
coEvery { storage . getDetailedVisits ( any ( ) , any ( ) , any ( ) ) } returns emptyList ( )
coEvery { storage . getDetailedVisits ( any ( ) , any ( ) , any ( ) ) } returns emptyList ( )
coEvery { storage . getHistoryMetadataSince ( any ( ) ) } returns listOf ( historyEntry1 )
coEvery { storage . getHistoryMetadataSince ( any ( ) ) } returns listOf ( historyEntry1 )
var actualResults : List < History > ? = null
var actualResults : List < History DB > ? = null
provider . getHistory ( 0 , 5 ) {
provider . getHistory ( 0 , 5 ) {
actualResults = it
actualResults = it
}
}
@ -269,12 +268,12 @@ class PagedHistoryProviderTest {
}
}
val results = listOf (
val results = listOf (
History . Group (
History DB . Group (
title = historyEntry1 . key . searchTerm !! ,
title = historyEntry1 . key . searchTerm !! ,
visitedAt = historyEntry1 . createdAt ,
visitedAt = historyEntry1 . createdAt ,
// Results are de-duped by URL and sorted descending by createdAt/visitedAt
// Results are de-duped by URL and sorted descending by createdAt/visitedAt
items = listOf (
items = listOf (
History . Metadata (
History DB . Metadata (
title = historyEntry1 . title !! ,
title = historyEntry1 . title !! ,
url = historyEntry1 . key . url ,
url = historyEntry1 . key . url ,
visitedAt = historyEntry1 . createdAt ,
visitedAt = historyEntry1 . createdAt ,
@ -396,7 +395,7 @@ class PagedHistoryProviderTest {
coEvery { storage . getHistoryMetadataSince ( any ( ) ) } returns listOf ( historyEntry1 , historyEntry2 , historyEntry3 , historyEntry4 )
coEvery { storage . getHistoryMetadataSince ( any ( ) ) } returns listOf ( historyEntry1 , historyEntry2 , historyEntry3 , historyEntry4 )
var actualResults : List < History > ? = null
var actualResults : List < History DB > ? = null
provider . getHistory ( 10 , 5 ) {
provider . getHistory ( 10 , 5 ) {
actualResults = it
actualResults = it
}
}
@ -418,18 +417,18 @@ class PagedHistoryProviderTest {
}
}
val results = listOf (
val results = listOf (
History . Group (
History DB . Group (
title = historyEntry2 . key . searchTerm !! ,
title = historyEntry2 . key . searchTerm !! ,
visitedAt = historyEntry2 . createdAt ,
visitedAt = historyEntry2 . createdAt ,
items = listOf (
items = listOf (
History . Metadata (
History DB . Metadata (
title = historyEntry2 . title !! ,
title = historyEntry2 . title !! ,
url = historyEntry2 . key . url ,
url = historyEntry2 . key . url ,
visitedAt = historyEntry2 . createdAt ,
visitedAt = historyEntry2 . createdAt ,
totalViewTime = historyEntry2 . totalViewTime ,
totalViewTime = historyEntry2 . totalViewTime ,
historyMetadataKey = historyMetadataKey2
historyMetadataKey = historyMetadataKey2
) ,
) ,
History . Metadata (
History DB . Metadata (
title = historyEntry1 . title !! ,
title = historyEntry1 . title !! ,
url = historyEntry1 . key . url ,
url = historyEntry1 . key . url ,
visitedAt = historyEntry1 . createdAt ,
visitedAt = historyEntry1 . createdAt ,
@ -445,32 +444,32 @@ class PagedHistoryProviderTest {
@Test
@Test
fun `WHEN removeConsecutiveDuplicates is called THEN all consecutive duplicates must be removed` ( ) {
fun `WHEN removeConsecutiveDuplicates is called THEN all consecutive duplicates must be removed` ( ) {
val results = listOf (
val results = listOf (
History . Group (
History DB . Group (
title = " Group 1 " ,
title = " Group 1 " ,
visitedAt = 0 ,
visitedAt = 0 ,
items = emptyList ( )
items = emptyList ( )
) ,
) ,
History . Regular (
History DB . Regular (
title = " No duplicate item " ,
title = " No duplicate item " ,
url = " url " ,
url = " url " ,
visitedAt = 0
visitedAt = 0
) ,
) ,
History . Regular (
History DB . Regular (
title = " Duplicate item 1 " ,
title = " Duplicate item 1 " ,
url = " url " ,
url = " url " ,
visitedAt = 0
visitedAt = 0
) ,
) ,
History . Regular (
History DB . Regular (
title = " Duplicate item 2 " ,
title = " Duplicate item 2 " ,
url = " url " ,
url = " url " ,
visitedAt = 0
visitedAt = 0
) ,
) ,
History . Group (
History DB . Group (
title = " Group 5 " ,
title = " Group 5 " ,
visitedAt = 0 ,
visitedAt = 0 ,
items = emptyList ( )
items = emptyList ( )
) ,
) ,
History . Regular (
History DB . Regular (
title = " No duplicate item " ,
title = " No duplicate item " ,
url = " url " ,
url = " url " ,
visitedAt = 0
visitedAt = 0
@ -478,22 +477,22 @@ class PagedHistoryProviderTest {
) . removeConsecutiveDuplicates ( )
) . removeConsecutiveDuplicates ( )
val expectedList = listOf (
val expectedList = listOf (
History . Group (
History DB . Group (
title = " Group 1 " ,
title = " Group 1 " ,
visitedAt = 0 ,
visitedAt = 0 ,
items = emptyList ( )
items = emptyList ( )
) ,
) ,
History . Regular (
History DB . Regular (
title = " No duplicate item " ,
title = " No duplicate item " ,
url = " url " ,
url = " url " ,
visitedAt = 0
visitedAt = 0
) ,
) ,
History . Group (
History DB . Group (
title = " Group 5 " ,
title = " Group 5 " ,
visitedAt = 0 ,
visitedAt = 0 ,
items = emptyList ( )
items = emptyList ( )
) ,
) ,
History . Regular (
History DB . Regular (
title = " No duplicate item " ,
title = " No duplicate item " ,
url = " url " ,
url = " url " ,
visitedAt = 0
visitedAt = 0