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.
- Loading branch information
Showing
10 changed files
with
153 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* 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 android.text.style.UnderlineSpan | ||
import android.widget.TextView | ||
import androidx.core.text.toSpannable | ||
|
||
/** | ||
* Adds an underline effect to the text displayed in the TextView. | ||
*/ | ||
fun TextView.addUnderline() { | ||
val currentText = text | ||
text = currentText.toSpannable().apply { | ||
setSpan(UnderlineSpan(), 0, currentText.length, 0) | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
...mozilla/fenix/home/sessioncontrol/viewholders/PrivateBrowsingDescriptionViewHolderTest.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,39 @@ | ||
/* 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.home.sessioncontrol.viewholders | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import kotlinx.android.synthetic.main.private_browsing_description.view.* | ||
import mozilla.components.support.test.robolectric.testContext | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner | ||
import org.mozilla.fenix.home.sessioncontrol.TabSessionInteractor | ||
|
||
@RunWith(FenixRobolectricTestRunner::class) | ||
class PrivateBrowsingDescriptionViewHolderTest { | ||
|
||
private lateinit var view: View | ||
private lateinit var interactor: TabSessionInteractor | ||
|
||
@Before | ||
fun setup() { | ||
view = LayoutInflater.from(testContext) | ||
.inflate(PrivateBrowsingDescriptionViewHolder.LAYOUT_ID, null) | ||
interactor = mockk(relaxed = true) | ||
} | ||
|
||
@Test | ||
fun `call interactor on click`() { | ||
PrivateBrowsingDescriptionViewHolder(view, interactor) | ||
|
||
view.private_session_common_myths.performClick() | ||
verify { interactor.onPrivateBrowsingLearnMoreClicked() } | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...illa/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingWhatsNewViewHolderTest.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,75 @@ | ||
/* 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.home.sessioncontrol.viewholders.onboarding | ||
|
||
import android.content.res.Resources | ||
import android.text.Spanned | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import androidx.core.text.HtmlCompat | ||
import androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.mockkStatic | ||
import io.mockk.unmockkStatic | ||
import io.mockk.verify | ||
import kotlinx.android.synthetic.main.onboarding_whats_new.view.* | ||
import mozilla.components.support.ktx.android.content.res.resolveAttribute | ||
import mozilla.components.support.test.robolectric.testContext | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner | ||
import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor | ||
|
||
@RunWith(FenixRobolectricTestRunner::class) | ||
class OnboardingWhatsNewViewHolderTest { | ||
|
||
private lateinit var view: View | ||
private lateinit var interactor: OnboardingInteractor | ||
|
||
@Before | ||
fun setup() { | ||
mockkStatic("mozilla.components.support.ktx.android.content.res.ThemeKt") | ||
view = LayoutInflater.from(testContext) | ||
.inflate(OnboardingWhatsNewViewHolder.LAYOUT_ID, null) | ||
interactor = mockk(relaxed = true) | ||
|
||
every { | ||
any<Resources.Theme>().resolveAttribute(R.attr.onboardingSelected) | ||
} returns R.color.onboarding_illustration_selected_normal_theme | ||
} | ||
|
||
@After | ||
fun teardown() { | ||
unmockkStatic("mozilla.components.support.ktx.android.content.res.ThemeKt") | ||
} | ||
|
||
@Test | ||
fun `sets and styles strings`() { | ||
OnboardingWhatsNewViewHolder(view, interactor) | ||
|
||
assertEquals( | ||
"Have questions about the redesigned Firefox Preview? Want to know what’s changed?", | ||
view.description_text.text | ||
) | ||
|
||
|
||
val getAnswersHtml = HtmlCompat.toHtml(view.get_answers.text as Spanned, TO_HTML_PARAGRAPH_LINES_CONSECUTIVE) | ||
assertTrue(getAnswersHtml, "<u>Get answers here</u>" in getAnswersHtml) | ||
} | ||
|
||
@Test | ||
fun `call interactor on click`() { | ||
OnboardingWhatsNewViewHolder(view, interactor) | ||
|
||
view.get_answers.performClick() | ||
verify { interactor.onWhatsNewGetAnswersClicked() } | ||
} | ||
} |