Skip to content

Commit

Permalink
EDSC-4125 adds temporal dropdown test for recurring
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-zamora committed Dec 17, 2024
1 parent 40fef94 commit cb9a164
Showing 1 changed file with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,141 @@ describe('TemporalSelectionDropdown component', () => {

expect(onChangeQueryMock).toHaveBeenCalledTimes(1)
})

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'
}
}
})
})
})
})

0 comments on commit cb9a164

Please sign in to comment.