2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] For issue https://github.com/mozilla-mobile/fenix/issues/5298 the same page appears in the History section multiple times

This commit is contained in:
Arturo Mejia 2021-11-19 18:35:16 -05:00
parent 7e446e3759
commit 5737a5533c
2 changed files with 88 additions and 1 deletions

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.components.history
import androidx.annotation.VisibleForTesting
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
import mozilla.components.concept.storage.VisitInfo
import mozilla.components.concept.storage.VisitType
@ -203,7 +204,8 @@ class DefaultPagedHistoryProvider(
}
)
return result.sortedByDescending { it.visitedAt }
return result.removeConsecutiveDuplicates()
.sortedByDescending { it.visitedAt }
}
private fun transformVisitInfoToHistoryItem(offset: Int): (id: Int, visit: VisitInfo) -> History.Regular {
@ -221,3 +223,18 @@ class DefaultPagedHistoryProvider(
}
}
}
@VisibleForTesting
internal fun List<History>.removeConsecutiveDuplicates(): List<History> {
var previousURL = ""
return filter {
var isNotDuplicate = true
previousURL = if (it is History.Regular) {
isNotDuplicate = it.url != previousURL
it.url
} else {
""
}
isNotDuplicate
}
}

View File

@ -452,4 +452,74 @@ class PagedHistoryProviderTest {
)
assertEquals(results, actualResults)
}
@Test
fun `WHEN removeConsecutiveDuplicates is called THEN all consecutive duplicates must be removed`() {
val results = listOf(
History.Group(
id = 1,
title = "Group 1",
visitedAt = 0,
items = emptyList()
),
History.Regular(
id = 2,
title = "No duplicate item",
url = "url",
visitedAt = 0
),
History.Regular(
id = 3,
title = "Duplicate item 1",
url = "url",
visitedAt = 0
),
History.Regular(
id = 4,
title = "Duplicate item 2",
url = "url",
visitedAt = 0
),
History.Group(
id = 5,
title = "Group 5",
visitedAt = 0,
items = emptyList()
),
History.Regular(
id = 6,
title = "No duplicate item",
url = "url",
visitedAt = 0
),
).removeConsecutiveDuplicates()
val expectedList = listOf(
History.Group(
id = 1,
title = "Group 1",
visitedAt = 0,
items = emptyList()
),
History.Regular(
id = 2,
title = "No duplicate item",
url = "url",
visitedAt = 0
),
History.Group(
id = 5,
title = "Group 5",
visitedAt = 0,
items = emptyList()
),
History.Regular(
id = 6,
title = "No duplicate item",
url = "url",
visitedAt = 0
),
)
assertEquals(expectedList, results)
}
}