From b5433c3938125568ab42511340e08ca67b1b1362 Mon Sep 17 00:00:00 2001 From: GerardPaligot Date: Mon, 2 Dec 2024 22:06:37 +0100 Subject: [PATCH] fix(schedules): resolve instrumented tests. --- .../confily/core/models/factory/Event.ext.kt | 4 +-- .../schedules/panes/ScheduleGridScreen.kt | 3 ++- .../presentation/ScheduleGridViewModel.kt | 6 ++--- .../schedules/sample/FilteringScheduleTest.kt | 4 +++ .../schedules/sample/fakes/AgendaFake.kt | 2 +- .../confily/core/di/RepositoryModule.kt | 4 ++- .../confily/core/events/entities/Event.kt | 25 +++++++++++-------- .../core/schedules/SessionRepository.kt | 4 ++- .../core/schedules/SessionRepositoryImpl.kt | 16 +++++++----- 9 files changed, 42 insertions(+), 26 deletions(-) diff --git a/android-core/core-models-factory/src/main/kotlin/com/paligot/confily/core/models/factory/Event.ext.kt b/android-core/core-models-factory/src/main/kotlin/com/paligot/confily/core/models/factory/Event.ext.kt index a89e38c4c..bd9fe9177 100644 --- a/android-core/core-models-factory/src/main/kotlin/com/paligot/confily/core/models/factory/Event.ext.kt +++ b/android-core/core-models-factory/src/main/kotlin/com/paligot/confily/core/models/factory/Event.ext.kt @@ -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) = apply { this.menus = menus } fun coc(coc: String) = apply { this.coc = coc } fun openfeedbackProjectId(openfeedbackProjectId: String?) = diff --git a/features/schedules/schedules-panes/src/commonMain/kotlin/com/paligot/confily/schedules/panes/ScheduleGridScreen.kt b/features/schedules/schedules-panes/src/commonMain/kotlin/com/paligot/confily/schedules/panes/ScheduleGridScreen.kt index db890ca32..4e71505e4 100644 --- a/features/schedules/schedules-panes/src/commonMain/kotlin/com/paligot/confily/schedules/panes/ScheduleGridScreen.kt +++ b/features/schedules/schedules-panes/src/commonMain/kotlin/com/paligot/confily/schedules/panes/ScheduleGridScreen.kt @@ -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 @@ -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, diff --git a/features/schedules/schedules-presentation/src/commonMain/kotlin/com/paligot/confily/schedules/presentation/ScheduleGridViewModel.kt b/features/schedules/schedules-presentation/src/commonMain/kotlin/com/paligot/confily/schedules/presentation/ScheduleGridViewModel.kt index 4351e2c91..a9edc222b 100644 --- a/features/schedules/schedules-presentation/src/commonMain/kotlin/com/paligot/confily/schedules/presentation/ScheduleGridViewModel.kt +++ b/features/schedules/schedules-presentation/src/commonMain/kotlin/com/paligot/confily/schedules/presentation/ScheduleGridViewModel.kt @@ -72,9 +72,9 @@ class ScheduleGridViewModel( private val _schedules = sessionRepository.sessions() val uiState: StateFlow = combine( - _tabsStates, - _uiHasFiltersState, - _schedules, + flow = _tabsStates, + flow2 = _uiHasFiltersState, + flow3 = _schedules, transform = { agendaTabs, topActions, schedules -> if (schedules.sessions.isNotEmpty()) { ScheduleGridUiState.Success( diff --git a/features/schedules/schedules-sample/src/androidTest/kotlin/com/paligot/confily/schedules/sample/FilteringScheduleTest.kt b/features/schedules/schedules-sample/src/androidTest/kotlin/com/paligot/confily/schedules/sample/FilteringScheduleTest.kt index d306fcf0e..ebcff863a 100644 --- a/features/schedules/schedules-sample/src/androidTest/kotlin/com/paligot/confily/schedules/sample/FilteringScheduleTest.kt +++ b/features/schedules/schedules-sample/src/androidTest/kotlin/com/paligot/confily/schedules/sample/FilteringScheduleTest.kt @@ -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 @@ -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 @@ -38,11 +40,13 @@ class FilteringScheduleTest : KoinTest { } private val settings by inject() + private val eventDao by inject() private val sessionDao by inject() @Before fun setup() { settings.insertEventId(BuildConfig.DEFAULT_EVENT) + eventDao.insertEvent(event = event, qAndA = emptyList()) sessionDao.insertAgenda(BuildConfig.DEFAULT_EVENT, agenda) } diff --git a/features/schedules/schedules-sample/src/androidTest/kotlin/com/paligot/confily/schedules/sample/fakes/AgendaFake.kt b/features/schedules/schedules-sample/src/androidTest/kotlin/com/paligot/confily/schedules/sample/fakes/AgendaFake.kt index d1c7bc9a3..3f6bf6b90 100644 --- a/features/schedules/schedules-sample/src/androidTest/kotlin/com/paligot/confily/schedules/sample/fakes/AgendaFake.kt +++ b/features/schedules/schedules-sample/src/androidTest/kotlin/com/paligot/confily/schedules/sample/fakes/AgendaFake.kt @@ -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") diff --git a/shared/core-di/src/commonMain/kotlin/com/paligot/confily/core/di/RepositoryModule.kt b/shared/core-di/src/commonMain/kotlin/com/paligot/confily/core/di/RepositoryModule.kt index 9a0e66741..9baccd004 100644 --- a/shared/core-di/src/commonMain/kotlin/com/paligot/confily/core/di/RepositoryModule.kt +++ b/shared/core-di/src/commonMain/kotlin/com/paligot/confily/core/di/RepositoryModule.kt @@ -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(), diff --git a/shared/core/src/commonMain/kotlin/com/paligot/confily/core/events/entities/Event.kt b/shared/core/src/commonMain/kotlin/com/paligot/confily/core/events/entities/Event.kt index 6a034eaab..719853f4b 100644 --- a/shared/core/src/commonMain/kotlin/com/paligot/confily/core/events/entities/Event.kt +++ b/shared/core/src/commonMain/kotlin/com/paligot/confily/core/events/entities/Event.kt @@ -26,7 +26,18 @@ class Event( val socials: List, val faqUrl: String, val cocUrl: String -) +) { + fun days(): List { + val startDate = startTime.date + val endDate = endTime.date + val days = mutableListOf() + 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, @@ -41,13 +52,5 @@ fun Event.mapToUi(): EventInfoUi = EventInfoUi( codeOfConductLink = cocUrl ) -fun Event.mapToDays(): List { - val startDate = startTime.date - val endDate = endTime.date - val days = mutableListOf() - 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 = + days().map { it.format(LocalDate.Format { byUnicodePattern("dd/MM") }) } diff --git a/shared/core/src/commonMain/kotlin/com/paligot/confily/core/schedules/SessionRepository.kt b/shared/core/src/commonMain/kotlin/com/paligot/confily/core/schedules/SessionRepository.kt index 378a3c536..945505eb6 100644 --- a/shared/core/src/commonMain/kotlin/com/paligot/confily/core/schedules/SessionRepository.kt +++ b/shared/core/src/commonMain/kotlin/com/paligot/confily/core/schedules/SessionRepository.kt @@ -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 @@ -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) } } diff --git a/shared/core/src/commonMain/kotlin/com/paligot/confily/core/schedules/SessionRepositoryImpl.kt b/shared/core/src/commonMain/kotlin/com/paligot/confily/core/schedules/SessionRepositoryImpl.kt index 3b3497246..8077200a7 100644 --- a/shared/core/src/commonMain/kotlin/com/paligot/confily/core/schedules/SessionRepositoryImpl.kt +++ b/shared/core/src/commonMain/kotlin/com/paligot/confily/core/schedules/SessionRepositoryImpl.kt @@ -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 @@ -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 { @@ -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 } ) } )