Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.

Commit 82c24a0

Browse files
committed
please god make it work
1 parent 8991774 commit 82c24a0

6 files changed

Lines changed: 73 additions & 20 deletions

File tree

app/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ dependencies {
5353
implementation(libs.androidx.compose.material3)
5454
implementation(libs.androidx.navigation.runtime.ktx)
5555
implementation(libs.androidx.navigation.compose)
56+
implementation(libs.androidx.work.testing)
5657
implementation(libs.maps.compose)
5758
implementation(libs.play.services.maps)
5859
implementation(libs.play.services.location)
5960
implementation(libs.places)
6061
testImplementation(libs.junit)
62+
testImplementation("org.robolectric:robolectric:4.16.1")
63+
testImplementation("androidx.test:core:1.6.1")
6164
androidTestImplementation(libs.androidx.junit)
6265
androidTestImplementation(libs.androidx.espresso.core)
6366
androidTestImplementation(platform(libs.androidx.compose.bom))

app/src/androidTest/java/fr/utbm/sy43/SignInAndAddPosologyUiTest.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,19 @@ import org.junit.Test
99
import org.junit.runner.RunWith
1010

1111
@RunWith(AndroidJUnit4::class)
12-
class SignUpAndAddPosologyUiTest {
12+
class SignInAndAddPosologyUiTest {
1313

1414
@get:Rule
1515
val composeTestRule = createAndroidComposeRule<MainActivity>()
1616

1717
@Test
1818
fun savePrescription_fillsFormAndSaves() {
1919

20-
composeTestRule.onNodeWithText("Don't have an account? Click here").performClick()
21-
composeTestRule.waitForIdle()
22-
23-
composeTestRule.onNodeWithTag("Name").performTextInput("John")
24-
composeTestRule.onNodeWithTag("Surname").performTextInput("Doe")
25-
composeTestRule.onNodeWithTag("Login").performTextInput("johndoe@aaaaaa.com")
20+
composeTestRule.onNodeWithTag("Email").performTextInput("johndoe@test.com")
2621
composeTestRule.onNodeWithTag("Password").performTextInput("johndoe1234")
2722
composeTestRule.waitForIdle()
2823

29-
composeTestRule.onNodeWithText("Sign up").performClick()
24+
composeTestRule.onNodeWithText("Sign in").performClick()
3025
composeTestRule.waitForIdle()
3126

3227
composeTestRule.onRoot().printToLog("UI_TREE")
@@ -48,6 +43,10 @@ class SignUpAndAddPosologyUiTest {
4843
composeTestRule.onNodeWithText("Save prescription").performClick()
4944
composeTestRule.waitForIdle()
5045

51-
composeTestRule.onNodeWithText("Doliprane").assertIsDisplayed()
46+
composeTestRule.onRoot().printToLog("UI_TREE")
47+
48+
composeTestRule.onAllNodesWithText("Doliprane", substring = true)
49+
.onFirst()
50+
.assertIsDisplayed()
5251
}
5352
}

app/src/main/java/fr/utbm/sy43/pilulito/ui/screens/LoginScreen.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import androidx.compose.runtime.setValue
2727
import androidx.compose.ui.Alignment
2828
import androidx.compose.ui.Modifier
2929
import androidx.compose.ui.graphics.Color
30+
import androidx.compose.ui.platform.testTag
3031
import androidx.compose.ui.text.font.FontWeight
3132
import androidx.compose.ui.text.input.PasswordVisualTransformation
3233
import androidx.compose.ui.tooling.preview.Preview
@@ -97,7 +98,7 @@ fun LoginScreen(
9798
},
9899
placeholder = { Text("johndoe@email.com") },
99100
singleLine = true,
100-
modifier = Modifier.fillMaxWidth(),
101+
modifier = Modifier.fillMaxWidth().testTag("Email"),
101102
colors = OutlinedTextFieldDefaults.colors(
102103
unfocusedContainerColor = Color.White,
103104
focusedContainerColor = Color.White,
@@ -126,7 +127,7 @@ fun LoginScreen(
126127
placeholder = { Text("Password") },
127128
singleLine = true,
128129
visualTransformation = PasswordVisualTransformation(),
129-
modifier = Modifier.fillMaxWidth(),
130+
modifier = Modifier.fillMaxWidth().testTag("Password"),
130131
colors = OutlinedTextFieldDefaults.colors(
131132
unfocusedContainerColor = Color.White,
132133
focusedContainerColor = Color.White,

app/src/main/java/fr/utbm/sy43/pilulito/ui/screens/SignupScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.runtime.*
99
import androidx.compose.ui.Alignment
1010
import androidx.compose.ui.Modifier
1111
import androidx.compose.ui.graphics.Color
12+
import androidx.compose.ui.platform.testTag
1213
import androidx.compose.ui.text.font.FontWeight
1314
import androidx.compose.ui.text.input.PasswordVisualTransformation
1415
import androidx.compose.ui.text.input.VisualTransformation
@@ -224,7 +225,7 @@ private fun LabeledField(
224225
placeholder = { Text(placeholder) },
225226
singleLine = true,
226227
visualTransformation = if (isPassword) PasswordVisualTransformation() else VisualTransformation.None,
227-
modifier = Modifier.fillMaxWidth(),
228+
modifier = Modifier.fillMaxWidth().testTag(label),
228229
colors = OutlinedTextFieldDefaults.colors(
229230
unfocusedContainerColor = Color.White,
230231
focusedContainerColor = Color.White,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
11
package fr.utbm.sy43
22

3+
import fr.utbm.sy43.pilulito.data.models.Drug
4+
import fr.utbm.sy43.pilulito.data.models.IntakeStatus
5+
import fr.utbm.sy43.pilulito.data.models.MedicationIntake
6+
import fr.utbm.sy43.pilulito.data.models.MedicationPlan
7+
import fr.utbm.sy43.pilulito.data.repositories.MedicationRepository
8+
import kotlinx.coroutines.flow.MutableStateFlow
9+
import kotlinx.coroutines.flow.StateFlow
10+
import kotlinx.coroutines.flow.asStateFlow
11+
12+
class FakeMedicationRepository : MedicationRepository {
13+
private val _drugs = MutableStateFlow<List<Drug>>(emptyList())
14+
override val drugs: StateFlow<List<Drug>> = _drugs.asStateFlow()
15+
16+
private val _plans = MutableStateFlow<List<MedicationPlan>>(emptyList())
17+
override val plans: StateFlow<List<MedicationPlan>> = _plans.asStateFlow()
18+
19+
private val _intakes = MutableStateFlow<List<MedicationIntake>>(emptyList())
20+
override val intakes: StateFlow<List<MedicationIntake>> = _intakes.asStateFlow()
21+
22+
var lastAddedPlan: MedicationPlan? = null
23+
var lastAddedIntakes: List<MedicationIntake>? = null
24+
25+
fun setDrugs(drugs: List<Drug>) { _drugs.value = drugs }
26+
27+
override suspend fun updateIntakeStatus(intakeId: String, status: IntakeStatus) {
28+
_intakes.value = _intakes.value.map {
29+
if (it.id == intakeId) it.copy(status = status) else it
30+
}
31+
}
32+
33+
override suspend fun addPlan(plan: MedicationPlan) {
34+
lastAddedPlan = plan
35+
_plans.value += plan
36+
}
37+
38+
override suspend fun addIntakes(intakes: List<MedicationIntake>) {
39+
lastAddedIntakes = intakes
40+
_intakes.value += intakes
41+
}
42+
}

app/src/test/java/fr/utbm/sy43/ValidationTest.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
package fr.utbm.sy43
22

3+
import android.app.Application
4+
import androidx.test.core.app.ApplicationProvider
5+
import fr.utbm.sy43.pilulito.data.models.Drug
6+
import fr.utbm.sy43.pilulito.data.repositories.MedicationRepository
7+
import fr.utbm.sy43.pilulito.viewmodels.AddPosologyViewModel
38
import org.junit.Test
4-
59
import org.junit.Assert.*
10+
import org.junit.runner.RunWith
11+
import org.robolectric.RobolectricTestRunner
12+
13+
@RunWith(RobolectricTestRunner::class)
14+
class ValidationTest {
615

7-
/**
8-
* Example local unit test, which will execute on the development machine (host).
9-
*
10-
* See [testing documentation](http://d.android.com/tools/testing).
11-
*/
12-
class ExampleUnitTest {
16+
private fun createViewModel(
17+
repo: MedicationRepository = FakeMedicationRepository(),
18+
application: Application = ApplicationProvider.getApplicationContext()
19+
): AddPosologyViewModel {
20+
return AddPosologyViewModel(application, repo)
21+
}
1322

1423
@Test
1524
fun onQuantityChanged_updatesQuantity_whenValid() {
@@ -21,7 +30,7 @@ class ExampleUnitTest {
2130
@Test
2231
fun onQuantityChanged_ignoresInvalidValue() {
2332
val viewModel = createViewModel()
24-
viewModel.onQuantityChanged(0) // your guard: qty >= 1
33+
viewModel.onQuantityChanged(0) // guard: qty >= 1
2534
assertEquals(1, viewModel.uiState.value.quantity) // unchanged from default
2635
}
2736

0 commit comments

Comments
 (0)