-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- espresso tests for treasure editor screen
- Loading branch information
Showing
16 changed files
with
267 additions
and
112 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
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
108 changes: 108 additions & 0 deletions
108
app/src/androidTestClassic/java/pl/marianjureczko/poszukiwacz/TreasureEditorScreenTest.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,108 @@ | ||
package pl.marianjureczko.poszukiwacz | ||
|
||
import androidx.compose.ui.test.assertTextEquals | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import dagger.hilt.android.testing.UninstallModules | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import pl.marianjureczko.poszukiwacz.model.Route | ||
import pl.marianjureczko.poszukiwacz.screen.treasureseditor.ADD_TREASURE_BUTTON | ||
import pl.marianjureczko.poszukiwacz.screen.treasureseditor.DO_PHOTO_TIP_BUTTON | ||
import pl.marianjureczko.poszukiwacz.screen.treasureseditor.RECORD_SOUND_TIP_BUTTON | ||
import pl.marianjureczko.poszukiwacz.screen.treasureseditor.STOP_RECORDING_BUTTON | ||
import pl.marianjureczko.poszukiwacz.screen.treasureseditor.TREASURE_ITEM_TEXT | ||
import pl.marianjureczko.poszukiwacz.shared.di.PortsModule | ||
import pl.marianjureczko.poszukiwacz.ui.components.NO_BUTTON | ||
import pl.marianjureczko.poszukiwacz.ui.components.YES_BUTTON | ||
|
||
@UninstallModules(PortsModule::class) | ||
@HiltAndroidTest | ||
class TreasureEditorScreenTest : UiTest() { | ||
|
||
var route: Route = TestPortsModule.getRouteFromStorage() | ||
// | ||
// @After | ||
// fun restoreRoute() { | ||
// TestPortsModule.assureRouteIsPresentInStorage() | ||
// route = TestPortsModule.getRouteFromStorage() | ||
// } | ||
|
||
@Test | ||
fun shouldShowAllTreasuresFromRoute_whenEditingTheRoute() { | ||
//given | ||
composeRule.waitForIdle() | ||
|
||
//when | ||
goToTreasuresEditorScreen(route.name) | ||
|
||
//then | ||
route.treasures.forEach { td -> | ||
getNode("$TREASURE_ITEM_TEXT ${td.id}") | ||
.assertTextEquals("[${td.id}] ${td.latitude} ${td.longitude}") | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldAddTreasure_whenTapOnPlus() { | ||
//given | ||
val newTreasureId = route.nextId() | ||
goToTreasuresEditorScreen(route.name) | ||
val lat = 1.0 | ||
val lng = 2.0 | ||
TestPortsModule.location.updateLocation(lat, lng) | ||
composeRule.waitForIdle() | ||
|
||
//when | ||
performTap(ADD_TREASURE_BUTTON) | ||
|
||
//then | ||
val treasureNode = getNode("$TREASURE_ITEM_TEXT $newTreasureId") | ||
treasureNode.assertTextEquals("[$newTreasureId] $lat $lng") | ||
|
||
val newTreasure = TestPortsModule.getRouteFromStorage().treasures.find { it.id == newTreasureId }!! | ||
assertEquals(lat, newTreasure.latitude, 0.001) | ||
assertEquals(lng, newTreasure.longitude, 0.001) | ||
assertEquals(null, newTreasure.tipFileName) | ||
assertEquals(null, newTreasure.photoFileName) | ||
} | ||
|
||
@Test | ||
fun shouldRecordAudioTip_whenTapOnMicrophone() { | ||
//given | ||
composeRule.waitForIdle() | ||
goToTreasuresEditorScreen(route.name) | ||
|
||
//when | ||
performTap("$RECORD_SOUND_TIP_BUTTON ${route.treasures[0].id}") | ||
|
||
//then | ||
Thread.sleep(100) | ||
performTap(STOP_RECORDING_BUTTON) | ||
TestPortsModule.storage.fileNotEmpty = true | ||
performTap("$RECORD_SOUND_TIP_BUTTON ${route.treasures[0].id}") | ||
getNode(YES_BUTTON).assertExists() | ||
performTap(NO_BUTTON) | ||
getNode(YES_BUTTON).assertDoesNotExist() | ||
} | ||
|
||
@Test | ||
fun shouldSavePhotoTip_whenTapOnCamera() { | ||
//given | ||
TestPortsModule.storage.fileNotEmpty = false | ||
composeRule.waitForIdle() | ||
goToTreasuresEditorScreen(route.name) | ||
TestPortsModule.camera.counter = 0 | ||
|
||
//when | ||
performTap("$DO_PHOTO_TIP_BUTTON ${route.treasures[0].id}") | ||
|
||
//then | ||
TestPortsModule.storage.fileNotEmpty = true | ||
assertEquals(1, TestPortsModule.camera.counter) | ||
composeRule.waitForIdle() | ||
performTap("$DO_PHOTO_TIP_BUTTON ${route.treasures[0].id}") | ||
getNode(YES_BUTTON).assertExists() | ||
performTap(NO_BUTTON) | ||
getNode(YES_BUTTON).assertDoesNotExist() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/androidTestClassic/java/pl/marianjureczko/poszukiwacz/UiTest.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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
package pl.marianjureczko.poszukiwacz | ||
|
||
import pl.marianjureczko.poszukiwacz.screen.main.EDIT_ROUTE_BUTTON | ||
|
||
open class UiTest: AbstractUITest() { | ||
|
||
fun goToTreasuresEditorScreen(routeName: String) { | ||
composeRule.waitForIdle() | ||
performTap(EDIT_ROUTE_BUTTON + routeName) | ||
} | ||
|
||
} |
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
Oops, something went wrong.