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
@@ -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}>
|
||||
|
||||
Reference in new issue
Block a user