Skip to content

Commit

Permalink
Change mount() to shallow() in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jan 16, 2020
1 parent 058aeb2 commit 1a89d91
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions src/Calendar.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { mount, shallow } from 'enzyme';
import { shallow } from 'enzyme';
import { getMonthStart } from '@wojtekmaj/date-utils';

import Calendar from './Calendar';
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('Calendar', () => {
});

it('renders YearView when given view = "year"', () => {
const component = mount(
const component = shallow(
<Calendar view="year" />,
);

Expand All @@ -57,7 +57,7 @@ describe('Calendar', () => {
});

it('renders DecadeView when given view = "decade"', () => {
const component = mount(
const component = shallow(
<Calendar view="decade" />,
);

Expand All @@ -67,7 +67,7 @@ describe('Calendar', () => {
});

it('renders CenturyView when given view = "century"', () => {
const component = mount(
const component = shallow(
<Calendar view="century" />,
);

Expand Down Expand Up @@ -253,19 +253,20 @@ describe('Calendar', () => {

describe('handles drill up properly', () => {
it('drills up when allowed', () => {
const component = mount(
const component = shallow(
<Calendar view="month" />,
);

component.instance().drillUp();
component.update();

expect(component.state().view).toBe('year');
});

it('calls onDrillUp on drill up', () => {
const onDrillUp = jest.fn();

const component = mount(
const component = shallow(
<Calendar
activeStartDate={new Date(2017, 6, 1)}
onDrillUp={onDrillUp}
Expand All @@ -284,7 +285,7 @@ describe('Calendar', () => {
it('refuses to drill up when already on minimum allowed detail', () => {
const onDrillUp = jest.fn();

const component = mount(
const component = shallow(
<Calendar
onDrillUp={onDrillUp}
view="century"
Expand All @@ -299,7 +300,7 @@ describe('Calendar', () => {

describe('handles drill down properly', () => {
it('drills down when allowed', () => {
const component = mount(
const component = shallow(
<Calendar view="century" />,
);

Expand All @@ -311,7 +312,7 @@ describe('Calendar', () => {
it('calls onDrillDown on drill down', () => {
const onDrillDown = jest.fn();

const component = mount(
const component = shallow(
<Calendar
activeStartDate={new Date(2001, 0, 1)}
onDrillDown={onDrillDown}
Expand All @@ -330,7 +331,7 @@ describe('Calendar', () => {
it('refuses to drill down when already on minimum allowed detail', () => {
const onDrillDown = jest.fn();

const component = mount(
const component = shallow(
<Calendar
onDrillDown={onDrillDown}
view="month"
Expand All @@ -345,20 +346,23 @@ describe('Calendar', () => {

describe('handles active start date change properly', () => {
it('changes active start date when allowed', () => {
const component = mount(
const component = shallow(
<Calendar />,
);

component.instance().setActiveStartDate(new Date(2019, 0, 1));
component.update();

const monthView = component.find('MonthView');

expect(component.state().activeStartDate).toEqual(new Date(2019, 0, 1));
expect(monthView.prop('activeStartDate')).toEqual(new Date(2019, 0, 1));
});

it('calls onActiveStartDateChange on activeStartDate change', () => {
const activeStartDate = new Date(2017, 0, 1);
const newActiveStartDate = new Date(2018, 0, 1);
const onActiveStartDateChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
activeStartDate={activeStartDate}
onActiveStartDateChange={onActiveStartDateChange}
Expand All @@ -378,7 +382,7 @@ describe('Calendar', () => {
describe('calls onChange properly', () => {
it('calls onChange function returning the beginning of selected period by default', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
onChange={onChange}
view="month"
Expand All @@ -392,7 +396,7 @@ describe('Calendar', () => {

it('calls onChange function returning the beginning of the selected period when returnValue is set to "start"', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
onChange={onChange}
returnValue="start"
Expand All @@ -407,7 +411,7 @@ describe('Calendar', () => {

it('calls onChange function returning the beginning of the selected period when returnValue is set to "start"', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
onChange={onChange}
returnValue="start"
Expand All @@ -422,7 +426,7 @@ describe('Calendar', () => {

it('calls onChange function returning the end of the selected period when returnValue is set to "end"', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
onChange={onChange}
returnValue="end"
Expand All @@ -437,7 +441,7 @@ describe('Calendar', () => {

it('calls onChange function returning the beginning of selected period when returnValue is set to "range"', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
onChange={onChange}
returnValue="range"
Expand All @@ -455,7 +459,7 @@ describe('Calendar', () => {

it('calls onChange function returning the beginning of selected period, but no earlier than minDate', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
minDate={new Date(2017, 0, 1, 12)}
onChange={onChange}
Expand All @@ -471,7 +475,7 @@ describe('Calendar', () => {

it('calls onChange function returning the beginning of selected period, but no later than maxDate', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
maxDate={new Date(2017, 0, 1, 12)}
onChange={onChange}
Expand All @@ -487,7 +491,7 @@ describe('Calendar', () => {

it('calls onChange function returning the end of selected period, but no earlier than minDate', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
minDate={new Date(2017, 0, 2, 12)}
onChange={onChange}
Expand All @@ -503,7 +507,7 @@ describe('Calendar', () => {

it('calls onChange function returning the end of selected period, but no later than maxDate', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
maxDate={new Date(2017, 0, 1, 12)}
onChange={onChange}
Expand All @@ -519,7 +523,7 @@ describe('Calendar', () => {

it('calls onChange function returning a range when selected two pieces of a range', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
onChange={onChange}
selectRange
Expand All @@ -539,7 +543,7 @@ describe('Calendar', () => {

it('calls onChange function returning a range when selected reversed two pieces of a range', () => {
const onChange = jest.fn();
const component = mount(
const component = shallow(
<Calendar
onChange={onChange}
selectRange
Expand All @@ -561,11 +565,12 @@ describe('Calendar', () => {
it('changes Calendar view given new activeStartDate value', () => {
const activeStartDate = new Date(2017, 0, 1);
const newActiveStartDate = new Date(2018, 0, 1);
const component = mount(
const component = shallow(
<Calendar activeStartDate={activeStartDate} />,
);

component.setProps({ activeStartDate: newActiveStartDate });
component.update();

const monthView = component.find('MonthView');

Expand Down

0 comments on commit 1a89d91

Please sign in to comment.