Skip to content

Commit

Permalink
refactor: Improve code readability and maintainability
Browse files Browse the repository at this point in the history
In this commit, I've mad the following enhancements to the code:
1. Split the test-cases and move the test-case for checking the aria-disabled attribute to a separate it block.
2. Changed the use of the magic number 4 to the length of the input array excludeTimes for better flexibility and maintainability.

Closes Hacker0x01#4334
  • Loading branch information
Balaji Sridharan committed Oct 21, 2023
1 parent 7ad0d20 commit 55ef1a7
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions test/exclude_times_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,37 @@ import { setTime, newDate } from "../src/date_utils";
import DatePicker from "../src/index.jsx";

describe("DatePicker", () => {
let now, excludeTimes;

beforeEach(() => {
now = newDate();
excludeTimes = [
setTime(now, { hour: 17, minute: 0 }),
setTime(now, { hour: 18, minute: 30 }),
setTime(now, { hour: 19, minute: 30 }),
setTime(now, { hour: 17, minute: 30 }),
];
});

it("should disable times specified in excludeTimes props", () => {
const now = newDate();
const { container: datePicker } = render(
<DatePicker open showTimeSelect excludeTimes={excludeTimes} />,
);

const disabledTimeItems = datePicker.querySelectorAll(
".react-datepicker__time-list-item--disabled",
);
expect(disabledTimeItems.length).toBe(excludeTimes.length);
});

it("should add aria-disabled to all the excluded times", () => {
const { container: datePicker } = render(
<DatePicker
open
showTimeSelect
excludeTimes={[
setTime(now, { hour: 17, minute: 0 }),
setTime(now, { hour: 18, minute: 30 }),
setTime(now, { hour: 19, minute: 30 }),
setTime(now, { hour: 17, minute: 30 }),
]}
/>,
<DatePicker open showTimeSelect excludeTimes={excludeTimes} />,
);

const disabledTimeItems = datePicker.querySelectorAll(
".react-datepicker__time-list-item--disabled",
);
expect(disabledTimeItems.length).toBe(4);

const allDisabledTimeItemsHaveAriaDisabled = Array.from(
disabledTimeItems,
Expand Down

0 comments on commit 55ef1a7

Please sign in to comment.