Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a single activity #36

Merged
merged 8 commits into from Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 0 additions & 52 deletions .github/workflows/test.yml

This file was deleted.

7 changes: 6 additions & 1 deletion app/build.gradle
Expand Up @@ -68,6 +68,10 @@ android {
}

dependencies {
def lifecycle_version = '2.5.1'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"

def compose_version = '1.2.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
Expand All @@ -88,8 +92,9 @@ dependencies {
kapt "com.google.dagger:hilt-compiler:$hilt_version"

implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation 'androidx.navigation:navigation-compose:2.5.1'
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
implementation 'ovh.plrapps:mapcompose:2.1.4'
implementation 'com.google.accompanist:accompanist-systemuicontroller:0.25.1'

Expand Down
Expand Up @@ -25,33 +25,28 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import ru.spbu.depnav.data.model.MapInfo
import ru.spbu.depnav.data.model.Marker
import ru.spbu.depnav.data.model.MarkerText

/**
* Instrumentation texts for [AppDatabase].
*/
/** Instrumentation tests for [AppDatabase]'s DAOs. */
@RunWith(AndroidJUnit4::class)
class AppDatabaseTest {
class AppDatabaseDaosTest {
private lateinit var db: AppDatabase
private lateinit var mapInfoDao: MapInfoDao
private lateinit var markerDao: MarkerDao
private lateinit var markerTextDao: MarkerTextDao
private lateinit var markerWithTextDao: MarkerWithTextDao

/**
* Initializes an instance of a database and related DAOs.
*/
/** Initializes an instance of a database and related DAOs. */
@Before
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()
db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build()
mapInfoDao = db.mapInfoDao()
markerDao = db.markerDao()
markerTextDao = db.markerTextDao()
markerWithTextDao = db.markerWithTextDao()
}

/**
Expand All @@ -64,16 +59,14 @@ class AppDatabaseTest {

/* MapInfo tests */

/**
* Checks that [MapInfoDao.loadByName] returns a [MapInfo] with the queried name.
*/
/** Checks that [MapInfoDao.loadByName] returns a [MapInfo] with the queried name. */
@Test
fun loadByName_returnsMapInfoWithQueriedName() {
val expected = listOf(
MapInfo("abc", 100, 100, 1024, 1, 5),
MapInfo("cba", 100, 200, 512, 2, 100)
)
runBlocking { mapInfoDao.insertAll(*expected.toTypedArray()) }
runBlocking { mapInfoDao.insertAll(expected) }

val actual = runBlocking {
listOf(
Expand All @@ -87,24 +80,22 @@ class AppDatabaseTest {

/* Marker tests */

/**
* Checks that [MarkerDao.loadWithTextById] returns the queried [Marker].
*/
/** Checks that [MarkerWithTextDao.loadById] returns the queried [Marker]. */
@Test
fun loadWithTextById_returnsQueriedMarker() {
fun loadById_returnsQueriedMarker() {
val expected = mutableListOf<Pair<Marker, MarkerText>>()
for (id in listOf(1, 2, 5)) {
expected += Marker(id, Marker.MarkerType.OTHER, false, 1, 0.0, 0.0) to
MarkerText(id, MarkerText.LanguageId.EN, null, null)
}
runBlocking {
markerDao.insertAll(*expected.map { it.first }.toTypedArray())
markerTextDao.insertAll(*expected.map { it.second }.toTypedArray())
markerWithTextDao.insertMarkers(expected.map { it.first })
markerWithTextDao.insertMarkerTexts(expected.map { it.second })
}

for ((expectedMarker, markerText) in expected) {
val actual =
runBlocking { markerDao.loadWithTextById(expectedMarker.id, markerText.languageId) }
runBlocking { markerWithTextDao.loadById(expectedMarker.id, markerText.languageId) }
val (actualMarker, _) = actual.entries.firstOrNull()?.toPair() ?: (null to null)

assertEquals(1, actual.size)
Expand All @@ -113,10 +104,10 @@ class AppDatabaseTest {
}

/**
* Checks that [MarkerDao.loadWithTextById] returns a [MarkerText] with the specified language.
* Checks that [MarkerWithTextDao.loadById] returns a [MarkerText] with the specified language.
*/
@Test
fun loadWithTextById_returnedMarkerHasSpecifiedLanguage() {
fun loadById_returnsMarkerWithSpecifiedLanguage() {
val markersWithTexts = mutableMapOf<Marker, List<MarkerText>>()
for (id in listOf(1, 2, 5)) {
val marker = Marker(id, Marker.MarkerType.OTHER, false, 1, 0.0, 0.0)
Expand All @@ -126,14 +117,14 @@ class AppDatabaseTest {
)
}
runBlocking {
markerDao.insertAll(*markersWithTexts.keys.toTypedArray())
markerTextDao.insertAll(*markersWithTexts.values.flatten().toTypedArray())
markerWithTextDao.insertMarkers(markersWithTexts.keys)
markerWithTextDao.insertMarkerTexts(markersWithTexts.values.flatten())
}

for ((expectedMarker, markerTexts) in markersWithTexts) {
for (expectedMarkerText in markerTexts) {
val actual = runBlocking {
markerDao.loadWithTextById(expectedMarker.id, expectedMarkerText.languageId)
markerWithTextDao.loadById(expectedMarker.id, expectedMarkerText.languageId)
}
val actualMarkerTexts = actual.values.firstOrNull()

Expand All @@ -145,11 +136,11 @@ class AppDatabaseTest {
}

/**
* Checks that [MarkerDao.loadWithTextByFloor] returns all [Markers][Marker] placed on the
* Checks that [MarkerWithTextDao.loadByFloor] returns all [Markers][Marker] placed on the
* specified floor.
*/
@Test
fun loadWithTextByFloor_returnsAllMarkersWithSpecifiedFloor() {
fun loadByFloor_returnsAllMarkersWithSpecifiedFloor() {
val languageId = MarkerText.LanguageId.EN
val markers = mutableMapOf<Int, MutableList<Marker>>()
val markerTexts = mutableListOf<MarkerText>()
Expand All @@ -160,39 +151,45 @@ class AppDatabaseTest {
markerTexts += MarkerText(id++, languageId, null, null)
}
runBlocking {
markerDao.insertAll(*markers.values.flatten().toTypedArray())
markerTextDao.insertAll(*markerTexts.toTypedArray())
markerWithTextDao.insertMarkers(markers.values.flatten())
markerWithTextDao.insertMarkerTexts(markerTexts)
}

for (floor in markers.keys) {
val actualMarkers =
runBlocking { markerDao.loadWithTextByFloor(floor, languageId).keys }
runBlocking { markerWithTextDao.loadByFloor(floor, languageId).keys }

assert(actualMarkers.isNotEmpty())
for (marker in actualMarkers) assertEquals(floor, marker.floor)
}
}

/**
* Checks that [MarkerDao.loadWithTextByFloor] returns [MarkerTexts][MarkerText] with the
* Checks that [MarkerWithTextDao.loadByFloor] returns [MarkerTexts][MarkerText] with the
* specified language.
*/
@Test
fun loadWithTextByFloor_returnedMarkersHaveSpecifiedLanguage() {
fun loadByFloor_returnsMarkersWithSpecifiedLanguage() {
val floors = listOf(1, 2, 5)
var id = 1
for (floor in floors) runBlocking {
markerDao.insertAll(Marker(id, Marker.MarkerType.OTHER, false, floor, 0.0, 0.0))
for (languageId in MarkerText.LanguageId.values()) {
markerTextDao.insertAll(MarkerText(id, languageId, null, null))
for (floor in floors) {
with(markerWithTextDao) {
runBlocking {
insertMarkers(
listOf(Marker(id, Marker.MarkerType.OTHER, false, floor, 0.0, 0.0))
)
for (languageId in MarkerText.LanguageId.values()) {
insertMarkerTexts(listOf(MarkerText(id, languageId, null, null)))
}
}
}
id++
}

for (floor in floors) {
for (languageId in MarkerText.LanguageId.values()) {
val actual = runBlocking {
markerDao.loadWithTextByFloor(floor, languageId).values.flatten()
markerWithTextDao.loadByFloor(floor, languageId).values.flatten()
}

assert(actual.isNotEmpty())
Expand All @@ -204,56 +201,96 @@ class AppDatabaseTest {
/* MarkerText tests */

/**
* Checks that [MarkerTextDao.loadByTokens] returns all inserted [MarkerTexts][MarkerText] with
* the queried tokens on the default language (English).
* Checks that [MarkerWithTextDao.loadByTokens] returns all inserted [MarkerTexts][MarkerText]
* with the queried tokens on the default language (English).
*/
@Test
fun loadByTokensEnglish_returnsAllTextsWithAllQueriedTokensInDescription() {
val expectedTitle = "+"
val unexpectedTitle = "-"
val markerId = 1
val language = MarkerText.LanguageId.EN
val markerTexts = listOf(
MarkerText(1, language, expectedTitle, "Lorem ipsum dolor sit amet"),
MarkerText(2, language, expectedTitle, "123 lorem iPsUm"),
MarkerText(3, language, expectedTitle, "123 lorem a iPsUm"),
MarkerText(4, language, expectedTitle, "ipsum lorem"),
MarkerText(4, language, unexpectedTitle, "lorem"),
MarkerText(4, language, unexpectedTitle, "ipsum"),
MarkerText(4, language, unexpectedTitle, "lor ip"),
MarkerText(4, language, unexpectedTitle, ""),
MarkerText(markerId, language, expectedTitle, "Lorem ipsum dolor sit amet"),
MarkerText(markerId, language, expectedTitle, "123 lorem iPsUm"),
MarkerText(markerId, language, expectedTitle, "123 lorem a iPsUm"),
MarkerText(markerId, language, expectedTitle, "ipsum lorem"),
MarkerText(markerId, language, unexpectedTitle, "lorem"),
MarkerText(markerId, language, unexpectedTitle, "ipsum"),
MarkerText(markerId, language, unexpectedTitle, "lor ip"),
MarkerText(markerId, language, unexpectedTitle, ""),
)
runBlocking { markerTextDao.insertAll(*markerTexts.toTypedArray()) }
runBlocking {
markerWithTextDao.insertMarkerTexts(markerTexts)
// Marker required because all MarkerTexts must have an associated marker
markerWithTextDao.insertMarkers(
listOf(Marker(markerId, Marker.MarkerType.WC, false, 1, 0.0, 0.0))
)
}

val actual = runBlocking { markerTextDao.loadByTokens("Lorem ipsum", language) }
val actual = runBlocking { markerWithTextDao.loadByTokens("Lorem ipsum", language).keys }

actual.forEach { assertEquals(expectedTitle, it.title) }
assertEquals(markerTexts.count { it.title == expectedTitle }, actual.size)
}

/**
* Checks that [MarkerTextDao.loadByTokens] returns all inserted [MarkerTexts][MarkerText] with
* the queried tokens on a non-default language.
* Checks that [MarkerWithTextDao.loadByTokens] returns all inserted [MarkerTexts][MarkerText]
* with the queried tokens on a non-default language.
*/
@Test
fun loadByTokensNotEnglish_returnsAllTextsWithAllQueriedTokensInDescription() {
val expectedTitle = "+"
val unexpectedTitle = "-"
val markerId = 1
val language = MarkerText.LanguageId.RU
val markerTexts = listOf(
MarkerText(1, language, expectedTitle, "Лорем ипсум долор сит амет"),
MarkerText(2, language, expectedTitle, "123 лорем иПсУм"),
MarkerText(3, language, expectedTitle, "123 лорем а иПсУм"),
MarkerText(4, language, expectedTitle, "ипсум лорем"),
MarkerText(4, language, unexpectedTitle, "лорем"),
MarkerText(4, language, unexpectedTitle, "ипсум"),
MarkerText(4, language, unexpectedTitle, "лор ип"),
MarkerText(4, language, unexpectedTitle, ""),
MarkerText(markerId, language, expectedTitle, "Лорем ипсум долор сит амет"),
MarkerText(markerId, language, expectedTitle, "123 лорем иПсУм"),
MarkerText(markerId, language, expectedTitle, "123 лорем а иПсУм"),
MarkerText(markerId, language, expectedTitle, "ипсум лорем"),
MarkerText(markerId, language, unexpectedTitle, "лорем"),
MarkerText(markerId, language, unexpectedTitle, "ипсум"),
MarkerText(markerId, language, unexpectedTitle, "лор ип"),
MarkerText(markerId, language, unexpectedTitle, ""),
)
runBlocking { markerTextDao.insertAll(*markerTexts.toTypedArray()) }
runBlocking {
markerWithTextDao.insertMarkerTexts(markerTexts)
// Marker required because all MarkerTexts must have an associated marker
markerWithTextDao.insertMarkers(
listOf(Marker(markerId, Marker.MarkerType.WC, false, 1, 0.0, 0.0))
)
}

val actual = runBlocking { markerTextDao.loadByTokens("Лорем ипсум", language) }
val actual = runBlocking { markerWithTextDao.loadByTokens("Лорем ипсум", language).keys }

actual.forEach { assertEquals(expectedTitle, it.title) }
assertEquals(markerTexts.count { it.title == expectedTitle }, actual.size)
}

/**
* Checks that [MarkerWithTextDao.loadByTokens] returns a single Marker for each MarkerText and
* that it has a corresponding ID.
*/
@Test
fun loadByTokens_returnsSingleMarkerWithCorrectIdForEachMarkerText() {
val title = "title"
val language = MarkerText.LanguageId.EN
val markersWithText = mutableMapOf<Marker, MarkerText>()
for (id in listOf(1, 2, 5)) {
val marker = Marker(id, Marker.MarkerType.OTHER, false, 1, 0.0, 0.0)
markersWithText[marker] = MarkerText(id, language, title, null)
}
runBlocking {
markerWithTextDao.insertMarkers(markersWithText.keys)
markerWithTextDao.insertMarkerTexts(markersWithText.values)
}

val actual = runBlocking { markerWithTextDao.loadByTokens(title, language) }

for ((markerText, markers) in actual) {
assertTrue(markers.size == 1)
assertEquals(markerText.markerId, markers.first().id)
}
}
}
3 changes: 0 additions & 3 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -10,9 +10,6 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.DepNav">
<activity
android:name=".SearchActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
Expand Down