fix(web): устойчивые ошибки courseNo и login E2E

This commit is contained in:
2026-10-29 20:01:40 +03:00
parent 65ed08f5c2
commit 7ef5c866a3
3 changed files with 24 additions and 4 deletions

View File

@@ -74,7 +74,10 @@ async function login(page: Page, login: string, password: string, expectedPath:
await page.goto("/login");
await page.fill("#login", login);
await page.fill("#password", password);
await Promise.all([page.waitForURL(expectedPath), page.click('button[type="submit"]')]);
await Promise.all([
page.waitForURL(expectedPath, { waitUntil: "domcontentloaded", timeout: 60_000 }),
page.click('button[type="submit"]'),
]);
}
test.beforeAll(async ({ playwright }) => {

View File

@@ -61,7 +61,12 @@ class AdminLabController(
model: Model,
): String {
val t = token(session)
val selected = courseNo?.trim()?.takeIf { it.isNotBlank() }?.let { api.courseByUrlNo(t, it) }
val selected =
courseNo?.trim()?.takeIf { it.isNotBlank() }?.let {
runCatching { api.courseByUrlNo(t, it) }
.onFailure { model.addAttribute("error", "Курс не найден") }
.getOrNull()
}
model.addAttribute("labs", api.listLabs(t, selected?.id))
model.addAttribute("courses", coursesFor(session))
model.addAttribute("selectedCourseNo", selected?.courseNo)

View File

@@ -92,7 +92,13 @@ class TeacherController(
redirect: RedirectAttributes,
): String {
val token = token(session) ?: return "redirect:/login"
val course = api.courseByUrlNo(token, courseNo)
val course =
try {
api.courseByUrlNo(token, courseNo)
} catch (ex: ApiException) {
redirect.addFlashAttribute("error", ex.message)
return "redirect:/teacher"
}
return try {
val target = groupId.trim().ifBlank { throw ApiException(400, "Выберите группу") }
api.attachCourseGroup(token, course.id, CourseGroupPayload(target))
@@ -112,7 +118,13 @@ class TeacherController(
redirect: RedirectAttributes,
): String {
val token = token(session) ?: return "redirect:/login"
val course = api.courseByUrlNo(token, courseNo)
val course =
try {
api.courseByUrlNo(token, courseNo)
} catch (ex: ApiException) {
redirect.addFlashAttribute("error", ex.message)
return "redirect:/teacher"
}
return try {
api.detachCourseGroup(token, course.id, groupId)
redirect.addFlashAttribute("notice", "Группа отвязана от курса")