fix: Apply filterOption to custom select even with options list#64
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #64 +/- ##
=======================================
Coverage 87.00% 87.00%
=======================================
Files 12 12
Lines 531 531
Branches 234 234
=======================================
Hits 462 462
Misses 11 11
Partials 58 58
☔ View full report in Codecov by Sentry. |
|
Hi, Nice catch! Thank you very much for this NICE fix! 🙏 Also, if you want to quickly add a test for what you did it's perfect, if not I could do it in the future 😉 |
|
@xrutayisire Thanks for the comment! I've just applied prettier and pushed. |
|
Exactly you should have some guidance, if you don't succeed, no problem, I will add some after and you could check them. |
|
@xrutayisire I was trying to check that there is only from "Thursday" The code is below: import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import Cron from '../Cron';
import { CronType, DropdownsConfig, PeriodType } from '../types';
const WEEK_DAY_WEDNESDAY = 3
const MONTH_OCTOBER = 9
describe('Cron filter week-days', () => {
it('should ', async () => {
const user = userEvent.setup()
const value = '* * * * *'
const setValue = jest.fn()
const allowedPeriods: PeriodType[] = ['minute', 'month', 'year']
const allowedDropdowns: CronType[] = ['period', 'week-days']
const dropdownsConfig: DropdownsConfig = {
"week-days": {
filterOption: ({ value }) => Number(value) > WEEK_DAY_WEDNESDAY,
},
// "months": {
// filterOption: ({ value }) => Number(value) > MONTH_OCTOBER,
// },
}
render(
<Cron
value={value}
setValue={setValue}
// allowedPeriods={allowedPeriods}
allowedDropdowns={allowedDropdowns}
dropdownsConfig={dropdownsConfig}
/>
)
// Open Period dropdown
await waitFor(() => {
user.click(screen.getByText('minute'))
})
// Select year period
await waitFor(() => {
user.click(screen.getByText('year'))
})
// await waitFor(() => {
// expect(screen.getByTestId('select-period').textContent).toContain('year')
// })
// Open week days dropdown
await waitFor(() => {
user.click(screen.getByTestId('custom-select-week-days'))
// user.click(screen.getByText('every day of the week'))
})
// Check dropdowns value
await waitFor(() => {
// expect(screen.findByText('Monday')).not.toBeInTheDocument()
// expect(screen.findByText('FRI')).toBeNull()
user.click(screen.getByText('Friday'))
})
})
}) |
|
No problem, I will try to add some tests in master soon. I will release tonight your fix. |
|
@xrutayisire May I ask a question? It seems that there is no GHA workflow related to deployment in this repository. Are you deploying new releases manually or in other way? |
|
Sorry, I couldn't find the time. I will do it now and yes it's currently manually. |
|
You can use v5.0.1 |
|
@xrutayisire Sorry, I was not meaning to rush you, but thanks for the quick release! |
|
Not really planned. I did some setup like that in the past. This release process is pretty simple so I never did it, but yeah why not in the future 🙂 No sure about the necessary to use an external use like that tought. Release is so simple for this lib that it may be overkill. |
|
Thanks for everything and happy for new PRs 🙂 |
Hello react-js-cron!
First of all, thanks for maintaining the project.
I was looking for a way to limit
week-days; for example, I want to disallow users to selectSaturdayandSundayfromweek-dayscustom selector. I found thatfilterOptionhas been added since v4.1.0 and tried to use it. It works fine with other types except forweek-daysandmonths, which pass additional argumentoptionsListto<CustomSelect />. And I finally figured out that.filter(filterOption)is not called whenoptionsListexists.🤔 This is a ...
🔗 Related issue link
I haven't reported an issue.
💡 Background and solution
Try this with and without the PR:
☑️ Self Check before Merge