Skip to content

Commit

Permalink
fix YearDropdownOptions test.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki0410-dev committed Jun 10, 2024
1 parent 9a6769f commit 3054d56
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/test/year_dropdown_options_test.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, fireEvent } from "@testing-library/react";
import React from "react";
import onClickOutside from "react-onclickoutside";

import * as utils from "../date_utils";
import { addYears, getYear, newDate, subYears } from "../date_utils";
import YearDropdownOptions from "../year_dropdown_options";

describe("YearDropdownOptions", () => {
Expand Down Expand Up @@ -219,14 +219,14 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {
it("should generate years between minDate and maxDate if prop scrollableYearDropdown is true", () => {
const onCancelSpy = jest.fn();
const onChangeSpy = jest.fn();
const minDate = utils.newDate();
const maxDate = utils.addYears(utils.newDate(), 1);
const minDate = newDate();
const maxDate = addYears(newDate(), 1);
const { container } = render(
<YearDropdownOptions
onCancel={onCancelSpy}
onChange={onChangeSpy}
scrollableYearDropdown
year={utils.getYear(utils.newDate())}
year={getYear(newDate())}
minDate={minDate}
maxDate={maxDate}
/>,
Expand All @@ -238,21 +238,21 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {
.map((node) => node.textContent?.replace("✓", ""));

expect(yearsList.length).toBe(2);
expect(yearsList).toContain(`${utils.getYear(minDate)}`);
expect(yearsList).toContain(`${utils.getYear(maxDate)}`);
expect(yearsList).toContain(`${getYear(minDate)}`);
expect(yearsList).toContain(`${getYear(maxDate)}`);
});

it("should hide arrows to add years, if not between minDate and maxDate", () => {
const onCancelSpy = jest.fn();
const onChangeSpy = jest.fn();
const minDate = utils.newDate();
const maxDate = utils.addYears(utils.newDate(), 1);
const minDate = newDate();
const maxDate = addYears(newDate(), 1);
const { container } = render(
<YearDropdownOptions
onCancel={onCancelSpy}
onChange={onChangeSpy}
scrollableYearDropdown
year={utils.getYear(utils.newDate())}
year={getYear(newDate())}
minDate={minDate}
maxDate={maxDate}
/>,
Expand All @@ -273,14 +273,14 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {
it("should show arrows to add years, if actual years list contains years between minDate and maxDate", () => {
const onCancelSpy = jest.fn();
const onChangeSpy = jest.fn();
const minDate = utils.subYears(utils.newDate(), 11);
const maxDate = utils.addYears(utils.newDate(), 11);
const minDate = subYears(newDate(), 11);
const maxDate = addYears(newDate(), 11);
const { container } = render(
<YearDropdownOptions
onCancel={onCancelSpy}
onChange={onChangeSpy}
scrollableYearDropdown
year={utils.getYear(utils.newDate())}
year={getYear(newDate())}
minDate={minDate}
maxDate={maxDate}
/>,
Expand All @@ -303,12 +303,12 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {

expect(
textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(minDate),
(year) => parseInt(year.textContent ?? "") === getYear(minDate),
),
).toBeUndefined();
expect(
textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(maxDate),
(year) => parseInt(year.textContent ?? "") === getYear(maxDate),
),
).toBeUndefined();

Expand All @@ -323,12 +323,12 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {
).filter((node) => node.textContent);

const x = textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(minDate),
(year) => parseInt(year.textContent ?? "") === getYear(minDate),
);
expect(x).not.toBeUndefined();
expect(
textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(maxDate),
(year) => parseInt(year.textContent ?? "") === getYear(maxDate),
),
).toBeUndefined();
expect(
Expand All @@ -348,26 +348,26 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {

expect(
textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(minDate),
(year) => parseInt(year.textContent ?? "") === getYear(minDate),
),
).toBeUndefined();
expect(
textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(maxDate),
(year) => parseInt(year.textContent ?? "") === getYear(maxDate),
),
).toBeUndefined();
});

it("should show arrows to add previous years, if actual years list does not contain minDate year, if only minDate is provided", () => {
const onCancelSpy = jest.fn();
const onChangeSpy = jest.fn();
const minDate = utils.subYears(utils.newDate(), 11);
const minDate = subYears(newDate(), 11);
const { container } = render(
<YearDropdownOptions
onCancel={onCancelSpy}
onChange={onChangeSpy}
scrollableYearDropdown
year={utils.getYear(utils.newDate())}
year={getYear(newDate())}
minDate={minDate}
/>,
);
Expand All @@ -389,7 +389,7 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {

expect(
textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(minDate),
(year) => parseInt(year.textContent ?? "") === getYear(minDate),
),
).toBeUndefined();

Expand All @@ -405,7 +405,7 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {

expect(
textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(minDate),
(year) => parseInt(year.textContent ?? "") === getYear(minDate),
),
).not.toBeUndefined();
expect(
Expand All @@ -423,13 +423,13 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {
it("should show arrows to add upcoming years, if actual years list does not contain maxDate year, if only maxDate is provided", () => {
const onCancelSpy = jest.fn();
const onChangeSpy = jest.fn();
const maxDate = utils.addYears(utils.newDate(), 11);
const maxDate = addYears(newDate(), 11);
const { container } = render(
<YearDropdownOptions
onCancel={onCancelSpy}
onChange={onChangeSpy}
scrollableYearDropdown
year={utils.getYear(utils.newDate())}
year={getYear(newDate())}
maxDate={maxDate}
/>,
);
Expand All @@ -451,7 +451,7 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {

expect(
textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(maxDate),
(year) => parseInt(year.textContent ?? "") === getYear(maxDate),
),
).toBeUndefined();

Expand All @@ -467,7 +467,7 @@ describe("YearDropdownOptions with scrollable dropwdown", () => {

expect(
textContents.find(
(year) => parseInt(year.textContent ?? "") === utils.getYear(maxDate),
(year) => parseInt(year.textContent ?? "") === getYear(maxDate),
),
).not.toBeUndefined();
expect(
Expand Down

0 comments on commit 3054d56

Please sign in to comment.