2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/12503: Add unit tests for permissions details view.

This commit is contained in:
mcarare 2020-07-14 15:45:54 +03:00 committed by Arturo Mejia
parent bfd879be4a
commit 1efe17c801
2 changed files with 53 additions and 47 deletions

View File

@ -1,47 +0,0 @@
/* 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.addons
import android.content.Intent.ACTION_VIEW
import androidx.core.net.toUri
import kotlinx.android.synthetic.main.fragment_add_on_permissions.*
import mozilla.components.feature.addons.Addon
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.createAddedTestFragmentInNavHostActivity
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.robolectric.Shadows.shadowOf
@RunWith(FenixRobolectricTestRunner::class)
class AddonPermissionsDetailsFragmentTest {
private val addon = Addon(
id = "",
translatableName = mapOf(
Addon.DEFAULT_LOCALE to "Some blank addon"
)
)
@Test
fun `trigger view intent when learn more is clicked`() {
val fragment = createAddedTestFragmentInNavHostActivity {
AddonPermissionsDetailsFragment().apply {
arguments = AddonPermissionsDetailsFragmentArgs(addon).toBundle()
}
}
assertEquals("Some blank addon", fragment.activity?.title)
fragment.learn_more_label.performClick()
val intent = shadowOf(fragment.activity).peekNextStartedActivity()
assertEquals(ACTION_VIEW, intent.action)
assertEquals(
"https://support.mozilla.org/kb/permission-request-messages-firefox-extensions".toUri(),
intent.data
)
}
}

View File

@ -0,0 +1,53 @@
/* 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.addons
import android.view.LayoutInflater
import android.view.View
import androidx.core.net.toUri
import io.mockk.mockk
import io.mockk.verify
import kotlinx.android.synthetic.main.fragment_add_on_permissions.*
import mozilla.components.feature.addons.Addon
import mozilla.components.support.test.robolectric.testContext
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class AddonPermissionsDetailsViewTest {
private lateinit var view: View
private lateinit var interactor: AddonPermissionsDetailsInteractor
private lateinit var permissionsDetailsView: AddonPermissionsDetailsView
private val addon = Addon(
id = "",
translatableName = mapOf(
Addon.DEFAULT_LOCALE to "Some blank addon"
)
)
private val learnMoreUrl =
"https://support.mozilla.org/kb/permission-request-messages-firefox-extensions"
@Before
fun setup() {
view = LayoutInflater.from(testContext).inflate(R.layout.fragment_add_on_permissions, null)
interactor = mockk(relaxed = true)
permissionsDetailsView = AddonPermissionsDetailsView(view, interactor)
}
@Test
fun `clicking learn more opens learn more page in browser`() {
permissionsDetailsView.bind(addon.copy(
rating = null
))
permissionsDetailsView.learn_more_label.performClick()
verify { interactor.openWebsite(learnMoreUrl.toUri()) }
}
}