mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 01:39:01 +08:00
feat: custom time frame is updated (#2564)
This commit is contained in:
parent
813eeb6d5a
commit
fb1e823e6b
@ -0,0 +1,42 @@
|
|||||||
|
import { fireEvent, render, screen } from '@testing-library/react';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import CustomDateTimeModal from './index';
|
||||||
|
|
||||||
|
describe('CustomDateTimeModal', () => {
|
||||||
|
const handleCreate = jest.fn();
|
||||||
|
const handleCancel = jest.fn();
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
render(
|
||||||
|
<CustomDateTimeModal
|
||||||
|
visible
|
||||||
|
onCreate={handleCreate}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders the modal with title and buttons', () => {
|
||||||
|
expect(screen.getByText('Chose date and time range')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Apply')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Cancel')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('donot calls onCreate when the Apply button is clicked without selecting dates', () => {
|
||||||
|
fireEvent.click(screen.getByText('Apply'));
|
||||||
|
|
||||||
|
expect(handleCreate).toHaveBeenCalledTimes(0);
|
||||||
|
expect(handleCreate).not.toHaveBeenCalledWith(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('calls onCancel when Cancel button is clicked', () => {
|
||||||
|
fireEvent.click(screen.getByText('Cancel'));
|
||||||
|
|
||||||
|
expect(handleCancel).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable react/jsx-no-bind */
|
|
||||||
import { DatePicker, Modal } from 'antd';
|
import { DatePicker, Modal } from 'antd';
|
||||||
import dayjs, { Dayjs } from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
@ -12,18 +11,21 @@ function CustomDateTimeModal({
|
|||||||
onCreate,
|
onCreate,
|
||||||
onCancel,
|
onCancel,
|
||||||
}: CustomDateTimeModalProps): JSX.Element {
|
}: CustomDateTimeModalProps): JSX.Element {
|
||||||
const [customDateTimeRange, setCustomDateTimeRange] = useState();
|
const [selectedDate, setDateTime] = useState<DateTimeRangeType>();
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
const onModalOkHandler = (date_time: any): void => {
|
||||||
function handleRangePickerOk(date_time: any): void {
|
onCreate(date_time);
|
||||||
setCustomDateTimeRange(date_time);
|
setDateTime(date_time);
|
||||||
}
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
const disabledDate = (current: Dayjs): boolean => {
|
||||||
function disabledDate(current: any): boolean {
|
|
||||||
const currentDay = dayjs(current);
|
const currentDay = dayjs(current);
|
||||||
return currentDay.isAfter(dayjs());
|
return currentDay.isAfter(dayjs());
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const onOk = (): void => {
|
||||||
|
if (selectedDate) onCreate(selectedDate);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
@ -32,13 +34,14 @@ function CustomDateTimeModal({
|
|||||||
okText="Apply"
|
okText="Apply"
|
||||||
cancelText="Cancel"
|
cancelText="Cancel"
|
||||||
onCancel={onCancel}
|
onCancel={onCancel}
|
||||||
style={{ position: 'absolute', top: 60, right: 40 }}
|
onOk={onOk}
|
||||||
onOk={(): void => onCreate(customDateTimeRange || null)}
|
|
||||||
>
|
>
|
||||||
<RangePicker
|
<RangePicker
|
||||||
disabledDate={disabledDate}
|
disabledDate={disabledDate}
|
||||||
onOk={handleRangePickerOk}
|
allowClear
|
||||||
|
onOk={onModalOkHandler}
|
||||||
showTime
|
showTime
|
||||||
|
onCalendarChange={onModalOkHandler}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user