mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
Merge b284e9d125 into f8f12a270a
This commit is contained in:
commit
9de04bbfbd
2 changed files with 27 additions and 1 deletions
|
|
@ -339,6 +339,32 @@ describe("AdvancedDatePicker", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["Start date", "2025-01-02", new Date(2025, 0, 2), new Date(2025, 0, 31, 23, 59, 59, 999)],
|
||||
["End date", "2025-01-30", new Date(2025, 0, 1), new Date(2025, 0, 30, 23, 59, 59, 999)],
|
||||
])("requires a cleared %s before applying the edited range", async (label, replacement, from, to) => {
|
||||
render(<AdvancedDatePicker value={defaultValue} onValueChange={mockOnValueChange} />);
|
||||
fireEvent.click(screen.getByRole("button", { expanded: false }));
|
||||
|
||||
const input = screen.getByLabelText(label);
|
||||
fireEvent.change(input, { target: { value: "" } });
|
||||
|
||||
expect(screen.getByRole("button", { name: "Apply" })).toBeDisabled();
|
||||
expect(screen.getByText("Start and end dates are required")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Apply" }));
|
||||
expect(mockOnValueChange).not.toHaveBeenCalled();
|
||||
expect(input).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(input, { target: { value: replacement } });
|
||||
expect(screen.queryByText("Start and end dates are required")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Apply" })).toBeEnabled();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Apply" }));
|
||||
|
||||
expect(mockOnValueChange).toHaveBeenNthCalledWith(1, { from, to }, null);
|
||||
await waitFor(() => expect(mockOnValueChange).toHaveBeenNthCalledWith(2, { from, to }, null));
|
||||
expect(screen.queryByLabelText(label)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should label compact custom date inputs, validate their order and apply the corrected range", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<AdvancedDatePicker value={defaultValue} onValueChange={mockOnValueChange} compact />);
|
||||
|
|
@ -67,7 +67,7 @@ const AdvancedDatePicker: React.FC<AdvancedDatePickerProps> = ({
|
|||
// Validation logic - simplified for dates only
|
||||
const validateDateRange = useCallback(() => {
|
||||
if (!startDate || !endDate) {
|
||||
return { isValid: true, error: "" };
|
||||
return { isValid: false, error: "Start and end dates are required" };
|
||||
}
|
||||
|
||||
const start = moment(startDate, "YYYY-MM-DD");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue