tests: added last unit tests, removed unused ui test dependencies
This commit is contained in:
@@ -110,9 +110,5 @@ dependencies {
|
||||
|
||||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
androidTestImplementation(platform(libs.androidx.compose.bom))
|
||||
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
|
||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||
debugImplementation(libs.androidx.compose.ui.test.manifest)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package agzam.vyatsu.data.remote
|
||||
|
||||
import agzam.vyatsu.domain.model.DateRange
|
||||
import agzam.vyatsu.domain.model.Season
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class VyatsuUrlsTest {
|
||||
|
||||
private val autumnRange = DateRange("14092026", "27092026")
|
||||
|
||||
@Test
|
||||
fun groupPdfUrl_usesAutumnKey() {
|
||||
assertEquals(
|
||||
"https://www.vyatsu.ru/reports/schedule/Group/12345_1_14092026_27092026.pdf",
|
||||
VyatsuUrls.groupPdfUrl("12345", Season.AUTUMN, autumnRange)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun groupPdfUrl_usesSpringKey() {
|
||||
assertEquals(
|
||||
"https://www.vyatsu.ru/reports/schedule/Group/765432_2_09022027_22022027.pdf",
|
||||
VyatsuUrls.groupPdfUrl("765432", Season.SPRING, DateRange("09022027", "22022027"))
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun season_apiKeysMatchUrlScheme() {
|
||||
assertEquals("1", Season.AUTUMN.apiKey)
|
||||
assertEquals("2", Season.SPRING.apiKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun generatedUrl_isRecognizedByGroupsParser() {
|
||||
val url = VyatsuUrls.groupPdfUrl("12345", Season.AUTUMN, autumnRange)
|
||||
val html = """<a href="$url">x</a>"""
|
||||
|
||||
val parsed = GroupsParser.parseStream(html.byteInputStream(Charsets.UTF_8))
|
||||
|
||||
assertEquals(listOf(autumnRange), parsed.dateRanges["12345"]?.get(Season.AUTUMN))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package agzam.vyatsu.domain.model
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
import java.time.LocalDate
|
||||
|
||||
class ScheduleTest {
|
||||
|
||||
private val autumnPeriod = SchedulePeriod(
|
||||
weekStart = LocalDate.of(2026, 9, 14),
|
||||
weekEnd = LocalDate.of(2026, 9, 27),
|
||||
season = Season.AUTUMN
|
||||
)
|
||||
private val nextPeriod = SchedulePeriod(
|
||||
weekStart = LocalDate.of(2026, 9, 28),
|
||||
weekEnd = LocalDate.of(2026, 10, 11),
|
||||
season = Season.AUTUMN
|
||||
)
|
||||
private val dayInFirstPeriod = Day(LocalDate.of(2026, 9, 15), emptyList())
|
||||
private val dayInSecondPeriod = Day(LocalDate.of(2026, 9, 29), emptyList())
|
||||
private val dayOutsidePeriods = Day(LocalDate.of(2026, 10, 20), emptyList())
|
||||
|
||||
private val schedule = Schedule(
|
||||
groupId = "12345",
|
||||
periods = listOf(autumnPeriod, nextPeriod),
|
||||
days = listOf(dayInFirstPeriod, dayInSecondPeriod, dayOutsidePeriods)
|
||||
)
|
||||
|
||||
@Test
|
||||
fun periodOf_matchesDateInsidePeriod() {
|
||||
assertEquals(autumnPeriod, schedule.periodOf(LocalDate.of(2026, 9, 15)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun periodOf_includesBothBounds() {
|
||||
assertEquals(autumnPeriod, schedule.periodOf(autumnPeriod.weekStart))
|
||||
assertEquals(autumnPeriod, schedule.periodOf(autumnPeriod.weekEnd))
|
||||
assertEquals(nextPeriod, schedule.periodOf(nextPeriod.weekStart))
|
||||
assertEquals(nextPeriod, schedule.periodOf(nextPeriod.weekEnd))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun periodOf_returnsNullForDateOutsideAllPeriods() {
|
||||
assertNull(schedule.periodOf(LocalDate.of(2026, 10, 20)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun daysOf_returnsOnlyDaysWithinPeriod() {
|
||||
assertEquals(listOf(dayInFirstPeriod), schedule.daysOf(autumnPeriod))
|
||||
assertEquals(listOf(dayInSecondPeriod), schedule.daysOf(nextPeriod))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun daysOf_returnsEmptyWhenPeriodHasNoDays() {
|
||||
val emptyPeriod = SchedulePeriod(
|
||||
weekStart = LocalDate.of(2027, 1, 4),
|
||||
weekEnd = LocalDate.of(2027, 1, 17),
|
||||
season = Season.SPRING
|
||||
)
|
||||
|
||||
assertEquals(emptyList<Day>(), schedule.daysOf(emptyPeriod))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun daysOf_neverReturnsDayOutsideEveryPeriod() {
|
||||
val collected = schedule.periods.flatMap { schedule.daysOf(it) }
|
||||
|
||||
assertFalse(collected.contains(dayOutsidePeriods))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user