This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #23431 - Display the order of Contile Top Sites correctly
- Loading branch information
1 parent
5bd6f1c
commit af700ef
Showing
6 changed files
with
177 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.ext | ||
|
||
import mozilla.components.feature.top.sites.TopSite | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner | ||
import org.mozilla.fenix.settings.SupportUtils | ||
|
||
@RunWith(FenixRobolectricTestRunner::class) | ||
class TopSiteTest { | ||
|
||
val defaultGoogleTopSite = TopSite.Default( | ||
id = 1L, | ||
title = "Google", | ||
url = SupportUtils.GOOGLE_URL, | ||
createdAt = 0 | ||
) | ||
val providedSite1 = TopSite.Provided( | ||
id = 3, | ||
title = "Mozilla", | ||
url = "https://mozilla.com", | ||
clickUrl = "https://mozilla.com/click", | ||
imageUrl = "https://test.com/image2.jpg", | ||
impressionUrl = "https://example.com", | ||
createdAt = 3 | ||
) | ||
val providedSite2 = TopSite.Provided( | ||
id = 3, | ||
title = "Firefox", | ||
url = "https://firefox.com", | ||
clickUrl = "https://firefox.com/click", | ||
imageUrl = "https://test.com/image2.jpg", | ||
impressionUrl = "https://example.com", | ||
createdAt = 3 | ||
) | ||
val pinnedSite1 = TopSite.Pinned( | ||
id = 1L, | ||
title = "DuckDuckGo", | ||
url = "https://duckduckgo.com", | ||
createdAt = 0 | ||
) | ||
val pinnedSite2 = TopSite.Pinned( | ||
id = 1L, | ||
title = "Mozilla", | ||
url = "mozilla.org", | ||
createdAt = 0 | ||
) | ||
val frecentSite = TopSite.Frecent( | ||
id = 1L, | ||
title = "Mozilla", | ||
url = "mozilla.org", | ||
createdAt = 0 | ||
) | ||
|
||
@Test | ||
fun `GIVEN the default Google top site is the first item WHEN the list of top sites is sorted THEN the order doesn't change`() { | ||
val topSites = listOf( | ||
defaultGoogleTopSite, | ||
providedSite1, | ||
providedSite2, | ||
pinnedSite1, | ||
pinnedSite2, | ||
frecentSite | ||
) | ||
|
||
assertEquals(topSites.sort(), topSites) | ||
} | ||
|
||
@Test | ||
fun `GIVEN the default Google top site is after the provided top sites WHEN the list of top sites is sorted THEN the default Google top site should be first`() { | ||
val topSites = listOf( | ||
providedSite1, | ||
providedSite2, | ||
defaultGoogleTopSite, | ||
pinnedSite1, | ||
pinnedSite2, | ||
frecentSite | ||
) | ||
val expected = listOf( | ||
defaultGoogleTopSite, | ||
providedSite1, | ||
providedSite2, | ||
pinnedSite1, | ||
pinnedSite2, | ||
frecentSite | ||
) | ||
|
||
assertEquals(topSites.sort(), expected) | ||
} | ||
|
||
@Test | ||
fun `GIVEN the default Google top site is the last item WHEN the list of top sites is sorted THEN the default Google top site should be first`() { | ||
val topSites = listOf( | ||
providedSite1, | ||
providedSite2, | ||
pinnedSite1, | ||
pinnedSite2, | ||
frecentSite, | ||
defaultGoogleTopSite | ||
) | ||
val expected = listOf( | ||
defaultGoogleTopSite, | ||
providedSite1, | ||
providedSite2, | ||
pinnedSite1, | ||
pinnedSite2, | ||
frecentSite | ||
) | ||
|
||
assertEquals(topSites.sort(), expected) | ||
} | ||
} |