fix(web): устойчивые ошибки courseNo и login E2E
This commit is contained in:
@@ -74,7 +74,10 @@ async function login(page: Page, login: string, password: string, expectedPath:
|
|||||||
await page.goto("/login");
|
await page.goto("/login");
|
||||||
await page.fill("#login", login);
|
await page.fill("#login", login);
|
||||||
await page.fill("#password", password);
|
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 }) => {
|
test.beforeAll(async ({ playwright }) => {
|
||||||
|
|||||||
@@ -61,7 +61,12 @@ class AdminLabController(
|
|||||||
model: Model,
|
model: Model,
|
||||||
): String {
|
): String {
|
||||||
val t = token(session)
|
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("labs", api.listLabs(t, selected?.id))
|
||||||
model.addAttribute("courses", coursesFor(session))
|
model.addAttribute("courses", coursesFor(session))
|
||||||
model.addAttribute("selectedCourseNo", selected?.courseNo)
|
model.addAttribute("selectedCourseNo", selected?.courseNo)
|
||||||
|
|||||||
@@ -92,7 +92,13 @@ class TeacherController(
|
|||||||
redirect: RedirectAttributes,
|
redirect: RedirectAttributes,
|
||||||
): String {
|
): String {
|
||||||
val token = token(session) ?: return "redirect:/login"
|
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 {
|
return try {
|
||||||
val target = groupId.trim().ifBlank { throw ApiException(400, "Выберите группу") }
|
val target = groupId.trim().ifBlank { throw ApiException(400, "Выберите группу") }
|
||||||
api.attachCourseGroup(token, course.id, CourseGroupPayload(target))
|
api.attachCourseGroup(token, course.id, CourseGroupPayload(target))
|
||||||
@@ -112,7 +118,13 @@ class TeacherController(
|
|||||||
redirect: RedirectAttributes,
|
redirect: RedirectAttributes,
|
||||||
): String {
|
): String {
|
||||||
val token = token(session) ?: return "redirect:/login"
|
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 {
|
return try {
|
||||||
api.detachCourseGroup(token, course.id, groupId)
|
api.detachCourseGroup(token, course.id, groupId)
|
||||||
redirect.addFlashAttribute("notice", "Группа отвязана от курса")
|
redirect.addFlashAttribute("notice", "Группа отвязана от курса")
|
||||||
|
|||||||
Reference in New Issue
Block a user