From d7bc6f2c2710272cfdc9b1560538c93a5ed67111 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 27 Oct 2024 08:04:47 +0100 Subject: [PATCH] ui test: add delete testcase And remove an unreliable instrumented test which was disabled already. --- .../MainActivityInstrumentedTest.kt | 18 ------------ .../plees_tracker/MainActivityUITest.kt | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityInstrumentedTest.kt b/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityInstrumentedTest.kt index e7beec2..1a9679e 100644 --- a/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityInstrumentedTest.kt +++ b/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityInstrumentedTest.kt @@ -86,24 +86,6 @@ class MainActivityInstrumentedTest { assertEquals(1, database.sleepDao().getAll().size) } - // FIXME started to fail with: androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: an instance of android.widget.TextView and view.getText() with or without transformation to match: is "Import File" - // @Test - fun testDoesNotImportDuplicate() = runBlocking { - // Create one sleep. - val sleep = Sleep() - sleep.start = Calendar.getInstance().timeInMillis - sleep.stop = Calendar.getInstance().timeInMillis + Duration.ofHours(1).toMillis() - database.sleepDao().insert(sleep) - assertEquals(1, database.sleepDao().getAll().size) - - // Export. - exportToFile() - - // Import. - importFromFile() - assertEquals(1, database.sleepDao().getAll().size) - } - private fun exportToFile() { val intent = Intent() intent.data = Uri.fromFile(exportFile) diff --git a/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityUITest.kt b/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityUITest.kt index 163801f..179866b 100644 --- a/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityUITest.kt +++ b/app/src/androidTest/java/hu/vmiklos/plees_tracker/MainActivityUITest.kt @@ -10,6 +10,7 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By +import androidx.test.uiautomator.Direction import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.Until import org.junit.Assert.assertNotNull @@ -51,6 +52,34 @@ class MainActivityUITest { ) assertNotNull(sleeps) } + + @Test + fun testDelete() { + // Given a sleep: + val instrumentation = InstrumentationRegistry.getInstrumentation() + val device = UiDevice.getInstance(instrumentation) + val pkg = instrumentation.processName + val timeout: Long = 5000 + device.pressMenu() + val deleteAllSleep = device.wait(Until.findObject(By.text("Delete All Sleep")), timeout) + deleteAllSleep.click() + val yesButton = device.wait(Until.findObject(By.text("YES")), timeout) + yesButton.click() + val startStop = device.wait(Until.findObject(By.res(pkg, "start_stop")), timeout) + startStop.click() + startStop.click() + + // When deleting one: + val sleepSwipeable = device.wait(Until.findObject(By.res(pkg, "sleep_swipeable")), timeout) + sleepSwipeable.swipe(Direction.RIGHT, 1F) + + // Then make sure we have no sleeps: + val sleeps = device.wait( + Until.findObject(By.res(pkg, "fragment_stats_sleeps").text("0")), + timeout + ) + assertNotNull(sleeps) + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */