Skip to content

Commit

Permalink
ui test: add delete testcase
Browse files Browse the repository at this point in the history
And remove an unreliable instrumented test which was disabled already.
  • Loading branch information
vmiklos committed Oct 27, 2024
1 parent 329bce2 commit d7bc6f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: */

0 comments on commit d7bc6f2

Please sign in to comment.