feat(support): verify the manual assessment request after a C3 refusal
This commit is contained in:
1 parent
6bfd7098c3
commit
68286af8b7
20 files changed
+680
-74
No files matched your search
@@ -10,6 +10,7 @@ export {
|
||||
} from "./model/submission";
|
||||
export {
|
||||
formatSupportDate,
|
||||
manualAssessmentRubricDescription,
|
||||
supportCaseActorLabels,
|
||||
supportCaseEventKindLabels,
|
||||
supportCaseStatusLabels,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { supportCaseStatusLabels, supportTargetDescription } from "./presentation";
|
||||
import {
|
||||
manualAssessmentRubricDescription,
|
||||
supportCaseStatusLabels,
|
||||
supportTargetDescription,
|
||||
} from "./presentation";
|
||||
|
||||
describe("support case presentation", () => {
|
||||
it("describes operational goals without presenting them as legal deadlines", () => {
|
||||
@@ -18,4 +22,44 @@ describe("support case presentation", () => {
|
||||
it("labels manual assessment as waiting for an expert", () => {
|
||||
expect(supportCaseStatusLabels.waiting_expert).toBe("Ожидает эксперта");
|
||||
});
|
||||
|
||||
it("states honestly when a manual request has no pinned rubric", () => {
|
||||
const copy = manualAssessmentRubricDescription(null, "waiting_expert");
|
||||
|
||||
expect(copy).toContain("рубрики для этой цели на момент запроса не было");
|
||||
expect(copy).toContain("категория не присвоена");
|
||||
expect(copy).toContain("ожидает эксперта");
|
||||
});
|
||||
|
||||
it("shows the pinned policy version", () => {
|
||||
expect(manualAssessmentRubricDescription(3, "waiting_expert")).toContain(
|
||||
"версия политики оценивания 3",
|
||||
);
|
||||
});
|
||||
|
||||
it.each(["submitted", "in_review", "waiting_for_user"] as const)(
|
||||
"keeps the unassigned-category note for the open status %s without the queue note",
|
||||
(status) => {
|
||||
const copy = manualAssessmentRubricDescription(3, status);
|
||||
|
||||
expect(copy).toContain("категория не присвоена");
|
||||
expect(copy).not.toContain("ожидает эксперта");
|
||||
},
|
||||
);
|
||||
|
||||
it("refers a resolved case to its decision instead of claiming no category", () => {
|
||||
const copy = manualAssessmentRubricDescription(null, "resolved");
|
||||
|
||||
expect(copy).toContain("Автоматическая оценка не выполнялась");
|
||||
expect(copy).toContain("решении");
|
||||
expect(copy).not.toContain("категория не присвоена");
|
||||
expect(copy).not.toContain("ожидает эксперта");
|
||||
});
|
||||
|
||||
it("does not claim an unassigned category for a closed case", () => {
|
||||
const copy = manualAssessmentRubricDescription(3, "closed");
|
||||
|
||||
expect(copy).toContain("Автоматическая оценка не выполнялась");
|
||||
expect(copy).not.toContain("категория не присвоена");
|
||||
});
|
||||
});
|
||||
@@ -36,6 +36,33 @@ export const supportCaseActorLabels: Readonly<Record<SupportCaseActorKind, strin
|
||||
system: "Система",
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes the rubric pinned to a manual assessment request. A null version
|
||||
* means that no single current reviewed rubric existed for the target when the
|
||||
* request was created; the request is still valid and no category is assigned
|
||||
* automatically. Once the case is resolved or closed the text no longer claims
|
||||
* that a category is unassigned, because the expert decision may have set one.
|
||||
*/
|
||||
export function manualAssessmentRubricDescription(
|
||||
rubricVersion: number | null,
|
||||
status: SupportCaseStatus,
|
||||
): string {
|
||||
const rubric =
|
||||
rubricVersion === null
|
||||
? "Опубликованной рубрики для этой цели на момент запроса не было."
|
||||
: `Зафиксирована версия политики оценивания ${rubricVersion}.`;
|
||||
switch (status) {
|
||||
case "resolved":
|
||||
return `${rubric} Автоматическая оценка не выполнялась. Итог указан в решении.`;
|
||||
case "closed":
|
||||
return `${rubric} Автоматическая оценка не выполнялась. Обращение закрыто.`;
|
||||
case "waiting_expert":
|
||||
return `${rubric} Автоматическая оценка не выполнялась, категория не присвоена. Запрос ожидает эксперта.`;
|
||||
default:
|
||||
return `${rubric} Автоматическая оценка не выполнялась, категория не присвоена.`;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatSupportDate(value: string): string {
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.valueOf())) return value;
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
import type { CatalogGrade } from "../../../shared/api/schemas";
|
||||
import type { CatalogSpecializationOption } from "../../../entities/specialization";
|
||||
|
||||
export function manualAvailabilityMessage(option: CatalogSpecializationOption | null): string {
|
||||
/**
|
||||
* Explains, before submission, what the catalog says about the automated bank
|
||||
* for the chosen target. The catalog describes tests, not the rubric pin, so the
|
||||
* copy never promises a rubric: the server pins one only when it can identify a
|
||||
* single current reviewed category, and the created case reports the result.
|
||||
*/
|
||||
export function manualAvailabilityMessage(
|
||||
option: CatalogSpecializationOption | null,
|
||||
grade: CatalogGrade["code"] | "" = "",
|
||||
): string {
|
||||
if (!option) return "Выберите специальность, чтобы увидеть ее доступность.";
|
||||
if (option.test_availability.status === "in_development") {
|
||||
return option.test_availability.note
|
||||
? `${option.test_availability.note} Запрос ручной оценки остается доступен.`
|
||||
const availability = option.test_availability;
|
||||
if (availability.status === "in_development") {
|
||||
return availability.note
|
||||
? `${availability.note} Запрос ручной оценки остается доступен.`
|
||||
: "Автоматическая проверка пока не опубликована. Запрос ручной оценки остается доступен.";
|
||||
}
|
||||
if (grade && !availability.grades.includes(grade)) {
|
||||
return "Для выбранного грейда автоматическая проверка не опубликована, поэтому рубрика может не быть зафиксирована. Запрос ручной оценки остается доступен и ждет эксперта.";
|
||||
}
|
||||
if (grade) {
|
||||
return "Для выбранного грейда есть опубликованный банк. Сервер зафиксирует рубрику, только если для цели найдется единственная актуальная категория; запрос в любом случае уйдет эксперту и не запускает тест.";
|
||||
}
|
||||
return "Автоматическая проверка опубликована отдельно. Этот запрос направляется эксперту и не запускает тест.";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { supportCaseCreateFailureMessage } from "../../../entities/support-case";
|
||||
import { ApiRequestError } from "../../../shared/api";
|
||||
|
||||
/**
|
||||
* A second manual request for the same specialization conflicts with the open
|
||||
* one. This happens after a reload, when the form has lost its idempotency
|
||||
* key, and it must lead the candidate to the existing request instead of
|
||||
* suggesting that the data is stale.
|
||||
*/
|
||||
export function manualRequestFailureMessage(error: unknown): string {
|
||||
if (error instanceof ApiRequestError && error.code === "state_conflict") {
|
||||
return "Для этой специальности уже есть открытый запрос ручной оценки. Второй запрос не создается: откройте «Мои обращения», чтобы посмотреть его статус.";
|
||||
}
|
||||
return supportCaseCreateFailureMessage(error);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { renderToString } from "react-dom/server";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ApiRequestError } from "../../../shared/api";
|
||||
import { paths } from "../../../shared/config";
|
||||
import { ManualRequestFailure } from "./manual-request-failure";
|
||||
|
||||
function render(error: unknown): string {
|
||||
return renderToString(
|
||||
<MemoryRouter>
|
||||
<ManualRequestFailure id="failure" error={error} />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("manual assessment failure notice", () => {
|
||||
it("explains a state_conflict as an open request and links to the case list", () => {
|
||||
const html = render(
|
||||
new ApiRequestError({ status: 409, code: "state_conflict", title: "Conflict" }),
|
||||
);
|
||||
|
||||
expect(html).toContain('role="alert"');
|
||||
expect(html).toContain("уже есть открытый запрос ручной оценки");
|
||||
expect(html).toContain(`href="${paths.candidate.supportCases}"`);
|
||||
expect(html).toContain("Мои обращения");
|
||||
expect(html).not.toContain("Обновите страницу");
|
||||
});
|
||||
|
||||
it("does not add the case-list link to other failures", () => {
|
||||
const html = render(
|
||||
new ApiRequestError({ status: 429, code: "rate_limited", title: "Slow down" }),
|
||||
);
|
||||
|
||||
expect(html).toContain("Слишком много запросов");
|
||||
expect(html).not.toContain("Мои обращения");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { Ref } from "react";
|
||||
import { ApiRequestError } from "../../../shared/api";
|
||||
import { paths } from "../../../shared/config";
|
||||
import { TextLink } from "../../../shared/ui";
|
||||
import { manualRequestFailureMessage } from "../model/failure-message";
|
||||
import styles from "./request-manual-assessment.module.css";
|
||||
|
||||
type ManualRequestFailureProps = {
|
||||
id: string;
|
||||
error: unknown;
|
||||
innerRef?: Ref<HTMLDivElement>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Failed submission notice. For a conflict with an open request it links to
|
||||
* the case list, where the existing request and its status can be opened.
|
||||
*/
|
||||
export function ManualRequestFailure({ id, error, innerRef }: ManualRequestFailureProps) {
|
||||
const isOpenRequestConflict = error instanceof ApiRequestError && error.code === "state_conflict";
|
||||
return (
|
||||
<div id={id} className={styles.error} role="alert" tabIndex={-1} ref={innerRef}>
|
||||
{manualRequestFailureMessage(error)}
|
||||
{isOpenRequestConflict ? (
|
||||
<>
|
||||
{" "}
|
||||
<TextLink to={paths.candidate.supportCases}>Мои обращения</TextLink>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { CatalogSpecializationOption } from "../../../entities/specialization";
|
||||
import { ApiRequestError } from "../../../shared/api";
|
||||
import { manualAvailabilityMessage } from "../model/availability-message";
|
||||
import { manualRequestFailureMessage } from "../model/failure-message";
|
||||
|
||||
const unavailableOption: CatalogSpecializationOption = {
|
||||
code: "ds_ml",
|
||||
@@ -36,4 +38,60 @@ describe("manual assessment availability copy", () => {
|
||||
|
||||
expect(copy).toContain("не запускает тест");
|
||||
});
|
||||
|
||||
it("does not promise a rubric for a grade without a published bank", () => {
|
||||
const copy = manualAvailabilityMessage(
|
||||
{
|
||||
...unavailableOption,
|
||||
test_availability: {
|
||||
status: "available",
|
||||
grades: ["junior"],
|
||||
task_languages: ["go"],
|
||||
note: null,
|
||||
},
|
||||
},
|
||||
"senior",
|
||||
);
|
||||
|
||||
expect(copy).toContain("рубрика может не быть зафиксирована");
|
||||
expect(copy).toContain("остается доступен");
|
||||
});
|
||||
|
||||
it("describes a published bank for the chosen grade without starting a test", () => {
|
||||
const copy = manualAvailabilityMessage(
|
||||
{
|
||||
...unavailableOption,
|
||||
test_availability: {
|
||||
status: "available",
|
||||
grades: ["junior"],
|
||||
task_languages: ["go"],
|
||||
note: null,
|
||||
},
|
||||
},
|
||||
"junior",
|
||||
);
|
||||
|
||||
expect(copy).toContain("не запускает тест");
|
||||
expect(copy).toContain("только если");
|
||||
expect(copy).not.toContain("зафиксирует версию рубрики при отправке");
|
||||
});
|
||||
});
|
||||
|
||||
describe("manual assessment failure copy", () => {
|
||||
it("sends a duplicate request to the existing case instead of a stale-data hint", () => {
|
||||
const error = new ApiRequestError({
|
||||
status: 409,
|
||||
code: "state_conflict",
|
||||
title: "Conflict",
|
||||
});
|
||||
|
||||
expect(manualRequestFailureMessage(error)).toContain("уже есть открытый запрос");
|
||||
expect(manualRequestFailureMessage(error)).toContain("Мои обращения");
|
||||
});
|
||||
|
||||
it("keeps the generic copy for other failures", () => {
|
||||
const error = new ApiRequestError({ status: 429, code: "rate_limited", title: "Slow down" });
|
||||
|
||||
expect(manualRequestFailureMessage(error)).toContain("Слишком много запросов");
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
getSupportCaseIdempotencyKey,
|
||||
isSupportSessionAccessError,
|
||||
queryClientHasSupportActor,
|
||||
supportCaseCreateFailureMessage,
|
||||
supportCaseDetailQueryKey,
|
||||
supportCaseListQueryKey,
|
||||
supportCasePathFor,
|
||||
@@ -39,6 +38,7 @@ import {
|
||||
Section,
|
||||
TextLink,
|
||||
} from "../../../shared/ui";
|
||||
import { ManualRequestFailure } from "./manual-request-failure";
|
||||
import styles from "./request-manual-assessment.module.css";
|
||||
|
||||
export function RequestManualAssessment() {
|
||||
@@ -55,7 +55,7 @@ export function RequestManualAssessment() {
|
||||
const [specializationCode, setSpecializationCode] = useState<SpecializationCode | "">("");
|
||||
const [gradeCode, setGradeCode] = useState<CatalogGrade["code"] | "">("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [actionError, setActionError] = useState<string | null>(null);
|
||||
const [failure, setFailure] = useState<{ error: unknown } | null>(null);
|
||||
const options = useMemo(
|
||||
() => (catalog.data ? listSpecializationOptions(catalog.data) : []),
|
||||
[catalog.data],
|
||||
@@ -81,8 +81,8 @@ export function RequestManualAssessment() {
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (actionError) errorRef.current?.focus();
|
||||
}, [actionError]);
|
||||
if (failure) errorRef.current?.focus();
|
||||
}, [failure]);
|
||||
|
||||
useEffect(() => {
|
||||
const accountId = actor?.account.id ?? knownActor?.account.id;
|
||||
@@ -165,7 +165,7 @@ export function RequestManualAssessment() {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setActionError(null);
|
||||
setFailure(null);
|
||||
const data: SupportCaseCreate = {
|
||||
type: "manual_assessment",
|
||||
description,
|
||||
@@ -189,7 +189,7 @@ export function RequestManualAssessment() {
|
||||
if (error instanceof ApiRequestError && error.code === "idempotency_key_reused") {
|
||||
idempotencyBinding.current = null;
|
||||
}
|
||||
setActionError(supportCaseCreateFailureMessage(error));
|
||||
setFailure({ error });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -204,7 +204,8 @@ export function RequestManualAssessment() {
|
||||
<Section title="Запрос ручной оценки">
|
||||
<p className={styles.intro}>
|
||||
Вы выбираете специальность и желаемый грейд. Эксперт рассмотрит запрос по рубрике этой
|
||||
категории, если она опубликована. Запрос доступен до первой попытки и не требует C3.
|
||||
категории, если она опубликована. Запрос доступен до первого теста, после неудачной
|
||||
попытки и без согласия C3.
|
||||
</p>
|
||||
<p className={styles.privacy}>
|
||||
Отправка не включает и не меняет C3, не создает попытку и не меняет подтвержденный грейд.{" "}
|
||||
@@ -230,8 +231,8 @@ export function RequestManualAssessment() {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<p id={`${formId}-availability`} className={styles.hint}>
|
||||
{manualAvailabilityMessage(specialization)}
|
||||
<p id={`${formId}-availability`} className={styles.hint} aria-live="polite">
|
||||
{manualAvailabilityMessage(specialization, gradeCode)}
|
||||
</p>
|
||||
</div>
|
||||
<div className={styles.field}>
|
||||
@@ -243,6 +244,7 @@ export function RequestManualAssessment() {
|
||||
setGradeCode(event.currentTarget.value as CatalogGrade["code"] | "")
|
||||
}
|
||||
disabled={isSubmitting}
|
||||
aria-describedby={`${formId}-availability ${formId}-grade-hint`}
|
||||
required
|
||||
>
|
||||
<option value="">Выберите грейд</option>
|
||||
@@ -252,7 +254,9 @@ export function RequestManualAssessment() {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<p className={styles.hint}>Это желаемая цель оценки, а не подтвержденный результат.</p>
|
||||
<p id={`${formId}-grade-hint`} className={styles.hint}>
|
||||
Это желаемая цель оценки, а не подтвержденный результат.
|
||||
</p>
|
||||
</div>
|
||||
<div className={styles.field}>
|
||||
<label htmlFor={`${formId}-description`}>Почему вы просите ручную оценку</label>
|
||||
@@ -264,22 +268,18 @@ export function RequestManualAssessment() {
|
||||
maxLength={4000}
|
||||
required
|
||||
disabled={isSubmitting}
|
||||
aria-describedby={`${formId}-description-hint${actionError ? ` ${formId}-error` : ""}`}
|
||||
aria-describedby={`${formId}-description-hint${failure ? ` ${formId}-error` : ""}`}
|
||||
/>
|
||||
<p id={`${formId}-description-hint`} className={styles.hint}>
|
||||
Можно отправить запрос без предыдущей попытки. До 4000 символов.
|
||||
Предыдущая попытка не нужна. До 4000 символов.
|
||||
</p>
|
||||
</div>
|
||||
{actionError ? (
|
||||
<div
|
||||
{failure ? (
|
||||
<ManualRequestFailure
|
||||
id={`${formId}-error`}
|
||||
className={styles.error}
|
||||
role="alert"
|
||||
tabIndex={-1}
|
||||
ref={errorRef}
|
||||
>
|
||||
{actionError}
|
||||
</div>
|
||||
error={failure.error}
|
||||
innerRef={errorRef}
|
||||
/>
|
||||
) : null}
|
||||
<div className={styles.actions}>
|
||||
<Button type="submit" isBusy={isSubmitting} aria-disabled={!canSubmit}>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useParams } from "react-router-dom";
|
||||
import {
|
||||
formatSupportDate,
|
||||
isSupportSessionAccessError,
|
||||
manualAssessmentRubricDescription,
|
||||
supportCaseActorLabels,
|
||||
supportCaseDetailQueryKey,
|
||||
supportCaseEventKindLabels,
|
||||
@@ -508,9 +509,7 @@ function SupportCaseDetails({
|
||||
<>
|
||||
<dt>Рубрика</dt>
|
||||
<dd>
|
||||
{supportCase.rubric_version === null
|
||||
? "Опубликованной рубрики для этой категории пока нет. Запрос ожидает эксперта; автоматическая оценка не выполнялась."
|
||||
: `Зафиксирована версия ${supportCase.rubric_version}. Запрос ожидает эксперта.`}
|
||||
{manualAssessmentRubricDescription(supportCase.rubric_version, supportCase.status)}
|
||||
</dd>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
Reference in new issue
Block a user