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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
165 additions
and
90 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
88 changes: 88 additions & 0 deletions
88
app/src/test/java/org/mozilla/fenix/settings/logins/SavedLoginsSortingStrategyMenuTest.kt
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,88 @@ | ||
/* 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.settings.logins | ||
|
||
import android.content.Context | ||
import androidx.appcompat.view.ContextThemeWrapper | ||
import io.mockk.Runs | ||
import io.mockk.every | ||
import io.mockk.just | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import mozilla.components.concept.menu.candidate.HighPriorityHighlightEffect | ||
import mozilla.components.support.ktx.android.content.getColorFromAttr | ||
import mozilla.components.support.test.robolectric.testContext | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNull | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.ext.components | ||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner | ||
import org.mozilla.fenix.settings.logins.SavedLoginsSortingStrategyMenu.Item | ||
import org.mozilla.fenix.settings.logins.interactor.SavedLoginsInteractor | ||
|
||
@RunWith(FenixRobolectricTestRunner::class) | ||
class SavedLoginsSortingStrategyMenuTest { | ||
|
||
private lateinit var context: Context | ||
private lateinit var interactor: SavedLoginsInteractor | ||
private lateinit var menu: SavedLoginsSortingStrategyMenu | ||
|
||
@Before | ||
fun setup() { | ||
context = ContextThemeWrapper(testContext, R.style.NormalTheme) | ||
interactor = mockk() | ||
menu = SavedLoginsSortingStrategyMenu(context, interactor) | ||
} | ||
|
||
@Test | ||
fun `item enum can be deserialized from string`() { | ||
assertEquals(Item.AlphabeticallySort, Item.fromString("ALPHABETICALLY")) | ||
assertEquals(Item.LastUsedSort, Item.fromString("LAST_USED")) | ||
assertEquals(Item.AlphabeticallySort, Item.fromString("OTHER")) | ||
} | ||
|
||
@Test | ||
fun `effect is set on alphabetical sort candidate`() { | ||
val (name, lastUsed) = menu.menuItems(Item.AlphabeticallySort) | ||
assertEquals( | ||
HighPriorityHighlightEffect(context.getColorFromAttr(R.attr.colorControlHighlight)), | ||
name.effect | ||
) | ||
assertNull(lastUsed.effect) | ||
} | ||
|
||
@Test | ||
fun `effect is set on last used sort candidate`() { | ||
val (name, lastUsed) = menu.menuItems(Item.LastUsedSort) | ||
assertNull(name.effect) | ||
assertEquals( | ||
HighPriorityHighlightEffect(context.getColorFromAttr(R.attr.colorControlHighlight)), | ||
lastUsed.effect | ||
) | ||
} | ||
|
||
@Test | ||
fun `candidates call interactor on click`() { | ||
val (name, lastUsed) = menu.menuItems(Item.AlphabeticallySort) | ||
every { interactor.onSortingStrategyChanged(any()) } just Runs | ||
|
||
name.onClick() | ||
verify { | ||
interactor.onSortingStrategyChanged( | ||
SortingStrategy.Alphabetically(context.components.publicSuffixList) | ||
) | ||
} | ||
|
||
lastUsed.onClick() | ||
verify { | ||
interactor.onSortingStrategyChanged( | ||
SortingStrategy.LastUsed | ||
) | ||
} | ||
} | ||
} |