From d195ee2f6a520b72b51777a86bf8431078f3b5ef Mon Sep 17 00:00:00 2001 From: Alexander Gramiak Date: Sat, 15 Oct 2022 18:49:53 -0600 Subject: [PATCH] [fenix] Add and update tests for login address view holder --- .../logins/LoginsListViewHolderTest.kt | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/src/test/java/org/mozilla/fenix/settings/logins/LoginsListViewHolderTest.kt b/app/src/test/java/org/mozilla/fenix/settings/logins/LoginsListViewHolderTest.kt index e031ec53c2..b3d99e2878 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/logins/LoginsListViewHolderTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/logins/LoginsListViewHolderTest.kt @@ -25,7 +25,7 @@ class LoginsListViewHolderTest { private val baseLogin = SavedLogin( guid = "abcd", - origin = "mozilla.org", + origin = "https://www.mozilla.org", username = "admin", password = "password", timeLastUsed = 100L, @@ -33,32 +33,40 @@ class LoginsListViewHolderTest { private lateinit var interactor: SavedLoginsInteractor private lateinit var binding: LoginsItemBinding + private lateinit var holder: LoginsListViewHolder @Before fun setup() { binding = LoginsItemBinding.inflate(LayoutInflater.from(testContext)) interactor = mockk(relaxed = true) + holder = LoginsListViewHolder( + binding.root, + interactor, + ) every { testContext.components.core.icons } returns BrowserIcons(testContext, mockk(relaxed = true)) } @Test fun `bind url and username`() { - val holder = LoginsListViewHolder( - binding.root, - interactor, - ) holder.bind(baseLogin) assertEquals("mozilla.org", binding.webAddressView.text) assertEquals("admin", binding.usernameView.text) } + @Test + fun `GIVEN url has a mobile prefix WHEN url is binded THEN mobile prefix is stripped`() { + holder.bind(baseLogin.copy(origin = "https://m.mozilla.org")) + + assertEquals("mozilla.org", binding.webAddressView.text) + + holder.bind(baseLogin.copy(origin = "https://mobile.mozilla.org")) + + assertEquals("mozilla.org", binding.webAddressView.text) + } + @Test fun `call interactor on click`() { - val holder = LoginsListViewHolder( - binding.root, - interactor, - ) holder.bind(baseLogin) binding.root.performClick()