For #8651 - Add HistoryInteractor/Controller unit/ui tests
parent
fc0260d6ee
commit
9f3bbf1fb7
@ -0,0 +1,74 @@
|
||||
/* 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.ui.robots
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.helpers.click
|
||||
import org.mozilla.fenix.helpers.ext.waitNotNull
|
||||
|
||||
/**
|
||||
* Implementation of Robot Pattern for the History three dot menu.
|
||||
*/
|
||||
class ThreeDotMenuHistoryItemRobot {
|
||||
|
||||
class Transition {
|
||||
|
||||
fun clickCopy(interact: HistoryRobot.() -> Unit): HistoryRobot.Transition {
|
||||
copyButton().click()
|
||||
HistoryRobot().interact()
|
||||
return HistoryRobot.Transition()
|
||||
}
|
||||
|
||||
fun clickShare(interact: LibrarySubMenusMultipleSelectionToolbarRobot.() -> Unit):
|
||||
LibrarySubMenusMultipleSelectionToolbarRobot.Transition {
|
||||
|
||||
shareButton().click()
|
||||
|
||||
mDevice.waitNotNull(
|
||||
Until.findObject(
|
||||
By.text("ALL ACTIONS")
|
||||
), TestAssetHelper.waitingTime
|
||||
)
|
||||
|
||||
LibrarySubMenusMultipleSelectionToolbarRobot().interact()
|
||||
return LibrarySubMenusMultipleSelectionToolbarRobot.Transition()
|
||||
}
|
||||
|
||||
fun clickOpenInNormalTab(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
||||
openInNewNormalTabButton().click()
|
||||
BrowserRobot().interact()
|
||||
return BrowserRobot.Transition()
|
||||
}
|
||||
|
||||
fun clickOpenInPrivateTab(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
||||
openInNewPrivateTabButton().click()
|
||||
BrowserRobot().interact()
|
||||
return BrowserRobot.Transition()
|
||||
}
|
||||
|
||||
fun clickDelete(interact: HistoryRobot.() -> Unit): HistoryRobot.Transition {
|
||||
deleteButton().click()
|
||||
HistoryRobot().interact()
|
||||
return HistoryRobot.Transition()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyButton() = onView(withText(R.string.history_menu_copy_button))
|
||||
|
||||
private fun shareButton() = onView(withText(R.string.history_menu_share_button))
|
||||
|
||||
private fun openInNewNormalTabButton() =
|
||||
onView(withText(R.string.history_menu_open_in_new_tab_button))
|
||||
|
||||
private fun openInNewPrivateTabButton() =
|
||||
onView(withText(R.string.history_menu_open_in_private_tab_button))
|
||||
|
||||
private fun deleteButton() = onView(withText(R.string.history_delete_item))
|
@ -0,0 +1,124 @@
|
||||
/* 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.library.history
|
||||
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isTrue
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verifyAll
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||
|
||||
class HistoryInteractorTest {
|
||||
private val historyItem = HistoryItem(0, "title", "url", 0.toLong())
|
||||
val controller: HistoryController = mockk(relaxed = true)
|
||||
val interactor = HistoryInteractor(controller)
|
||||
|
||||
@Test
|
||||
fun onOpen() {
|
||||
interactor.open(historyItem)
|
||||
|
||||
verifyAll {
|
||||
controller.handleOpen(historyItem)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onSelect() {
|
||||
interactor.select(historyItem)
|
||||
|
||||
verifyAll {
|
||||
controller.handleSelect(historyItem)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onDeselect() {
|
||||
interactor.deselect(historyItem)
|
||||
|
||||
verifyAll {
|
||||
controller.handleDeselect(historyItem)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onBackPressed() {
|
||||
every {
|
||||
controller.handleBackPressed()
|
||||
} returns true
|
||||
|
||||
val backpressHandled = interactor.onBackPressed()
|
||||
|
||||
verifyAll {
|
||||
controller.handleBackPressed()
|
||||
}
|
||||
assertThat(backpressHandled).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onModeSwitched() {
|
||||
interactor.onModeSwitched()
|
||||
|
||||
verifyAll {
|
||||
controller.handleModeSwitched()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onCopyPressed() {
|
||||
interactor.onCopyPressed(historyItem)
|
||||
|
||||
verifyAll {
|
||||
controller.handleCopyUrl(historyItem)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onSharePressed() {
|
||||
interactor.onSharePressed(historyItem)
|
||||
|
||||
verifyAll {
|
||||
controller.handleShare(historyItem)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onOpenInNormalTab() {
|
||||
interactor.onOpenInNormalTab(historyItem)
|
||||
|
||||
verifyAll {
|
||||
controller.handleOpen(historyItem, BrowsingMode.Normal)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onOpenInPrivateTab() {
|
||||
interactor.onOpenInPrivateTab(historyItem)
|
||||
|
||||
verifyAll {
|
||||
controller.handleOpen(historyItem, BrowsingMode.Private)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onDeleteAll() {
|
||||
interactor.onDeleteAll()
|
||||
|
||||
verifyAll {
|
||||
controller.handleDeleteAll()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onDeleteSome() {
|
||||
val items = setOf(historyItem)
|
||||
|
||||
interactor.onDeleteSome(items)
|
||||
verifyAll {
|
||||
controller.handleDeleteSome(items)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue