|
|
@ -36,18 +36,17 @@ function setup(initial: TimeRange = defaultTimeRange, timeZone = 'utc'): TimeRan |
|
|
|
describe('TimeRangeForm', () => { |
|
|
|
describe('TimeRangeForm', () => { |
|
|
|
it('should render form correcty', () => { |
|
|
|
it('should render form correcty', () => { |
|
|
|
const { getByLabelText, getByText, getAllByRole } = setup(); |
|
|
|
const { getByLabelText, getByText, getAllByRole } = setup(); |
|
|
|
const { TimePicker } = selectors.components; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(getByText('Apply time range')).toBeInTheDocument(); |
|
|
|
expect(getByText('Apply time range')).toBeInTheDocument(); |
|
|
|
expect(getAllByRole('button', { name: TimePicker.calendar.openButton })).toHaveLength(2); |
|
|
|
expect(getAllByRole('button', { name: 'Open calendar' })).toHaveLength(2); |
|
|
|
expect(getByLabelText(TimePicker.fromField)).toBeInTheDocument(); |
|
|
|
expect(getByLabelText('From')).toBeInTheDocument(); |
|
|
|
expect(getByLabelText(TimePicker.toField)).toBeInTheDocument(); |
|
|
|
expect(getByLabelText('To')).toBeInTheDocument(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should display calendar when clicking the calendar icon', () => { |
|
|
|
it('should display calendar when clicking the calendar icon', () => { |
|
|
|
const { getByLabelText, getAllByRole } = setup(); |
|
|
|
const { getByLabelText, getAllByRole } = setup(); |
|
|
|
const { TimePicker } = selectors.components; |
|
|
|
const { TimePicker } = selectors.components; |
|
|
|
const openCalendarButton = getAllByRole('button', { name: TimePicker.calendar.openButton }); |
|
|
|
const openCalendarButton = getAllByRole('button', { name: 'Open calendar' }); |
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(openCalendarButton[0]); |
|
|
|
fireEvent.click(openCalendarButton[0]); |
|
|
|
expect(getByLabelText(TimePicker.calendar.label)).toBeInTheDocument(); |
|
|
|
expect(getByLabelText(TimePicker.calendar.label)).toBeInTheDocument(); |
|
|
@ -55,24 +54,23 @@ describe('TimeRangeForm', () => { |
|
|
|
|
|
|
|
|
|
|
|
it('should have passed time range entered in form', () => { |
|
|
|
it('should have passed time range entered in form', () => { |
|
|
|
const { getByLabelText } = setup(); |
|
|
|
const { getByLabelText } = setup(); |
|
|
|
const { TimePicker } = selectors.components; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fromValue = defaultTimeRange.raw.from as string; |
|
|
|
const fromValue = defaultTimeRange.raw.from as string; |
|
|
|
const toValue = defaultTimeRange.raw.to as string; |
|
|
|
const toValue = defaultTimeRange.raw.to as string; |
|
|
|
|
|
|
|
|
|
|
|
expect(getByLabelText(TimePicker.fromField)).toHaveValue(fromValue); |
|
|
|
expect(getByLabelText('From')).toHaveValue(fromValue); |
|
|
|
expect(getByLabelText(TimePicker.toField)).toHaveValue(toValue); |
|
|
|
expect(getByLabelText('To')).toHaveValue(toValue); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should close calendar when clicking the close icon', () => { |
|
|
|
it('should close calendar when clicking the close icon', () => { |
|
|
|
const { queryByLabelText, getAllByRole, getByRole } = setup(); |
|
|
|
const { queryByLabelText, getAllByRole, getByRole } = setup(); |
|
|
|
const { TimePicker } = selectors.components; |
|
|
|
const { TimePicker } = selectors.components; |
|
|
|
const openCalendarButton = getAllByRole('button', { name: TimePicker.calendar.openButton }); |
|
|
|
const openCalendarButton = getAllByRole('button', { name: 'Open calendar' }); |
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(openCalendarButton[0]); |
|
|
|
fireEvent.click(openCalendarButton[0]); |
|
|
|
expect(getByRole('button', { name: TimePicker.calendar.closeButton })).toBeInTheDocument(); |
|
|
|
expect(getByRole('button', { name: 'Close calendar' })).toBeInTheDocument(); |
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(getByRole('button', { name: TimePicker.calendar.closeButton })); |
|
|
|
fireEvent.click(getByRole('button', { name: 'Close calendar' })); |
|
|
|
expect(queryByLabelText(TimePicker.calendar.label)).toBeNull(); |
|
|
|
expect(queryByLabelText(TimePicker.calendar.label)).toBeNull(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
@ -85,8 +83,7 @@ describe('TimeRangeForm', () => { |
|
|
|
|
|
|
|
|
|
|
|
it('should have passed time range selected in calendar', () => { |
|
|
|
it('should have passed time range selected in calendar', () => { |
|
|
|
const { getAllByRole, getCalendarDayByLabelText } = setup(); |
|
|
|
const { getAllByRole, getCalendarDayByLabelText } = setup(); |
|
|
|
const { TimePicker } = selectors.components; |
|
|
|
const openCalendarButton = getAllByRole('button', { name: 'Open calendar' }); |
|
|
|
const openCalendarButton = getAllByRole('button', { name: TimePicker.calendar.openButton }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(openCalendarButton[0]); |
|
|
|
fireEvent.click(openCalendarButton[0]); |
|
|
|
const from = getCalendarDayByLabelText('June 17, 2021'); |
|
|
|
const from = getCalendarDayByLabelText('June 17, 2021'); |
|
|
@ -98,8 +95,7 @@ describe('TimeRangeForm', () => { |
|
|
|
|
|
|
|
|
|
|
|
it('should select correct time range in calendar when having a custom time zone', () => { |
|
|
|
it('should select correct time range in calendar when having a custom time zone', () => { |
|
|
|
const { getAllByRole, getCalendarDayByLabelText } = setup(defaultTimeRange, 'Asia/Tokyo'); |
|
|
|
const { getAllByRole, getCalendarDayByLabelText } = setup(defaultTimeRange, 'Asia/Tokyo'); |
|
|
|
const { TimePicker } = selectors.components; |
|
|
|
const openCalendarButton = getAllByRole('button', { name: 'Open calendar' }); |
|
|
|
const openCalendarButton = getAllByRole('button', { name: TimePicker.calendar.openButton }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(openCalendarButton[1]); |
|
|
|
fireEvent.click(openCalendarButton[1]); |
|
|
|
const from = getCalendarDayByLabelText('June 17, 2021'); |
|
|
|
const from = getCalendarDayByLabelText('June 17, 2021'); |
|
|
|