-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from LookUpGroup27/feature/calendar-optimization
feat: Calendar Optimization and IcalRepository Integration
- Loading branch information
Showing
13 changed files
with
876 additions
and
467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/calendar/CalendarKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package com.github.lookupgroup27.lookup.ui.calendar | ||
|
||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithContentDescription | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import androidx.compose.ui.test.performTextInput | ||
import androidx.navigation.compose.ComposeNavigator | ||
import androidx.navigation.testing.TestNavHostController | ||
import com.github.lookupgroup27.lookup.model.calendar.CalendarViewModel | ||
import com.github.lookupgroup27.lookup.model.calendar.MockIcalRepository | ||
import com.github.lookupgroup27.lookup.ui.navigation.NavigationActions | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
import kotlinx.coroutines.test.advanceUntilIdle | ||
import kotlinx.coroutines.test.runTest | ||
import net.fortuna.ical4j.model.DateTime | ||
import net.fortuna.ical4j.model.component.VEvent | ||
import net.fortuna.ical4j.model.property.Summary | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class CalendarKtTest { | ||
|
||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
private lateinit var calendarViewModel: CalendarViewModel | ||
private lateinit var navigationActions: NavigationActions | ||
private lateinit var navController: TestNavHostController | ||
private val dateFormat = SimpleDateFormat("MMMM yyyy", Locale.getDefault()) | ||
|
||
@Before | ||
fun setUp() { | ||
|
||
val mockIcalData = | ||
""" | ||
BEGIN:VCALENDAR | ||
BEGIN:VEVENT | ||
DTSTART:20251001T120000Z | ||
DTEND:20251001T130000Z | ||
SUMMARY:Test Event | ||
END:VEVENT | ||
END:VCALENDAR | ||
""" | ||
.trimIndent() | ||
|
||
val mockIcalRepository = MockIcalRepository(mockIcalData) | ||
calendarViewModel = CalendarViewModel(mockIcalRepository) | ||
|
||
val event = VEvent(DateTime("20251001T120000Z"), "Test Event v2") | ||
event.getProperties().add(Summary("Test Event v2")) | ||
|
||
composeTestRule.setContent { | ||
EventItem(event = event, onClick = {}) | ||
navController = TestNavHostController(LocalContext.current) | ||
navController.navigatorProvider.addNavigator(ComposeNavigator()) | ||
navigationActions = NavigationActions(navController) | ||
CalendarScreen(calendarViewModel = calendarViewModel, navigationActions = navigationActions) | ||
} | ||
} | ||
|
||
@Test | ||
fun testCalendarHeaderDisplaysCurrentMonth() = runTest { | ||
val currentDate = Calendar.getInstance().time | ||
val formattedMonth = dateFormat.format(currentDate) | ||
|
||
composeTestRule.onNodeWithText(formattedMonth).assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun testPreviousMonthButton() = runTest { | ||
val currentDate = Calendar.getInstance().time | ||
val previousMonthDate = | ||
Calendar.getInstance() | ||
.apply { | ||
time = currentDate | ||
add(Calendar.MONTH, -1) | ||
} | ||
.time | ||
val formattedPreviousMonth = dateFormat.format(previousMonthDate) | ||
|
||
composeTestRule.onNodeWithContentDescription("Previous Month").performClick() | ||
composeTestRule.onNodeWithText(formattedPreviousMonth).assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun testNextMonthButton() = runTest { | ||
val currentDate = Calendar.getInstance().time | ||
val nextMonthDate = | ||
Calendar.getInstance() | ||
.apply { | ||
time = currentDate | ||
add(Calendar.MONTH, 1) | ||
} | ||
.time | ||
val formattedNextMonth = dateFormat.format(nextMonthDate) | ||
|
||
composeTestRule.onNodeWithContentDescription("Next Month").performClick() | ||
composeTestRule.onNodeWithText(formattedNextMonth).assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun testLookUpEventButtonExists() = runTest { | ||
composeTestRule.onNodeWithContentDescription("Look Up Event").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun testSearchDialogOpensAndSearchesForEvents() = runTest { | ||
advanceUntilIdle() | ||
|
||
composeTestRule.onNodeWithContentDescription("Look Up Event").performClick() | ||
composeTestRule.onNodeWithText("Look Up Event").assertIsDisplayed() | ||
|
||
composeTestRule.onNodeWithText("Enter event name").performTextInput("Test Event") | ||
composeTestRule.onNodeWithText("Search").performClick() | ||
|
||
composeTestRule.waitForIdle() | ||
composeTestRule.onNodeWithText("Test Event").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun testSearchDialogCancelButtonClosesDialog() = runTest { | ||
composeTestRule.onNodeWithContentDescription("Look Up Event").performClick() | ||
composeTestRule.onNodeWithText("Look Up Event").assertIsDisplayed() | ||
|
||
composeTestRule.onNodeWithText("Cancel").performClick() | ||
composeTestRule.onNodeWithText("Look Up Event").assertDoesNotExist() | ||
} | ||
|
||
@Test | ||
fun testEventItemDisplaysCorrectly() = runTest { | ||
composeTestRule.onNodeWithText("Test Event v2").assertIsDisplayed() | ||
composeTestRule.onNodeWithText("Date: October 1, 2025").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun testSelectingDayUpdatesSelectedDate() = runTest { | ||
val calendar = Calendar.getInstance() | ||
val dayToSelect = calendar.get(Calendar.DAY_OF_MONTH) + 1 | ||
|
||
composeTestRule.onNodeWithText(dayToSelect.toString()).performClick() | ||
|
||
composeTestRule.onNodeWithText(dayToSelect.toString()).assertIsDisplayed() | ||
} | ||
} |
91 changes: 0 additions & 91 deletions
91
app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/overview/CalendarKtTest.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.