|
|
@ -1,4 +1,4 @@ |
|
|
import { fireEvent, render, screen } from "@testing-library/react"; |
|
|
|
|
|
|
|
|
import { cleanup, fireEvent, render, screen } from "@testing-library/react"; |
|
|
import { beforeEach, describe, expect, it, vi } from "vitest"; |
|
|
import { beforeEach, describe, expect, it, vi } from "vitest"; |
|
|
import type { QuestionField } from "@/lib/schema-adapter"; |
|
|
import type { QuestionField } from "@/lib/schema-adapter"; |
|
|
import { QuestionDate } from "./question-date"; |
|
|
import { QuestionDate } from "./question-date"; |
|
|
@ -36,6 +36,7 @@ const question = { |
|
|
|
|
|
|
|
|
describe("QuestionDate", () => { |
|
|
describe("QuestionDate", () => { |
|
|
beforeEach(() => { |
|
|
beforeEach(() => { |
|
|
|
|
|
cleanup(); |
|
|
answerValue = null; |
|
|
answerValue = null; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
@ -57,4 +58,16 @@ describe("QuestionDate", () => { |
|
|
const yearWheel = screen.getByLabelText("Year"); |
|
|
const yearWheel = screen.getByLabelText("Year"); |
|
|
expect(yearWheel.textContent).not.toMatch(/[,٬]/); |
|
|
expect(yearWheel.textContent).not.toMatch(/[,٬]/); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it("handles invalid date strings gracefully without throwing RangeError", () => { |
|
|
|
|
|
answerValue = "Mortezaei"; |
|
|
|
|
|
const { rerender } = render(<QuestionDate question={question} />); |
|
|
|
|
|
expect(screen.queryByText("Age")).toBeNull(); |
|
|
|
|
|
expect(screen.getByText("Select date")).toBeDefined(); |
|
|
|
|
|
|
|
|
|
|
|
answerValue = "invalid-date-format"; |
|
|
|
|
|
rerender(<QuestionDate question={question} />); |
|
|
|
|
|
expect(screen.queryByText("Age")).toBeNull(); |
|
|
|
|
|
expect(screen.getByText("Select date")).toBeDefined(); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |