Skip to content

Commit

Permalink
fix(schedules): resolve instrumented tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Dec 2, 2024
1 parent 1df7d56 commit b5433c3
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class EventBuilder {
fun id(id: String) = apply { this.id = id }
fun name(name: String) = apply { this.name = name }
fun address(address: Address) = apply { this.address = address }
fun startDate(startDate: Instant) = apply { this.startDate = startDate.formatISO() }
fun endDate(endDate: Instant) = apply { this.endDate = endDate.formatISO() }
fun startDate(startDate: Instant) = apply { this.startDate = "${startDate.formatISO()}Z" }
fun endDate(endDate: Instant) = apply { this.endDate = "${endDate.formatISO()}Z" }
fun menus(menus: List<EventLunchMenu>) = apply { this.menus = menus }
fun coc(coc: String) = apply { this.coc = coc }
fun openfeedbackProjectId(openfeedbackProjectId: String?) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import com.paligot.confily.models.ui.AgendaUi
import com.paligot.confily.models.ui.EventSessionItemUi
import com.paligot.confily.models.ui.TalkItemUi
import com.paligot.confily.schedules.semantics.SchedulesSemantics
Expand All @@ -32,7 +33,7 @@ const val NbHorizontalPadding = 2

@Composable
fun ScheduleGridScreen(
agenda: com.paligot.confily.models.ui.AgendaUi,
agenda: AgendaUi,
onTalkClicked: (id: String) -> Unit,
onEventSessionClicked: (id: String) -> Unit,
onFavoriteClicked: (TalkItemUi) -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class ScheduleGridViewModel(
private val _schedules = sessionRepository.sessions()
val uiState: StateFlow<ScheduleGridUiState> =
combine(
_tabsStates,
_uiHasFiltersState,
_schedules,
flow = _tabsStates,
flow2 = _uiHasFiltersState,
flow3 = _schedules,
transform = { agendaTabs, topActions, schedules ->
if (schedules.sessions.isNotEmpty()) {
ScheduleGridUiState.Success(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.paligot.confily.schedules.sample
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.core.app.ActivityScenario
import androidx.test.platform.app.InstrumentationRegistry
import com.paligot.confily.core.events.EventDao
import com.paligot.confily.core.kvalue.ConferenceSettings
import com.paligot.confily.core.sample.BuildConfig
import com.paligot.confily.core.schedules.SessionDao
Expand All @@ -16,6 +17,7 @@ import com.paligot.confily.schedules.sample.fakes.AgendaFake.format
import com.paligot.confily.schedules.sample.fakes.AgendaFake.schedule
import com.paligot.confily.schedules.sample.fakes.AgendaFake.session
import com.paligot.confily.schedules.sample.fakes.AgendaFake.speaker
import com.paligot.confily.schedules.sample.fakes.EventFake.event
import com.paligot.confily.schedules.test.robot.schedules
import com.paligot.confily.schedules.test.scheduleRobotGraph
import org.junit.After
Expand All @@ -38,11 +40,13 @@ class FilteringScheduleTest : KoinTest {
}

private val settings by inject<ConferenceSettings>()
private val eventDao by inject<EventDao>()
private val sessionDao by inject<SessionDao>()

@Before
fun setup() {
settings.insertEventId(BuildConfig.DEFAULT_EVENT)
eventDao.insertEvent(event = event, qAndA = emptyList())
sessionDao.insertAgenda(BuildConfig.DEFAULT_EVENT, agenda)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.datetime.Clock
import kotlin.time.Duration

object AgendaFake {
private val startInstant = Clock.System.now().plus(Duration.parse("1d"))
private val startInstant = Clock.System.now().plus(Duration.parse("1h"))

val schedule = ScheduleItemV4.builder()
.id("session-id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import org.koin.dsl.module

val repositoriesModule = module {
includes(databasesModule, networksModule, fileSystemModule)
single { SessionRepository.Factory.create(sessionDao = get(), settings = get()) }
single {
SessionRepository.Factory.create(eventDao = get(), sessionDao = get(), settings = get())
}
single {
EventRepository.Factory.create(
api = get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ class Event(
val socials: List<Social>,
val faqUrl: String,
val cocUrl: String
)
) {
fun days(): List<LocalDate> {
val startDate = startTime.date
val endDate = endTime.date
val days = mutableListOf<LocalDate>()
for (i in 0 until startDate.until(endDate, DateTimeUnit.DAY)) {
val currentDate = startDate.plus(i, DateTimeUnit.DAY)
days.add(currentDate)
}
return days
}
}

fun Event.mapToUi(): EventInfoUi = EventInfoUi(
name = name,
Expand All @@ -41,13 +52,5 @@ fun Event.mapToUi(): EventInfoUi = EventInfoUi(
codeOfConductLink = cocUrl
)

fun Event.mapToDays(): List<String> {
val startDate = startTime.date
val endDate = endTime.date
val days = mutableListOf<String>()
for (i in 0 until startDate.until(endDate, DateTimeUnit.DAY)) {
val currentDate = startDate.plus(i, DateTimeUnit.DAY)
days.add(currentDate.format(LocalDate.Format { byUnicodePattern("dd/MM") }))
}
return days
}
fun Event.mapToDays(): List<String> =
days().map { it.format(LocalDate.Format { byUnicodePattern("dd/MM") }) }
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.paligot.confily.core.schedules

import com.paligot.confily.core.events.EventDao
import com.paligot.confily.core.kvalue.ConferenceSettings
import com.paligot.confily.core.schedules.entities.EventSession
import com.paligot.confily.core.schedules.entities.Filters
Expand All @@ -24,8 +25,9 @@ interface SessionRepository {

object Factory {
fun create(
eventDao: EventDao,
sessionDao: SessionDao,
settings: ConferenceSettings
): SessionRepository = SessionRepositoryImpl(sessionDao, settings)
): SessionRepository = SessionRepositoryImpl(eventDao, sessionDao, settings)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.paligot.confily.core.schedules

import com.paligot.confily.core.events.EventDao
import com.paligot.confily.core.kvalue.ConferenceSettings
import com.paligot.confily.core.schedules.entities.EventSession
import com.paligot.confily.core.schedules.entities.Filters
Expand All @@ -14,6 +15,7 @@ import kotlinx.coroutines.flow.flatMapConcat

@OptIn(ExperimentalCoroutinesApi::class)
class SessionRepositoryImpl(
private val eventDao: EventDao,
private val sessionDao: SessionDao,
private val settings: ConferenceSettings
) : SessionRepository {
Expand All @@ -22,16 +24,18 @@ class SessionRepositoryImpl(
flow = sessionDao.fetchSessionsFiltered(it),
flow2 = sessionDao.fetchEventSessions(it),
flow3 = filtersApplied(),
transform = { sessions, eventSessions, filters ->
flow4 = eventDao.fetchEvent(it),
transform = { sessions, eventSessions, filters, event ->
val allSessions = sessions + eventSessions
val days = event?.days() ?: emptyList()
Sessions(
filtersApplied = filters,
sessions = (sessions + eventSessions)
.groupBy { it.startTime.date }
.map { entry ->
entry.key to entry.value
sessions = days
.associateWith { day ->
allSessions
.filter { it.startTime.date == day }
.sortedWith(compareBy({ it.startTime }, { it.order }))
}
.associate { it }
)
}
)
Expand Down

0 comments on commit b5433c3

Please sign in to comment.