Fix marking as non-changed if cell don't have classes

This commit is contained in:
Mikołaj Pich 2021-05-16 22:58:19 +02:00
parent e282a7a50e
commit bb083546e0
3 changed files with 37 additions and 11 deletions

View file

@ -147,15 +147,19 @@ class TimetableParser {
)
}
private fun getLesson(lesson: Timetable, spans: Elements, offset: Int = 0, infoExtraOffset: Int = 0, changes: String = "") = lesson.copy(
subject = getLessonAndGroupInfoFromSpan(spans[0])[0],
group = getLessonAndGroupInfoFromSpan(spans[0])[1],
teacher = spans[1 + offset].text(),
room = spans[2 + offset].text(),
info = getFormattedLessonInfo(spans.getOrNull(3 + offset + infoExtraOffset)?.text() ?: changes),
canceled = spans.first().hasClass(CLASS_MOVED_OR_CANCELED),
changes = spans.first().hasClass(CLASS_CHANGES)
)
private fun getLesson(lesson: Timetable, spans: Elements, offset: Int = 0, infoExtraOffset: Int = 0, changes: String = ""): Timetable {
val firstElementClasses = spans.first().classNames()
val isCanceled = CLASS_MOVED_OR_CANCELED in firstElementClasses
return lesson.copy(
subject = getLessonAndGroupInfoFromSpan(spans[0])[0],
group = getLessonAndGroupInfoFromSpan(spans[0])[1],
teacher = spans[1 + offset].text(),
room = spans[2 + offset].text(),
info = getFormattedLessonInfo(spans.getOrNull(3 + offset + infoExtraOffset)?.text() ?: changes),
canceled = isCanceled,
changes = (changes.isNotBlank() && !isCanceled) || CLASS_CHANGES in firstElementClasses
)
}
private fun getLessonWithReplacement(lesson: Timetable, spans: Elements, o: Int = 0) = lesson.copy(
subject = getLessonAndGroupInfoFromSpan(spans[3 + o])[0],

View file

@ -31,7 +31,7 @@ class TimetableTest : BaseLocalTest() {
@Test
fun getTimetableTest() {
assertEquals(5, headers.size)
assertEquals(24, timetable.size)
assertEquals(25, timetable.size)
assertEquals(2, additional.size)
}
@ -555,6 +555,28 @@ class TimetableTest : BaseLocalTest() {
}
}
@Test
fun getLightLesson_withoutClasses_withSubstitution() {
with(timetable[FRIDAY_OFFSET + 4]) {
// piątek, 4
assertEquals(4, number)
assertEquals(getDate(2018, 9, 28, 10, 50, 0), start)
assertEquals(getDate(2018, 9, 28, 11, 35, 0), end)
assertEquals("pracownia programowania", subject)
assertEquals("JA 2", group)
assertEquals("", teacher)
assertEquals("B149", room)
assertEquals("zastępstwo: Tabaluga Jakub", info)
assertEquals("", subjectOld)
assertEquals("", teacherOld)
assertEquals("", roomOld)
assertEquals(false, canceled)
assertEquals(true, changes)
}
}
@Test
fun getDayHeader_empty() {
with(headers[0]) {

View file

@ -78,7 +78,7 @@
"<div><span class=''>podstawy algorytmiki i programowania</span> <span class=''>A114</span>(zastępstwo: Stanisław Baran)</div>",
"<div><span class='x-treelabel-ppl x-treelabel-inv'>Język angielski [JA 2]</span><span class='x-treelabel-ppl x-treelabel-inv'> </span><span class='x-treelabel-ppl x-treelabel-inv'> A315</span>(nieobecność nauczyciela: czytelnia)</div>",
"<div><span class='x-treelabel-ppl x-treelabel-inv'>Fizyka</span> <span class='x-treelabel-ppl x-treelabel-inv'>A10</span>(nieobecność nauczyciela: uczniowie przychodzą później)</div>",
""
"<div><span class=''>pracownia programowania [JA 2]</span><span class=''> </span><span class=''> B149</span>(zastępstwo: Tabaluga Jakub)</div>"
]
],
"Additionals": [