Tests merge #8

Open
vantablackTea wants to merge 12 commits from tests-branch into main
4 changed files with 115 additions and 8 deletions
Showing only changes of commit aa568cb628 - Show all commits
-4
View File
@@ -110,9 +110,5 @@ dependencies {
testImplementation(libs.junit) testImplementation(libs.junit)
androidTestImplementation(libs.androidx.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.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))
}
}
-4
View File
@@ -3,7 +3,6 @@ agp = "9.1.1"
coreKtx = "1.10.1" coreKtx = "1.10.1"
junit = "4.13.2" junit = "4.13.2"
junitVersion = "1.1.5" junitVersion = "1.1.5"
espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.6.1" lifecycleRuntimeKtx = "2.6.1"
activityCompose = "1.8.0" activityCompose = "1.8.0"
kotlin = "2.2.10" kotlin = "2.2.10"
@@ -22,7 +21,6 @@ monitor = "1.8.0"
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" } junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" } androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
@@ -30,8 +28,6 @@ androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" } androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-compose-material-icons-core = { group = "androidx.compose.material", name = "material-icons-core" } androidx-compose-material-icons-core = { group = "androidx.compose.material", name = "material-icons-core" }
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" } androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }