Snapshot: Filtro de data corrigido para dd/mm/aa
This commit is contained in:
69
app/src/test/java/com/example/ExampleRobolectricTest.kt
Normal file
69
app/src/test/java/com/example/ExampleRobolectricTest.kt
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.example
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.example.data.local.AppDatabase
|
||||
import com.example.data.remote.GoogleSheetsSyncService
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
import kotlinx.coroutines.flow.first
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34])
|
||||
class ExampleRobolectricTest {
|
||||
|
||||
@Test
|
||||
fun `read string from context`() {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
val appName = context.getString(R.string.app_name)
|
||||
assertEquals("Cargill Parada OS", appName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `inspect project sheet`() {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
val service = GoogleSheetsSyncService(context)
|
||||
println("--- INSPECTING PROJECT SHEET ---")
|
||||
try {
|
||||
val values = service.fetchValues("project!A1:Z50")
|
||||
println("Fetched ${values.size} rows with columns up to Z")
|
||||
for ((index, row) in values.withIndex()) {
|
||||
println("Row $index: $row")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
println("Failed to fetch sheet: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
println("--- END INSPECTING ---")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `diagnose synchronization backend`() {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
val db = androidx.room.Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build()
|
||||
val repository = com.example.data.repository.MaintenanceRepository(db.maintenanceDao(), context)
|
||||
|
||||
println("--- STARTING SYNCHRONIZE DIAGNOSTIC UPDATED ---")
|
||||
try {
|
||||
val result = kotlinx.coroutines.runBlocking {
|
||||
val r = repository.synchronizeWithBackend()
|
||||
println("Sync Result: $r")
|
||||
val list = repository.allActivities.first()
|
||||
println("Total activities in database: ${list.size}")
|
||||
list.forEach { act ->
|
||||
println(" OS: ${act.numeroOs}, Desc: ${act.descricao}, Setor: ${act.setor}, Equipe: ${act.equipe}, Pct: ${act.percentualExecucao}")
|
||||
}
|
||||
r
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
println("Sync threw exception: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
println("--- END SYNCHRONIZE DIAGNOSTIC ---")
|
||||
db.close()
|
||||
}
|
||||
}
|
||||
85
app/src/test/java/com/example/ExampleUnitTest.kt
Normal file
85
app/src/test/java/com/example/ExampleUnitTest.kt
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.example
|
||||
|
||||
import com.example.data.model.extractDateOnly
|
||||
import com.example.data.model.formatToShortDate
|
||||
import com.example.data.model.parseDateOnly
|
||||
import com.example.data.model.parseFullDateTime
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import java.util.Calendar
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testExtractDateOnly() {
|
||||
assertEquals("14/08/2026", extractDateOnly("14/08/2026 08:30"))
|
||||
assertEquals("14/08/2026", extractDateOnly("14/08/2026"))
|
||||
assertEquals("2026-08-14", extractDateOnly("2026-08-14T10:15:00"))
|
||||
assertEquals("N/A", extractDateOnly("N/A"))
|
||||
assertEquals("N/A", extractDateOnly(""))
|
||||
assertEquals("14/08/26", extractDateOnly("Sex 14/08/26 07:00"))
|
||||
assertEquals("17/08/26", extractDateOnly("Seg 17/08/26"))
|
||||
assertEquals("2026-08-15", extractDateOnly("2026-08-15"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParseDateOnly() {
|
||||
val date1 = parseDateOnly("14/08/2026")
|
||||
assertNotNull(date1)
|
||||
val cal1 = Calendar.getInstance().apply { time = date1!! }
|
||||
assertEquals(2026, cal1.get(Calendar.YEAR))
|
||||
assertEquals(Calendar.AUGUST, cal1.get(Calendar.MONTH))
|
||||
assertEquals(14, cal1.get(Calendar.DAY_OF_MONTH))
|
||||
|
||||
val date2 = parseDateOnly("2026-08-15")
|
||||
assertNotNull(date2)
|
||||
val cal2 = Calendar.getInstance().apply { time = date2!! }
|
||||
assertEquals(2026, cal2.get(Calendar.YEAR))
|
||||
assertEquals(Calendar.AUGUST, cal2.get(Calendar.MONTH))
|
||||
assertEquals(15, cal2.get(Calendar.DAY_OF_MONTH))
|
||||
|
||||
// 2-digit years support tests
|
||||
val date3 = parseDateOnly("17/08/26")
|
||||
assertNotNull(date3)
|
||||
val cal3 = Calendar.getInstance().apply { time = date3!! }
|
||||
assertEquals(2026, cal3.get(Calendar.YEAR))
|
||||
assertEquals(Calendar.AUGUST, cal3.get(Calendar.MONTH))
|
||||
assertEquals(17, cal3.get(Calendar.DAY_OF_MONTH))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testParseFullDateTime() {
|
||||
val date1 = parseFullDateTime("14/08/2026 08:30")
|
||||
assertNotNull(date1)
|
||||
val cal1 = Calendar.getInstance().apply { time = date1!! }
|
||||
assertEquals(2026, cal1.get(Calendar.YEAR))
|
||||
assertEquals(8, cal1.get(Calendar.HOUR_OF_DAY))
|
||||
assertEquals(30, cal1.get(Calendar.MINUTE))
|
||||
|
||||
val date2 = parseFullDateTime("17/08/26 14:15")
|
||||
assertNotNull(date2)
|
||||
val cal2 = Calendar.getInstance().apply { time = date2!! }
|
||||
assertEquals(2026, cal2.get(Calendar.YEAR))
|
||||
assertEquals(14, cal2.get(Calendar.HOUR_OF_DAY))
|
||||
assertEquals(15, cal2.get(Calendar.MINUTE))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFormatToShortDate() {
|
||||
assertEquals("14/08/26", formatToShortDate("Sex 14/08/26 07:00"))
|
||||
assertEquals("14/08/26", formatToShortDate("14/08/2026 08:30"))
|
||||
assertEquals("14/08/26", formatToShortDate("14/08/2026"))
|
||||
assertEquals("15/08/26", formatToShortDate("2026-08-15"))
|
||||
assertEquals("Todas", formatToShortDate("Todas"))
|
||||
assertEquals("N/A", formatToShortDate("N/A"))
|
||||
}
|
||||
}
|
||||
33
app/src/test/java/com/example/GreetingScreenshotTest.kt
Normal file
33
app/src/test/java/com/example/GreetingScreenshotTest.kt
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.example
|
||||
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onRoot
|
||||
import com.example.ui.components.CargillLogo
|
||||
import com.example.ui.theme.MyApplicationTheme
|
||||
import com.github.takahirom.roborazzi.RobolectricDeviceQualifiers
|
||||
import com.github.takahirom.roborazzi.captureRoboImage
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.GraphicsMode
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@GraphicsMode(GraphicsMode.Mode.NATIVE)
|
||||
@Config(qualifiers = RobolectricDeviceQualifiers.Pixel8, sdk = [36])
|
||||
class GreetingScreenshotTest {
|
||||
|
||||
@get:Rule val composeTestRule = createComposeRule()
|
||||
|
||||
@Test
|
||||
fun greeting_screenshot() {
|
||||
composeTestRule.setContent {
|
||||
MyApplicationTheme {
|
||||
CargillLogo()
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onRoot().captureRoboImage(filePath = "src/test/screenshots/greeting.png")
|
||||
}
|
||||
}
|
||||
BIN
app/src/test/screenshots/greeting.png
Normal file
BIN
app/src/test/screenshots/greeting.png
Normal file
Binary file not shown.
Reference in New Issue
Block a user