Skip to content

Commit

Permalink
test(dropdownsConfig): Add tests on filterOption
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire committed Nov 8, 2023
1 parent 3ea350e commit 95af1fa
Showing 1 changed file with 70 additions and 5 deletions.
75 changes: 70 additions & 5 deletions src/tests/Cron.updateValue.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Cron update value test suite', () => {

render(<Cron value={value} setValue={setValue} />)

// Open minute dropdown
// Clear cron value
await waitFor(() => {
user.click(screen.getByText('Clear'))
})
Expand All @@ -136,7 +136,7 @@ describe('Cron update value test suite', () => {

render(<Cron value={value} setValue={setValue} clearButtonAction='empty' />)

// Open minute dropdown
// Clear cron value
await waitFor(() => {
user.click(screen.getByText('Clear'))
})
Expand All @@ -156,7 +156,7 @@ describe('Cron update value test suite', () => {

render(<Cron value={value} setValue={setValue} shortcuts={true} />)

// Open minute dropdown
// Clear cron value
await waitFor(() => {
user.click(screen.getByText('Clear'))
})
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('Cron update value test suite', () => {
/>
)

// Open minute dropdown
// Clear cron value
await waitFor(() => {
user.click(screen.getByText('Clear'))
})
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('Cron update value test suite', () => {
/>
)

// Open minute dropdown
// Clear cron value
await waitFor(() => {
user.click(screen.getByText('Clear'))
})
Expand Down Expand Up @@ -269,4 +269,69 @@ describe('Cron update value test suite', () => {
// Check dropdowns values still the sane
expect(await screen.findByText('1,4')).toBeVisible()
})

it('should check that week-days and minutes options are filtered with dropdownConfig', async () => {
const user = userEvent.setup()
const value = '4,6 * * * 1'
const setValue = jest.fn()

render(
<Cron
value={value}
setValue={setValue}
dropdownsConfig={{
'minutes': {
// Remove minute 59 and 58
filterOption: ({ value }) => Number(value) < 58,
},
'week-days': {
// Remove sunday
filterOption: ({ value }) => Number(value) !== 0,
},
}}
/>
)

// Open minutes dropdown
await waitFor(() => {
user.click(screen.getByText('4,6'))
})

// Check minutes
await waitFor(() => {
for (let i = 0; i < 60; i++) {
if (i < 58) {
expect(screen.getByText(i)).toBeVisible()
} else {
expect(screen.queryByText(58)).not.toBeInTheDocument()

This comment has been minimized.

Copy link
@rapsealk

rapsealk Nov 8, 2023

Contributor

These two lines can be simplified:

expect(screen.queryByText(i)).not.toBeInTheDocument()

This comment has been minimized.

Copy link
@xrutayisire

xrutayisire Nov 8, 2023

Author Owner

Yeah I did it manually, forgot to remove it, thanks 🙂

expect(screen.queryByText(59)).not.toBeInTheDocument()
}
}
})

// Open week-days dropdown
await waitFor(() => {
user.click(screen.getByText('MON'))
})

// Check days of the week
await waitFor(() => {
const days = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
]
for (let i = 0; i < 7; i++) {
if (i === 0) {
expect(screen.queryByText(days[i])).not.toBeInTheDocument()
} else {
expect(screen.getByText(days[i])).toBeVisible()
}
}
})
})
})

0 comments on commit 95af1fa

Please sign in to comment.