From 1efe17c8011e1cebdc8e6e425556b96f6ea24272 Mon Sep 17 00:00:00 2001 From: mcarare Date: Tue, 14 Jul 2020 15:45:54 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/12503: Add unit tests for permissions details view. --- .../AddonPermissionsDetailsFragmentTest.kt | 47 ---------------- .../addons/AddonPermissionsDetailsViewTest.kt | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+), 47 deletions(-) delete mode 100644 app/src/test/java/org/mozilla/fenix/addons/AddonPermissionsDetailsFragmentTest.kt create mode 100644 app/src/test/java/org/mozilla/fenix/addons/AddonPermissionsDetailsViewTest.kt diff --git a/app/src/test/java/org/mozilla/fenix/addons/AddonPermissionsDetailsFragmentTest.kt b/app/src/test/java/org/mozilla/fenix/addons/AddonPermissionsDetailsFragmentTest.kt deleted file mode 100644 index 3c767fe893..0000000000 --- a/app/src/test/java/org/mozilla/fenix/addons/AddonPermissionsDetailsFragmentTest.kt +++ /dev/null @@ -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 - ) - } -} diff --git a/app/src/test/java/org/mozilla/fenix/addons/AddonPermissionsDetailsViewTest.kt b/app/src/test/java/org/mozilla/fenix/addons/AddonPermissionsDetailsViewTest.kt new file mode 100644 index 0000000000..7a666c383c --- /dev/null +++ b/app/src/test/java/org/mozilla/fenix/addons/AddonPermissionsDetailsViewTest.kt @@ -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()) } + } +}