diff --git a/static/src/js/components/TemporalDisplay/__tests__/TemporalSelectionDropdown.test.js b/static/src/js/components/TemporalDisplay/__tests__/TemporalSelectionDropdown.test.js index 0e98751f39..c8bcce2878 100644 --- a/static/src/js/components/TemporalDisplay/__tests__/TemporalSelectionDropdown.test.js +++ b/static/src/js/components/TemporalDisplay/__tests__/TemporalSelectionDropdown.test.js @@ -564,4 +564,141 @@ describe('TemporalSelectionDropdown component', () => { }) }) }) + + describe('TemporalSelectionDropdown recurring and slider behavior', () => { + test('handles recurring toggle and slider interactions correctly', async () => { + const onChangeQueryMock = jest.fn() + const user = userEvent.setup() + + setup({ + onChangeQuery: onChangeQueryMock, + temporalSearch: { + startDate: '2022-03-29T00:00:00.000Z', + endDate: '2024-03-30T00:00:00.000Z', + isRecurring: true + } + }) + + // Open dropdown and verify recurring state + await act(async () => { + await user.click(screen.getByRole('button', { name: 'Open temporal filters' })) + }) + + const startDateInput = screen.getByRole('textbox', { name: 'Start Date' }) + const endDateInput = screen.getByRole('textbox', { name: 'End Date' }) + + // In recurring mode, dates should show without year + expect(startDateInput).toHaveValue('03-29 00:00:00') + expect(endDateInput).toHaveValue('03-30 00:00:00') + expect(screen.getByText('Year Range:')).toBeInTheDocument() + expect(screen.getByText('2022 - 2024')).toBeInTheDocument() + + // Apply recurring state + await act(async () => { + await user.click(screen.getByRole('button', { name: 'Apply' })) + }) + + expect(onChangeQueryMock).toHaveBeenCalledWith({ + collection: { + temporal: { + isRecurring: true, + startDate: expect.stringMatching(/^2022-03-29/), + endDate: expect.stringMatching(/^2024-03-30/), + recurringDayStart: '88', + recurringDayEnd: '89' + } + } + }) + + // Reopen dropdown + await act(async () => { + await user.click(screen.getByRole('button', { name: 'Open temporal filters' })) + }) + + // Find the checkbox and ensure it's checked + const recurringCheckbox = screen.getByRole('checkbox', { checked: true }) + + // Uncheck it + await act(async () => { + await user.click(recurringCheckbox) + await waitFor(() => { + expect(recurringCheckbox).not.toBeChecked() + }) + }) + + // Apply non-recurring state + await act(async () => { + await user.click(screen.getByRole('button', { name: 'Apply' })) + }) + + expect(onChangeQueryMock).toHaveBeenLastCalledWith({ + collection: { + temporal: { + isRecurring: false, + startDate: expect.stringMatching(/^2022-03-29/), + endDate: expect.stringMatching(/^2024-03-30/) + } + } + }) + }) + + test('handles recurring toggle with same year dates', async () => { + const onChangeQueryMock = jest.fn() + const user = userEvent.setup() + + setup({ + onChangeQuery: onChangeQueryMock, + temporalSearch: { + startDate: '2024-03-29T00:00:00.000Z', + endDate: '2024-03-30T00:00:00.000Z', + isRecurring: false + } + }) + + // Open dropdown + await act(async () => { + await user.click(screen.getByRole('button', { name: 'Open temporal filters' })) + }) + + const startDateInput = screen.getByRole('textbox', { name: 'Start Date' }) + const endDateInput = screen.getByRole('textbox', { name: 'End Date' }) + + // Initial non-recurring state + expect(startDateInput).toHaveValue('2024-03-29 00:00:00') + expect(endDateInput).toHaveValue('2024-03-30 00:00:00') + expect(screen.queryByText('Year Range:')).not.toBeInTheDocument() + + // Toggle recurring on + const recurringCheckbox = screen.getByRole('checkbox', { checked: false }) + await act(async () => { + await user.click(recurringCheckbox) + await waitFor(() => { + expect(recurringCheckbox).toBeChecked() + }) + }) + + // In recurring mode, dates should show without year and use minimum year + expect(startDateInput).toHaveValue('03-29 00:00:00') + expect(endDateInput).toHaveValue('03-30 00:00:00') + expect(screen.getByText('Year Range:')).toBeInTheDocument() + expect(screen.getByText('1960 - 2024')).toBeInTheDocument() + + // Apply recurring state + await act(async () => { + await user.click(screen.getByRole('button', { name: 'Apply' })) + }) + + expect(onChangeQueryMock).toHaveBeenCalledWith({ + collection: { + temporal: { + isRecurring: true, + startDate: '1960-03-29T00:00:00.000Z', + endDate: '2024-03-30T00:00:00.000Z', + recurringDayStart: '89', + recurringDayEnd: '90' + } + } + }) + }) + }) })