Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into feat/map/ui
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/com/android/periodpals/MainActivity.kt
  • Loading branch information
taghizadlaura committed Oct 14, 2024
2 parents cdea07f + 3c9ecc7 commit fc9126c
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 46 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
branches:
- main
- 'setup/**'
- 'feat/**'

pull_request:
types:
Expand Down Expand Up @@ -40,6 +42,16 @@ jobs:
distribution: "temurin"
java-version: "17"

# Hello Hello, Alonso here ^_~
# For whatever reason Android SDK is weird and I can't get the emulator to work
# vvv this new plugin should install v12.0 that was published Sep 2024 to be updated
- name: Setup Android SDK
uses: Swisyn/setup-android-sdk@v1
with:
cmdline-tools-version: 11076708
##TODO: Check if I need to install adb and avdmanager manually with cli cmds


# Caching is a very useful part of a CI, as a workflow is executed in a clean environment every time,
# this means that one would need to re-download and re-process gradle files for every run. Which is very time consuming.
#
Expand All @@ -66,7 +78,7 @@ jobs:
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
disable-animations: true
script: echo "Generated AVD snapshot for caching."

- name: Grant execute permission for gradlew
Expand Down Expand Up @@ -97,8 +109,9 @@ jobs:
api-level: 34
target: google_apis
arch: x86_64
avd-name: github
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -skin 1080x1920
disable-animations: true
script: ./gradlew connectedCheck --parallel --build-cache

Expand Down
58 changes: 36 additions & 22 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,26 @@ android {

sonar {
properties {
property("sonar.projectKey", "PeriodPals_periodpals")
property("sonar.projectKey", "periodpals_periodpals")
property("sonar.organization", "periodpals")
property("sonar.host.url", "https://sonarcloud.io")
// Comma-separated paths to the various directories containing the *.xml JUnit report files.
// Each path may be absolute or relative to the project base directory.
property(
"sonar.junit.reportPaths",
"${project.layout.buildDirectory.get()}/test-results/testDebugunitTest/")
"sonar.junit.reportPaths",
"${project.layout.buildDirectory.get()}/test-results/testDebugunitTest/"
)
// Paths to xml files with Android Lint issues. If the main flavor is changed, this file will
// have to be changed too.
property(
"sonar.androidLint.reportPaths",
"${project.layout.buildDirectory.get()}/reports/lint-results-debug.xml")
"sonar.androidLint.reportPaths",
"${project.layout.buildDirectory.get()}/reports/lint-results-debug.xml"
)
// Paths to JaCoCo XML coverage report files.
property(
"sonar.coverage.jacoco.xmlReportPaths",
"${project.layout.buildDirectory.get()}/reports/jacoco/jacocoTestReport/jacocoTestReport.xml")
"sonar.coverage.jacoco.xmlReportPaths",
"${project.layout.buildDirectory.get()}/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"
)
}
}

Expand All @@ -134,6 +137,17 @@ dependencies {
// implementation(libs.androidx.fragment.ktx)
// implementation(libs.kotlinx.serialization.json)

implementation(libs.compose)
implementation(libs.mockk.v1120)
implementation(libs.androidx.ui.test.junit4.v105)
implementation(libs.androidx.ui.test.manifest.v105)

configurations.all {
resolutionStrategy {
force("androidx.test.ext:junit:1.1.5")
force("androidx.test.espresso:espresso-core:3.5.0")
}
}
// supabase setup
implementation(platform("io.github.jan-tennert.supabase:bom:3.0.0"))
implementation(libs.github.postgrest.kt)
Expand Down Expand Up @@ -204,26 +218,26 @@ tasks.register("jacocoTestReport", JacocoReport::class) {
}

val fileFilter =
listOf(
"**/R.class",
"**/R$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*Test*.*",
"android/**/*.*",
)
listOf(
"**/R.class",
"**/R$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*Test*.*",
"android/**/*.*",
)

val debugTree =
fileTree("${project.layout.buildDirectory.get()}/tmp/kotlin-classes/debug") {
exclude(fileFilter)
}
fileTree("${project.layout.buildDirectory.get()}/tmp/kotlin-classes/debug") {
exclude(fileFilter)
}

val mainSrc = "${project.layout.projectDirectory}/src/main/java"
sourceDirectories.setFrom(files(mainSrc))
classDirectories.setFrom(files(debugTree))
executionData.setFrom(
fileTree(project.layout.buildDirectory.get()) {
include("outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec")
include("outputs/code_coverage/debugAndroidTest/connected/*/coverage.ec")
})
fileTree(project.layout.buildDirectory.get()) {
include("outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec")
include("outputs/code_coverage/debugAndroidTest/connected/*/coverage.ec")
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.android.periodpals.ui.profile

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.test.ext.junit.runners.AndroidJUnit4
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class CreateProfileTest {

@get:Rule val composeTestRule = createComposeRule()

@Test
fun testProfileImageDisplayed() {
composeTestRule.setContent { CreateProfile() }

// Check if the profile image is displayed
composeTestRule.onNodeWithTag("profile_image").assertIsDisplayed()
}

@Test
fun testFormFieldsDisplayed() {
composeTestRule.setContent { CreateProfile() }

// Check if the form fields are displayed
composeTestRule.onNodeWithTag("email_field").assertIsDisplayed()
composeTestRule.onNodeWithTag("dob_field").assertIsDisplayed()
composeTestRule.onNodeWithTag("name_field").assertIsDisplayed()
composeTestRule.onNodeWithTag("description_field").assertIsDisplayed()
}

@Test
fun testSaveButtonClickWithValidDate() {
composeTestRule.setContent { CreateProfile() }

// Input valid date
composeTestRule.onNodeWithTag("dob_field").performTextInput("01/01/2000")

// Perform click on the save button
composeTestRule.onNodeWithTag("save_button").performClick()
composeTestRule.waitForIdle()

assertTrue(validateDate("01/01/2000"))
assertTrue(validateDate("31/12/1999"))
}

@Test
fun testSaveButtonClickWithInvalidDate() {
composeTestRule.setContent { CreateProfile() }

// Input invalid date
composeTestRule.onNodeWithTag("dob_field").performTextInput("invalid_date")

// Perform click on the save button
composeTestRule.onNodeWithTag("save_button").performClick()
composeTestRule.waitForIdle()

assertFalse(validateDate("32/01/2000")) // Invalid day
assertFalse(validateDate("01/13/2000")) // Invalid month
assertFalse(validateDate("01/01/abcd")) // Invalid year
assertFalse(validateDate("01-01-2000")) // Invalid format
assertFalse(validateDate("01/01")) // Incomplete date
}
}
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:theme="@style/Theme.PeriodPals"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name="com.android.periodpals.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.PeriodPals">
Expand All @@ -29,5 +29,4 @@
</intent-filter>
</activity>
</application>

</manifest>
17 changes: 3 additions & 14 deletions app/src/main/java/com/android/periodpals/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.PointerIcon.Companion.Text
import androidx.compose.ui.unit.dp
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
Expand Down Expand Up @@ -92,12 +93,8 @@ class MainActivity : ComponentActivity() {
@Composable
fun CountriesList(dispatcher: CoroutineDispatcher = Dispatchers.IO) {
var countries by remember { mutableStateOf<List<Country>>(listOf()) }
LaunchedEffect(Unit) {
withContext(dispatcher) {
countries = supabase.from("countries").select().decodeList<Country>()
}
}
LazyColumn {
LaunchedEffect(Unit) { withContext(dispatcher) { countries = listOf(Country(1, "eyyo pogger")) } }
LazyColumn {
items(
countries.size,
) { idx ->
Expand All @@ -109,14 +106,6 @@ fun CountriesList(dispatcher: CoroutineDispatcher = Dispatchers.IO) {
}
}

val supabase =
createSupabaseClient(
supabaseUrl = "https://bhhjdcvdcfrxczbudraf.supabase.co",
supabaseKey =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJoaGpkY3ZkY2ZyeGN6YnVkcmFmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mjc4ODA4MjMsImV4cCI6MjA0MzQ1NjgyM30.teiPmTsMGNbXBx808uX7enVVLdgxqn4ftvSKjIgfCyQ") {
install(Postgrest)
}

@Serializable
data class Country(
val id: Int,
Expand Down
Loading

0 comments on commit fc9126c

Please sign in to comment.