Skip to content

Commit

Permalink
test(date-picker): add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasmenker committed Nov 5, 2020
1 parent 0495790 commit 475b1c8
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions test/components/DatePicker.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import moment from 'moment';
import { currentMonth, lastMonth, ISO_FORMAT, NUMBER_OF_MONTHS } from '../../src/utils/dates';
import { DatePicker } from '../../src/components/DatePicker';
import { mockPeriodOptions } from '../mock/DatePicker';

import { render, fireEvent, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import { today, currentMonth, lastMonth, ISO_FORMAT, NUMBER_OF_MONTHS } from '../../src/utils/dates';
import { DatePicker } from '../../src/components/DatePicker';
import { mockPeriodOptions } from '../mock/DatePicker';

const parseDate = (start, end) => ({
startDate: start,
endDate: end,
Expand Down Expand Up @@ -170,4 +170,22 @@ describe('<DatePicker>', () => {
const selectWithLabel = getByText(periodLabel);
expect(selectWithLabel).toBeInTheDocument();
});
it('Should call onDatesChange when some date change', () => {
const mockCallBack = jest.fn();
const { container, getByText } = render(
<DatePicker periodOptions={mockPeriodOptions} onDatesChange={mockCallBack}/>
);
fireEvent.mouseDown(container.querySelector('.select-styled__control'));
fireEvent.click(getByText(currentMonthLabel));
expect(mockCallBack).toHaveBeenCalled();
});
it('Should call stateDateWrapper when some date change', () => {
const mockStateDateWrapper = jest.fn();
const { container, getByText } = render(
<DatePicker periodOptions={mockPeriodOptions} stateDateWrapper={mockStateDateWrapper}/>
);
fireEvent.mouseDown(container.querySelector('.select-styled__control'));
fireEvent.click(getByText(currentMonthLabel));
expect(mockStateDateWrapper).toHaveBeenCalled();
});
});

0 comments on commit 475b1c8

Please sign in to comment.