React95
React95 copied to clipboard
DatePicker: Write tests and refactor
The DatePicker component is already created and it's functional, but it was written some time ago and it can be refactored (migrating from class-based to hooks). In order to achieve a good result, we also need a good test coverage.
Running storybook locally
- Fork and clone the repo
- Install the necessary dependêncies using npm (run
npm ion the root folder) - Start storybook locally by running
npm start, this will start a local server and opens a tab on your browser automatically - Uncomment the code on
src/DatePicker/DatePicker.stories.jsfile in order to make it appear - Create a
DatePicker.spec.jsfile on the same folder to write tests
Aditional information
We're using React Testing Library to unit test our components and we have a good test coverage, so you can rely on the existing ones.
Before start working on this bug leave a comment here so we can avoid more than one person working on the issue, if you have any doubts feel free to drop a comment here or join us at Slack 🕺
hi! can i work on this?
@luckened For sure! Feel free to drop questions here if you need anything 🚀
@luizbaldi please take a look :mag:
@luckened great work! We have to decide on some things tho and modify couple of things in the DatePicker that were not well planned from the beginning (which is my fault).
- DatePicker should only consist of month input, year input and date selector. Wrapping it in a
Windowcomponent withWindowHeaderwith hardcoded title is really limiting. That's why we should only care about making this part:
-
Currently we have hardcoded months and week days which will cause problems with internationalization. We should let developers pass their own labels for both months and weekday symbols.
-
dateprop should accept any parsable date (like for example string in 'YYYY-MM-DD' format), not onlyDateobject. -
I have no idea how I missed it but... there's whole one row of days missing 😂 See the comparison between our component and the correctly working one (day 30 and 31 is missing):

This should be a minor change in code. I think we need to change 35 in this line: const dayPickerItems = Array.apply(null, { length: 35 }); to 42 since it's 6 rows * 7 days
-
Accessibility: aria-labels and proper keyboard controls for date selection
-
We need to have good tests in place before we release this component. I would suggest to simply copy test cases from some good datepicker library (https://github.com/Hacker0x01/react-datepicker/tree/master/test) so we don't miss anything
@arturbien thanks for the feedback! ❤️ I will work on it and keep you informed if I have any questions =)