Added complete validation for expert claim submit state

This commit is contained in:
SepehrYahyaee
2026-09-05 17:33:23 +03:30
parent feacad58ca
commit e48dffef89
6 changed files with 166 additions and 20 deletions

View File

@@ -1,19 +1,92 @@
import { getExpertReplyPricingValidationError } from "./expert-reply-pricing";
import { TypeOfDamage } from "src/Types&Enums/claim-request-management/type-of-damage.enum";
import { DaghiOption } from "src/Types&Enums/claim-request-management/daghi-option.enum";
describe("getExpertReplyPricingValidationError", () => {
it("rejects a blank pricing line", () => {
expect(
getExpertReplyPricingValidationError([
{ partId: 201, price: "", salary: "", totalPayment: "" },
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
price: "",
salary: "",
totalPayment: "",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toMatch(/requires valid price, salary, and totalPayment/);
).toMatch(/requires valid salary and totalPayment/);
});
it("accepts a fully priced line with a zero-valued split", () => {
expect(
getExpertReplyPricingValidationError([
{ partId: 201, price: "0", salary: "10000", totalPayment: "10000" },
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
price: "0",
salary: "10000",
totalPayment: "10000",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toBeNull();
});
it("rejects a repair line without a price", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
salary: "0",
totalPayment: "0",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toMatch(/price is also required/);
});
it("rejects recycled-value daghi without its price", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Change,
salary: "0",
totalPayment: "0",
daghi: { option: DaghiOption.RECYCLED_PARTS_VALUE },
},
]),
).toMatch(/requires a valid daghi price/);
});
it("accepts a replacement line without a part price", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Change,
salary: "0",
totalPayment: "0",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toBeNull();
});
it("rejects an invalid price when a replacement line supplies one", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Change,
price: "not-a-number",
salary: "0",
totalPayment: "0",
daghi: { option: DaghiOption.NO_VALUE },
},
]),
).toMatch(/requires valid salary and totalPayment/);
});
});