Skip to content

Commit

Permalink
update CONTRIBUTING.MD and add tests to week
Browse files Browse the repository at this point in the history
  • Loading branch information
iMartzen committed Oct 8, 2023
1 parent 12f192f commit 35ff390
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ Start reading our code, and you'll get the hang of it. We optimize for readabili
Local development configuration is pretty snappy. Here's how to get set up:

1. Install/use node >=16.0.0
1. Install/use yarn <=1.x.x
1. Run `yarn link` from project root
1. Run `cd docs-site && yarn link react-datepicker`
1. Run `yarn install` from project root
1. Run `yarn build` from project root (at least the first time, this will get you the `dist` directory that holds the code that will be linked to)
1. Run `yarn start` from project root
1. Run `yarn start` from project root. (This command launches a documentation app and runs it as a simple webserver at http://localhost:3000.)
1. Open new terminal window
1. Run `yarn build-dev` from project root. (This command sets up a development environment that keeps an eye on any file changes. When a file is updated, it auto-builds using the latest code.)

You can run `yarn test` to execute the test suite and linters. To help you develop the component we’ve set up some tests that cover the basic functionality (can be found in `/tests`). Even though we’re big fans of testing, this only covers a small piece of the component. We highly recommend you add tests when you’re adding new functionality.

1. After each JS change run `yarn build:js` in project root
1. After each SCSS change run `yarn run css:dev && yarn run css:modules:dev` in project root
97 changes: 97 additions & 0 deletions test/week_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,101 @@ describe("Week", () => {
day.simulate("mouseenter");
expect(day.prop("day")).toEqual(dayMouseEntered);
});

describe("handleWeekClick", () => {
it("should call onWeekSelect prop with correct arguments", () => {
const onWeekSelect = jest.fn();
const day = new Date("2022-02-01");
const weekNumber = 5;
const event = { target: {} };
const wrapper = shallow(
<Week
onWeekSelect={onWeekSelect}
showWeekPicker={false}
shouldCloseOnSelect={false}
setOpen={() => {}}
/>,
);
wrapper.instance().handleWeekClick(day, weekNumber, event);
expect(onWeekSelect).toHaveBeenCalledWith(day, weekNumber, event);
});

it("should call handleDayClick with start of week if showWeekPicker prop is true", () => {
const handleDayClick = jest.fn();
const day = new Date("2022-02-01");
const weekNumber = 5;
const event = { target: {} };
const wrapper = shallow(
<Week
onWeekSelect={() => {}}
showWeekPicker
shouldCloseOnSelect={false}
setOpen={() => {}}
/>,
);
wrapper.instance().handleDayClick = handleDayClick;
wrapper.instance().handleWeekClick(day, weekNumber, event);
const startOfWeek = utils.getStartOfWeek(day);
expect(handleDayClick).toHaveBeenCalledWith(startOfWeek, event);
});

it("should call setOpen prop with false if shouldCloseOnSelect prop is true", () => {
const setOpen = jest.fn();
const day = new Date("2022-02-01");
const weekNumber = 5;
const event = { target: {} };
const wrapper = shallow(
<Week
onWeekSelect={() => {}}
showWeekPicker={false}
shouldCloseOnSelect
setOpen={setOpen}
/>,
);
wrapper.instance().handleWeekClick(day, weekNumber, event);
expect(setOpen).toHaveBeenCalledWith(false);
});
});

describe("keyboard-selected", () => {
const className = "react-datepicker__week--keyboard-selected";

it("should apply the keyboard-selected class when pre-selected and another week is selected", () => {
const week = utils.newDate();
const selected = utils.addWeeks(week, 1);
const shallowWeek = shallow(
<Week day={week} selected={selected} preSelection={week} />,
);
expect(shallowWeek.hasClass(className)).toBe(true);
});

it("should apply the keyboard-selected class when pre-selected and the same week is selected", () => {
const week = utils.newDate();
const shallowWeek = shallow(
<Week day={week} selected={week} preSelection={week} />,
);
expect(shallowWeek.hasClass(className)).toBe(false);
});
});

describe("selected", () => {
const className = "react-datepicker__week--selected";

it("should apply the selected class when pre-selected and another week is selected", () => {
const week = utils.newDate();
const selected = utils.addWeeks(week, 1);
const shallowWeek = shallow(
<Week day={week} selected={selected} preSelection={week} />,
);
expect(shallowWeek.hasClass(className)).toBe(false);
});

it("should apply the selected class when pre-selected and same week is selected", () => {
const week = utils.newDate();
const shallowWeek = shallow(
<Week day={week} selected={week} preSelection={week} />,
);
expect(shallowWeek.hasClass(className)).toBe(true);
});
});
});

0 comments on commit 35ff390

Please sign in to comment.