Files
lincodex/frontend/src/features/edit-need/model/steps.test.ts
T

68 lines
2.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { emptyNeedForm, type NeedFormField } from "../../../entities/need";
import {
describeSalary,
firstErrorStep,
lastNeedStep,
needStepOfField,
needSteps,
pendingSuggestionCount,
} from "./steps";
describe("need editor steps", () => {
it("ends with the review step, the only one that saves", () => {
expect(needSteps.map((step) => step.id)).toEqual([
"role",
"skills",
"tasks",
"conditions",
"review",
]);
expect(lastNeedStep).toBe(4);
});
it("maps every form field to a step before the review", () => {
const fields = Object.keys(needStepOfField) as NeedFormField[];
expect(fields).toHaveLength(Object.keys(emptyNeedForm()).length);
for (const field of fields) {
expect(needStepOfField[field]).toBeLessThan(lastNeedStep);
}
});
it("opens the earliest step that holds an error", () => {
expect(firstErrorStep({})).toBeNull();
expect(firstErrorStep({ salary: "x", requiredSkills: "y" })).toBe(1);
expect(firstErrorStep({ title: "x", salary: "y" })).toBe(0);
expect(firstErrorStep({ title: "" })).toBeNull();
});
it("counts only unconfirmed suggestions", () => {
expect(pendingSuggestionCount(emptyNeedForm())).toBe(0);
const form = {
...emptyNeedForm(),
grade: {
status: "extracted" as const,
value: "middle" as const,
source: {
origin: "extracted_from_text" as const,
quote: null,
extractedInVersion: 1,
extractionVersion: "r1",
},
},
};
expect(pendingSuggestionCount(form)).toBe(1);
});
it("writes a salary range with grouped thousands and the tax basis", () => {
const text = describeSalary({
from: 100000,
to: 130000,
currency: "RUB",
period: "month",
taxBasis: "net",
});
expect(text.replaceAll(/\s/g, " ")).toBe("от 100 000 до 130 000 ₽ в месяц, после налога");
});
});