From cff96eecccc30c025183647af45fcfe3ab8f7cf6 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 14 Jan 2020 20:20:27 +0100 Subject: [PATCH] Created DateRangeRow test --- test/utils/DateRangeRow.test.js | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/utils/DateRangeRow.test.js diff --git a/test/utils/DateRangeRow.test.js b/test/utils/DateRangeRow.test.js new file mode 100644 index 00000000..5b6a4cc5 --- /dev/null +++ b/test/utils/DateRangeRow.test.js @@ -0,0 +1,40 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import DateRangeRow from '../../src/utils/DateRangeRow'; +import DateInput from '../../src/utils/DateInput'; + +describe('', () => { + let wrapper; + const onEndDateChange = jest.fn(); + const onStartDateChange = jest.fn(); + + beforeEach(() => { + wrapper = shallow(); + }); + afterEach(() => { + wrapper.unmount(); + jest.clearAllMocks(); + }); + + it('renders two date inputs', () => { + const dateInput = wrapper.find(DateInput); + + expect(dateInput).toHaveLength(2); + }); + + it('invokes start date callback when change event is triggered on first input', () => { + const dateInput = wrapper.find(DateInput).first(); + + expect(onStartDateChange).not.toHaveBeenCalled(); + dateInput.simulate('change'); + expect(onStartDateChange).toHaveBeenCalled(); + }); + + it('invokes end date callback when change event is triggered on second input', () => { + const dateInput = wrapper.find(DateInput).last(); + + expect(onEndDateChange).not.toHaveBeenCalled(); + dateInput.simulate('change'); + expect(onEndDateChange).toHaveBeenCalled(); + }); +});