refactor: update activity sorting logic and expand dashboard screen functionality with new state management and media handling
This commit is contained in:
@@ -185,6 +185,67 @@ class ExampleRobolectricTest {
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun `test sorting OSs without start date appear at the very end of list`() {
|
||||
val testDispatcher = kotlinx.coroutines.test.UnconfinedTestDispatcher()
|
||||
kotlinx.coroutines.Dispatchers.setMain(testDispatcher)
|
||||
try {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
val db = androidx.room.Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java)
|
||||
.allowMainThreadQueries()
|
||||
.setQueryExecutor { it.run() }
|
||||
.setTransactionExecutor { it.run() }
|
||||
.build()
|
||||
val repository = com.example.data.repository.MaintenanceRepository(db.maintenanceDao(), context)
|
||||
|
||||
val actNoStart = com.example.data.model.MaintenanceActivity(
|
||||
numeroOs = "OS-NO-START",
|
||||
descricao = "OS without start date",
|
||||
setor = "Geral",
|
||||
equipe = "Mecânica",
|
||||
recurso = "Sem Recurso",
|
||||
dataInicio = "",
|
||||
dataFim = "27/08/2026 17:00",
|
||||
percentualExecucao = 0,
|
||||
synced = true
|
||||
)
|
||||
val actValidStart = com.example.data.model.MaintenanceActivity(
|
||||
numeroOs = "OS-VALID-START",
|
||||
descricao = "OS with valid start date",
|
||||
setor = "Geral",
|
||||
equipe = "Elétrica",
|
||||
recurso = "Sem Recurso",
|
||||
dataInicio = "01/01/2026 08:00",
|
||||
dataFim = "01/01/2026 17:00",
|
||||
percentualExecucao = 0,
|
||||
synced = true
|
||||
)
|
||||
|
||||
kotlinx.coroutines.runBlocking {
|
||||
db.maintenanceDao().insertActivities(listOf(actNoStart, actValidStart))
|
||||
val viewModel = com.example.ui.viewmodel.MaintenanceViewModel(repository)
|
||||
|
||||
val job = viewModel.viewModelScope.launch {
|
||||
viewModel.filteredActivities.collect {}
|
||||
}
|
||||
|
||||
Thread.sleep(200)
|
||||
org.robolectric.shadows.ShadowLooper.idleMainLooper()
|
||||
|
||||
val list = viewModel.filteredActivities.value
|
||||
assertEquals(2, list.size)
|
||||
assertEquals("OS-VALID-START", list[0].numeroOs)
|
||||
assertEquals("OS-NO-START", list[1].numeroOs)
|
||||
|
||||
job.cancel()
|
||||
}
|
||||
db.close()
|
||||
} finally {
|
||||
kotlinx.coroutines.Dispatchers.resetMain()
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
|
||||
@Test
|
||||
fun `test analytics state calculations in ViewModel`() {
|
||||
|
||||
Reference in New Issue
Block a user