Skip to content

Commit

Permalink
Avoid unnecessary destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Mar 24, 2023
1 parent e9654ab commit 694b6de
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
29 changes: 24 additions & 5 deletions src/Calendar/Navigation.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ describe('Navigation', () => {

const children = [...container.firstElementChild.children];

const [prev2, prev, drillUp, next, next2] = children;
const prev2 = children[0];
const prev = children[1];
const drillUp = children[2];
const next = children[3];
const next2 = children[4];

expect(children).toHaveLength(5);
expect(prev2).toHaveAttribute('type', 'button');
Expand All @@ -38,7 +42,9 @@ describe('Navigation', () => {

const children = [...container.firstElementChild.children];

const [prev, drillUp, next] = children;
const prev = children[0];
const drillUp = children[1];
const next = children[2];

expect(children).toHaveLength(3);
expect(prev).toHaveAttribute('type', 'button');
Expand Down Expand Up @@ -98,7 +104,12 @@ describe('Navigation', () => {
/>,
);

const [prev2, prev, , next, next2] = [...container.firstElementChild.children];
const children = [...container.firstElementChild.children];

const prev2 = children[0];
const prev = children[1];
const next = children[3];
const next2 = children[4];

expect(prev2).toHaveTextContent('prev2Label');
expect(prev).toHaveTextContent('prevLabel');
Expand All @@ -111,7 +122,9 @@ describe('Navigation', () => {
<Navigation {...defaultProps} navigationAriaLive="polite" view="month" />,
);

const [, , navigation] = [...container.firstElementChild.children];
const children = [...container.firstElementChild.children];

const navigation = children[2];

expect(navigation).toHaveAttribute('aria-live', 'polite');
});
Expand All @@ -129,7 +142,13 @@ describe('Navigation', () => {
/>,
);

const [prev2, prev, navigation, next, next2] = [...container.firstElementChild.children];
const children = [...container.firstElementChild.children];

const prev2 = children[0];
const prev = children[1];
const navigation = children[2];
const next = children[3];
const next2 = children[4];

expect(prev2).toHaveAccessibleName('prev2AriaLabel');
expect(prev).toHaveAccessibleName('prevAriaLabel');
Expand Down
12 changes: 7 additions & 5 deletions src/CenturyView.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ describe('CenturyView', () => {
);

const tiles = container.querySelectorAll('.react-calendar__tile');
const [firstDayTile, secondDayTile] = tiles;

const firstDayTile = tiles[0];
const secondDayTile = tiles[1];

expect(firstDayTile).toHaveClass('firstDayOfTheMonth');
expect(secondDayTile).not.toHaveClass('firstDayOfTheMonth');
Expand All @@ -75,9 +77,7 @@ describe('CenturyView', () => {
<CenturyView {...defaultProps} showNeighboringMonth={false} tileContent={tileContent} />,
);

const tiles = container.querySelectorAll('.react-calendar__tile');
const [firstDayTile] = tiles;

const firstDayTile = container.querySelector('.react-calendar__tile');
const firstDayTileContent = firstDayTile.querySelector('.testContent');

expect(firstDayTileContent).toBeInTheDocument();
Expand All @@ -103,7 +103,9 @@ describe('CenturyView', () => {
);

const tiles = container.querySelectorAll('.react-calendar__tile');
const [firstDayTile, secondDayTile] = tiles;

const firstDayTile = tiles[0];
const secondDayTile = tiles[1];

const firstDayTileContent = firstDayTile.querySelector('.testContent');
const secondDayTileContent = secondDayTile.querySelector('.testContent');
Expand Down
8 changes: 6 additions & 2 deletions src/DecadeView.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ describe('DecadeView', () => {
);

const tiles = container.querySelectorAll('.react-calendar__tile');
const [firstDayTile, secondDayTile] = tiles;

const firstDayTile = tiles[0];
const secondDayTile = tiles[1];

expect(firstDayTile).toHaveClass('firstDayOfTheMonth');
expect(secondDayTile).not.toHaveClass('firstDayOfTheMonth');
Expand Down Expand Up @@ -96,7 +98,9 @@ describe('DecadeView', () => {
);

const tiles = container.querySelectorAll('.react-calendar__tile');
const [firstDayTile, secondDayTile] = tiles;

const firstDayTile = tiles[0];
const secondDayTile = tiles[1];

const firstDayTileContent = firstDayTile.querySelector('.testContent');
const secondDayTileContent = secondDayTile.querySelector('.testContent');
Expand Down
8 changes: 6 additions & 2 deletions src/MonthView.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ describe('MonthView', () => {
);

const tiles = container.querySelectorAll('.react-calendar__tile');
const [firstDayTile, secondDayTile] = tiles;

const firstDayTile = tiles[0];
const secondDayTile = tiles[1];

expect(firstDayTile).toHaveClass('firstDayOfTheMonth');
expect(secondDayTile).not.toHaveClass('firstDayOfTheMonth');
Expand Down Expand Up @@ -104,7 +106,9 @@ describe('MonthView', () => {
);

const tiles = container.querySelectorAll('.react-calendar__tile');
const [firstDayTile, secondDayTile] = tiles;

const firstDayTile = tiles[0];
const secondDayTile = tiles[1];

const firstDayTileContent = firstDayTile.querySelector('.testContent');
const secondDayTileContent = secondDayTile.querySelector('.testContent');
Expand Down
8 changes: 4 additions & 4 deletions src/MonthView/WeekNumbers.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ describe('.react-calendar__month-view__weekNumbers', () => {
/>,
);

const children = container.querySelectorAll('button.react-calendar__tile');
const firstChild = container.querySelector('button.react-calendar__tile');
fireEvent.click(firstChild);

fireEvent.click(children[0]);
expect(onClickWeekNumber).toHaveBeenCalledWith(52, new Date(2016, 11, 26), expect.any(Object));
});

Expand All @@ -122,9 +122,9 @@ describe('.react-calendar__month-view__weekNumbers', () => {
<WeekNumbers {...defaultProps} calendarType="US" onClickWeekNumber={onClickWeekNumber} />,
);

const children = container.querySelectorAll('button.react-calendar__tile');
const firstChild = container.querySelector('button.react-calendar__tile');
fireEvent.click(firstChild);

fireEvent.click(children[0]);
expect(onClickWeekNumber).toHaveBeenCalledWith(1, new Date(2017, 0, 1), expect.any(Object));
});
});
10 changes: 4 additions & 6 deletions src/MonthView/Weekdays.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ describe('Weekdays', () => {
it('renders weekdays with custom weekdays formatting', () => {
const { container } = render(<Weekdays {...defaultProps} formatShortWeekday={() => 'Wkdy'} />);

const weekdays = container.querySelectorAll('.react-calendar__month-view__weekdays__weekday');
const firstWeekday = weekdays[0];
const firstWeekday = container.querySelector('.react-calendar__month-view__weekdays__weekday');

expect(firstWeekday).toHaveTextContent('Wkdy');
});

it('renders weekdays with custom weekdays formatting', () => {
const { container } = render(<Weekdays {...defaultProps} formatWeekday={() => 'Weekday'} />);

const weekdays = container.querySelectorAll('.react-calendar__month-view__weekdays__weekday');
const firstWeekday = weekdays[0];
const abbr = firstWeekday.querySelector('abbr');
const firstWeekday = container.querySelector('.react-calendar__month-view__weekdays__weekday');
const firstWeekdayAbbr = firstWeekday.querySelector('abbr');

expect(abbr).toHaveAccessibleName('Weekday');
expect(firstWeekdayAbbr).toHaveAccessibleName('Weekday');
});
});
8 changes: 6 additions & 2 deletions src/YearView.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ describe('YearView', () => {
);

const tiles = container.querySelectorAll('.react-calendar__tile');
const [firstDayTile, secondDayTile] = tiles;

const firstDayTile = tiles[0];
const secondDayTile = tiles[1];

expect(firstDayTile).toHaveClass('firstDayOfTheMonth');
expect(secondDayTile).not.toHaveClass('firstDayOfTheMonth');
Expand Down Expand Up @@ -95,7 +97,9 @@ describe('YearView', () => {
);

const tiles = container.querySelectorAll('.react-calendar__tile');
const [firstDayTile, secondDayTile] = tiles;

const firstDayTile = tiles[0];
const secondDayTile = tiles[1];

const firstDayTileContent = firstDayTile.querySelector('.testContent');
const secondDayTileContent = secondDayTile.querySelector('.testContent');
Expand Down

0 comments on commit 694b6de

Please sign in to comment.