Skip to content

Commit

Permalink
Merge pull request #3 from agstack/feature/clean-architecture
Browse files Browse the repository at this point in the history
Feature/clean architecture
  • Loading branch information
lucienshema authored Nov 26, 2024
2 parents ebd565b + 41653f8 commit a888883
Show file tree
Hide file tree
Showing 117 changed files with 6,994 additions and 4,399 deletions.
16 changes: 16 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '11'
}
buildFeatures {
compose true
Expand Down Expand Up @@ -139,7 +139,9 @@ dependencies {
implementation 'androidx.test:monitor:1.7.2'
implementation 'androidx.test.ext:junit-ktx:1.2.1'
implementation 'androidx.compose.ui:ui-test-junit4-android:1.7.5'
implementation 'com.google.android.gms:play-services-phenotype:17.0.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.testng:testng:6.9.6'

// Paging
def paging_version = "3.3.4"
Expand Down Expand Up @@ -217,7 +219,6 @@ dependencies {
testImplementation 'androidx.compose.ui:ui-test-junit4-android:1.7.5'
testImplementation 'androidx.arch.core:core-testing:2.2.0'
testImplementation "com.google.truth:truth:1.1.3"
testImplementation "org.robolectric:robolectric:4.10.3"
testImplementation "io.mockk:mockk:1.13.7"
testImplementation "io.mockk:mockk-android:1.13.5"
testImplementation "org.robolectric:robolectric:4.9"
Expand All @@ -231,5 +232,13 @@ dependencies {
androidTestImplementation "io.mockk:mockk-android:1.13.5"
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.48'

androidTestImplementation 'androidx.test.ext:junit:1.2.1'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.7.5"

debugImplementation("androidx.compose.ui:ui-test-manifest:1.7.5")
//
// implementation("group:artifact") {
// exclude group: "org.junit.jupiter", module: "junit-jupiter-engine"
// }
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.technoserve.farmcollector.ui.components

import org.junit.Assert.*

import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

class FakeMapViewModel : ViewModel() {
var coordinatesCleared = false

fun clearCoordinates() {
coordinatesCleared = true
}
}

@RunWith(AndroidJUnit4::class)
class KeepPolygonDialogIntegrationTest {

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun testKeepPolygonDialogClearsCoordinatesAndCapturesNew() {
val fakeViewModel = FakeMapViewModel()

composeTestRule.setContent {
KeepPolygonDialog(
onDismiss = {},
onKeepExisting = {},
onCaptureNew = {
fakeViewModel.clearCoordinates()
}
)
}

// Click the "Capture New" button
composeTestRule.onNodeWithText("Capture New").performClick()

// Assert that coordinates were cleared
assert(fakeViewModel.coordinatesCleared)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.performClick
import androidx.navigation.NavController
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import io.mockk.mockk
import io.mockk.verify
import org.technoserve.farmcollector.ui.screens.settings.BottomSidebar


class BottomBarKtTest{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ import io.mockk.just
import io.mockk.mockk
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test
import org.mockito.Mockito.verify
import org.technoserve.farmcollector.ui.screens.settings.LanguageSelector
import org.technoserve.farmcollector.viewmodels.LanguageViewModel


// Mock Language class
data class Language(val displayName: String)

// Mock ViewModel
class LanguageViewModel : ViewModel() {
private val _currentLanguage = MutableStateFlow(Language("English"))
private val _currentLanguage = MutableStateFlow(
org.technoserve.farmcollector.database.models.Language(
"English"
)
)
val currentLanguage: StateFlow<Language> get() = _currentLanguage

fun selectLanguage(language: Language, context: Context) {
Expand All @@ -32,7 +37,7 @@ class LanguageViewModel : ViewModel() {
}


class LanguageUIKtTest{
class LanguageSelectorKtTest{
@get:Rule
val composeTestRule = createComposeRule()

Expand All @@ -41,7 +46,10 @@ class LanguageUIKtTest{
@Test
fun languageSelector_displaysCurrentLanguage() {
val mockViewModel = mockk<LanguageViewModel>(relaxed = true)
val languages = listOf(Language("English"), Language("French"))
val languages = listOf(
org.technoserve.farmcollector.database.models.Language("English"),
org.technoserve.farmcollector.database.models.Language("French")
)
val currentLanguage = MutableStateFlow(languages[0]) // English

every { mockViewModel.currentLanguage } returns currentLanguage
Expand All @@ -57,7 +65,10 @@ class LanguageUIKtTest{
@Test
fun languageSelector_opensDropdownOnClick() {
val mockViewModel = mockk<LanguageViewModel>(relaxed = true)
val languages = listOf(Language("English"), Language("French"))
val languages = listOf(
org.technoserve.farmcollector.database.models.Language("English"),
org.technoserve.farmcollector.database.models.Language("French")
)
val currentLanguage = MutableStateFlow(languages[0]) // English

every { mockViewModel.currentLanguage } returns currentLanguage
Expand All @@ -77,7 +88,10 @@ class LanguageUIKtTest{
@Test
fun languageSelector_selectsLanguageOnClick() {
val mockViewModel = mockk<LanguageViewModel>(relaxed = true)
val languages = listOf(Language("English"), Language("French"))
val languages = listOf(
org.technoserve.farmcollector.database.models.Language("English"),
org.technoserve.farmcollector.database.models.Language("French")
)
val currentLanguage = MutableStateFlow(languages[0]) // English

every { mockViewModel.currentLanguage } returns currentLanguage
Expand All @@ -94,6 +108,9 @@ class LanguageUIKtTest{
composeTestRule.onNodeWithText("French").performClick()

// Verify that selectLanguage was called with the correct language
verify { mockViewModel.selectLanguage(Language("French"), mockContext) }
verify { mockViewModel.selectLanguage(
org.technoserve.farmcollector.database.models.Language(
"French"
), mockContext) }
}
}
44 changes: 44 additions & 0 deletions app/src/main/assets/migrations/migration_12_16.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- Step 1: Create a new temporary table with the updated schema
CREATE TABLE new_Farms (
siteId INTEGER NOT NULL,
remote_id BLOB NOT NULL,
farmerPhoto TEXT NOT NULL,
farmerName TEXT NOT NULL,
memberId TEXT NOT NULL,
village TEXT NOT NULL,
district TEXT NOT NULL,
purchases REAL,
size REAL NOT NULL,
latitude TEXT NOT NULL,
longitude TEXT NOT NULL,
coordinates TEXT,
synced INTEGER NOT NULL DEFAULT 0,
scheduledForSync INTEGER NOT NULL DEFAULT 0,
createdAt INTEGER NOT NULL,
updatedAt INTEGER NOT NULL,
needsUpdate INTEGER NOT NULL DEFAULT 0,
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
FOREIGN KEY (siteId)
REFERENCES CollectionSites (siteId)
ON UPDATE NO ACTION
ON DELETE CASCADE
);

-- Step 2: Copy data from the old table to the new table, setting needsUpdate to 0
INSERT INTO new_Farms (
siteId, remote_id, farmerPhoto, farmerName, memberId,
village, district, purchases, size, latitude, longitude,
coordinates, synced, scheduledForSync, createdAt, updatedAt, needsUpdate, id
)
SELECT
siteId, remote_id, farmerPhoto, farmerName, memberId,
village, district, purchases, size, latitude, longitude,
coordinates, synced, scheduledForSync, createdAt, updatedAt, 0 AS needsUpdate, id
FROM Farms;

-- Step 3: Drop the old table
DROP TABLE Farms;

-- Step 4: Rename the new table to the original table name
ALTER TABLE new_Farms RENAME TO Farms;

44 changes: 44 additions & 0 deletions app/src/main/assets/migrations/migration_15_16.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
CREATE TABLE new_Farms (
siteId INTEGER NOT NULL,
remote_id BLOB NOT NULL,
farmerPhoto TEXT NOT NULL,
farmerName TEXT NOT NULL,
memberId TEXT NOT NULL,
village TEXT NOT NULL,
district TEXT NOT NULL,
purchases REAL,
size REAL NOT NULL,
latitude TEXT NOT NULL,
longitude TEXT NOT NULL,
coordinates TEXT,
synced INTEGER NOT NULL DEFAULT 0,
scheduledForSync INTEGER NOT NULL DEFAULT 0,
createdAt INTEGER NOT NULL,
updatedAt INTEGER NOT NULL,
needsUpdate INTEGER NOT NULL DEFAULT 0,
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
FOREIGN KEY (siteId)
REFERENCES CollectionSites (siteId) ON UPDATE NO ACTION
ON DELETE CASCADE
)


// Step 2: Copy data from the old table to the new table, setting needsUpdate to 0

INSERT INTO new_Farms (
siteId, remote_id, farmerPhoto, farmerName, memberId,
village, district, purchases, size, latitude, longitude,
coordinates, synced, scheduledForSync, createdAt, updatedAt, needsUpdate, id
)
SELECT
siteId, remote_id, farmerPhoto, farmerName, memberId,
village, district, purchases, size, latitude, longitude,
coordinates, synced, scheduledForSync, createdAt, updatedAt,0 AS needsUpdate, id
FROM Farms


// Step 3: Drop the old table
DROP TABLE Farms

// Step 4: Rename the new table to the original table name
"ALTER TABLE new_Farms RENAME TO Farms"
Loading

0 comments on commit a888883

Please sign in to comment.