Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a9a5068 authored by Jeremie Boulic's avatar Jeremie Boulic Committed by Android (Google) Code Review
Browse files

Merge "[DocsUI Peek] Simplify PeekUiTest" into main

parents dc6e88c4 66ea173e
Loading
Loading
Loading
Loading
+18 −26
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ class PeekUiTest : ActivityTestJunit4<FilesActivity?>() {
    @get:Rule
    val testFilesRule: TestFilesRule =
        TestFilesRule()
            .createFileInRoot(StubProvider.ROOT_0_ID, "image.png", "image/png")
            .createFileInRoot(StubProvider.ROOT_0_ID, "image.jpg", "image/jpeg")
            .createFileInRoot(StubProvider.ROOT_0_ID, "file0.log", "text/plain")

    private lateinit var peekBot: PeekBot
@@ -57,7 +57,14 @@ class PeekUiTest : ActivityTestJunit4<FilesActivity?>() {
        peekBot = PeekBot(device!!, context!!, TIMEOUT)
    }

    fun validatePeekContents(fileName: String) {
    private fun showAndCheckPreview(fileName: String) {
        peekBot.assertPeekHidden()
        bots.directory.selectDocument(fileName, 1)
        bots.main.clickActionItem("Get info")
        checkPreviewActive(fileName)
    }

    private fun checkPreviewActive(fileName: String) {
        peekBot.assertPeekActive()
        peekBot.assertHasTitle(fileName)
    }
@@ -65,28 +72,17 @@ class PeekUiTest : ActivityTestJunit4<FilesActivity?>() {
    @Test
    @Throws(Exception::class)
    fun testSequentialFilePreview() {
        peekBot.assertPeekHidden()
        bots.directory.selectDocument("image.png", 1)
        bots.main.clickActionItem("Get info")
        validatePeekContents("image.png")
        peekBot.hide()

        bots.directory.selectDocument("file0.log", 1)
        bots.main.clickActionItem("Get info")
        validatePeekContents("file0.log")
        showAndCheckPreview("image.jpg")
        peekBot.hide()
        showAndCheckPreview("file0.log")
    }

    @Test
    @Throws(Exception::class)
    fun testFileCantBeSelectedDuringFilePreview() {
        peekBot.assertPeekHidden()
        // Selecting a document should show the "1 selected" label.
        bots.directory.selectDocument("image.png", 1)
        bots.main.clickActionItem("Get info")
        validatePeekContents("image.png")
        showAndCheckPreview("file0.log")
        // The selection should not be possible, the "1 selected" label shouldn't show.
        val selectionHotspot: UiObject2 = bots.directory.findSelectionHotspot("image.png")
        val selectionHotspot: UiObject2 = bots.directory.findSelectionHotspot("file0.log")
        Assert.assertNull(selectionHotspot)
        val assertSelectionText = "1 selected"
        val timeout: Long = 1000
@@ -98,14 +94,12 @@ class PeekUiTest : ActivityTestJunit4<FilesActivity?>() {
    @Test
    @Throws(Exception::class)
    fun testPeekRestorationOnConfigurationChange() {
        bots.directory.selectDocument("image.png", 1)
        bots.main.clickActionItem("Get info")
        validatePeekContents("image.png")
        showAndCheckPreview("image.jpg")

        // Recreate the activity to simulate a configuration change (window resize, for example),
        // and ensure that the preview is restored.
        mActivityScenario!!.recreate()
        validatePeekContents("image.png")
        checkPreviewActive("image.jpg")

        peekBot.hide()
        // Ensure that the Peek overlay isn't showing when the activity gets recreated after the
@@ -115,18 +109,16 @@ class PeekUiTest : ActivityTestJunit4<FilesActivity?>() {

        bots.directory.selectDocument("file0.log", 1)
        bots.main.clickActionItem("Get info")
        validatePeekContents("file0.log")
        checkPreviewActive("file0.log")
        // Check Peek's contents when restoring a different preview.
        mActivityScenario!!.recreate()
        validatePeekContents("file0.log")
        checkPreviewActive("file0.log")
    }

    @Test
    @Throws(Exception::class)
    fun testNoPreview() {
        bots.directory.selectDocument("file0.log", 1)
        bots.main.clickActionItem("Get info")
        validatePeekContents("file0.log")
        showAndCheckPreview("file0.log")

        // Use the "No preview available" content description to ensure that the "No preview" shape
        // is showing.