Skip to content

Commit 11d8b7a

Browse files
author
javadoug
committed
prettier
1 parent 6c3acc4 commit 11d8b7a

8 files changed

+131
-118
lines changed

src/App.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import React from 'react'
22
import logo from './logo.svg'
3-
import {SelectDateRange} from './SelectDateRange'
3+
import { SelectDateRange } from './SelectDateRange'
44
import './App.css'
55

6-
function App({onDateSelected}) {
6+
function App({ onDateSelected }) {
77
return (
88
<div className="App">
99
<header className="App-header">
10-
<img src={logo} className="App-logo" alt="logo"/>
10+
<img src={logo} className="App-logo" alt="logo" />
1111
<h1 className="App-title">Welcome to React</h1>
1212
</header>
1313
<p className="App-intro">
1414
To get started, edit <code>src/App.js</code> and save to reload.
1515
</p>
16-
<SelectDateRange onDateSelected={onDateSelected}/>
16+
<SelectDateRange onDateSelected={onDateSelected} />
1717
</div>
1818
)
1919
}

src/SelectDateRange.js

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import React, {Component} from 'react'
1+
import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33
import {
4-
getOffsetDate, getOffsetMonth, getOffsetYear,
4+
getOffsetDate,
5+
getOffsetMonth,
6+
getOffsetYear,
57
getStartOfMonthDate,
68
getStartOfWeekDate,
79
isDateInStartDateMonth,
810
isDateSelectedDate,
911
isDateToday
10-
} from "./date"
12+
} from './date'
1113
import './SelectDateRange.css'
1214

1315
export class SelectDateRange extends Component {
14-
1516
static propTypes = {
1617
date: PropTypes.instanceOf(Date)
1718
}
@@ -39,7 +40,7 @@ export class SelectDateRange extends Component {
3940
</div>
4041
<div>
4142
<button onClick={() => this.previousMonth()}>Previous Month</button>
42-
<MonthName date={this.state.date}/>
43+
<MonthName date={this.state.date} />
4344
<button onClick={() => this.nextMonth()}>Next Month</button>
4445
</div>
4546
<div className="week">
@@ -55,7 +56,7 @@ export class SelectDateRange extends Component {
5556
<CalendarMonth
5657
startDate={this.state.date}
5758
selectedDate={this.state.selectedDate}
58-
onDateSelected={(date) => this.selectDate(date)}
59+
onDateSelected={date => this.selectDate(date)}
5960
/>
6061
</div>
6162
</div>
@@ -64,31 +65,31 @@ export class SelectDateRange extends Component {
6465

6566
previousYear() {
6667
const date = getOffsetYear(this.state.date, -1)
67-
this.setState({date})
68+
this.setState({ date })
6869
}
6970

7071
nextYear() {
7172
const date = getOffsetYear(this.state.date, 1)
72-
this.setState({date})
73+
this.setState({ date })
7374
}
7475

7576
previousMonth() {
7677
const date = getOffsetMonth(this.state.date, -1)
77-
this.setState({date})
78+
this.setState({ date })
7879
}
7980

8081
nextMonth() {
8182
const date = getOffsetMonth(this.state.date, 1)
82-
this.setState({date})
83+
this.setState({ date })
8384
}
8485

8586
selectDate(date) {
86-
this.setState({selectedDate: date})
87+
this.setState({ selectedDate: date })
8788
this.props.onDateSelected(date)
8889
}
8990
}
9091

91-
export function CalendarMonth({startDate, selectedDate, onDateSelected}) {
92+
export function CalendarMonth({ startDate, selectedDate, onDateSelected }) {
9293
const monthStart = getStartOfMonthDate(startDate)
9394
const weekStart = getStartOfWeekDate(monthStart)
9495
const weeks = []
@@ -108,7 +109,12 @@ export function CalendarMonth({startDate, selectedDate, onDateSelected}) {
108109
return weeks
109110
}
110111

111-
export function CalendarWeek({startOfWeekDate, startDate, selectedDate, onDateSelected}) {
112+
export function CalendarWeek({
113+
startOfWeekDate,
114+
startDate,
115+
selectedDate,
116+
onDateSelected
117+
}) {
112118
const week = []
113119
for (let i = 0; i < 7; i++) {
114120
const date = getOffsetDate(startOfWeekDate, i)
@@ -129,8 +135,7 @@ export function CalendarWeek({startOfWeekDate, startDate, selectedDate, onDateSe
129135
)
130136
}
131137

132-
export function CalendarDay({date, startDate, selectedDate = null, onDateSelected}) {
133-
138+
export function CalendarDay({ date, startDate, selectedDate = null, onDateSelected }) {
134139
const day = date.getDate()
135140
const isToday = isDateToday(date)
136141
const inMonth = isDateInStartDateMonth(date, startDate)
@@ -163,7 +168,7 @@ export function CalendarDay({date, startDate, selectedDate = null, onDateSelecte
163168
)
164169
}
165170

166-
export function MonthName({date}) {
171+
export function MonthName({ date }) {
167172
const month = date && date.getMonth()
168173
switch (month) {
169174
case 0:

src/SelectDateRange.test.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react'
33
import ReactDOM from 'react-dom'
44
import ReactDomTestUtils from 'react-dom/test-utils'
55
import renderer from 'react-test-renderer'
6-
import {SelectDateRange} from "./SelectDateRange";
6+
import { SelectDateRange } from './SelectDateRange'
77

88
describe('SelectDateRange', () => {
99
let props
@@ -30,10 +30,7 @@ describe('SelectDateRange', () => {
3030
const spy = jest.spyOn(console, 'log')
3131
const div = document.createElement('div')
3232
ReactDOM.render(
33-
<SelectDateRange
34-
date={props.date}
35-
selectedDate={props.selectedDate}
36-
/>,
33+
<SelectDateRange date={props.date} selectedDate={props.selectedDate} />,
3734
div
3835
)
3936
const day = div.querySelectorAll('.day')[10]
@@ -44,39 +41,39 @@ describe('SelectDateRange', () => {
4441
it('calls onDateSelected callback', () => {
4542
expect.assertions(1)
4643
const div = document.createElement('div')
47-
ReactDOM.render(<SelectDateRange {...props}/>, div)
44+
ReactDOM.render(<SelectDateRange {...props} />, div)
4845
const day = div.querySelectorAll('.day')[10]
4946
ReactDomTestUtils.Simulate.click(day, {})
5047
expect(props.onDateSelected).toHaveBeenCalledWith(new Date(2017, 9, 4))
5148
})
5249
it('calls previousYear()', () => {
5350
expect.assertions(1)
5451
const div = document.createElement('div')
55-
ReactDOM.render(<SelectDateRange {...props}/>, div)
52+
ReactDOM.render(<SelectDateRange {...props} />, div)
5653
const button = div.querySelectorAll('button')[0]
5754
ReactDomTestUtils.Simulate.click(button, {})
5855
expect(div.innerHTML).toMatchSnapshot()
5956
})
6057
it('calls nextYear()', () => {
6158
expect.assertions(1)
6259
const div = document.createElement('div')
63-
ReactDOM.render(<SelectDateRange {...props}/>, div)
60+
ReactDOM.render(<SelectDateRange {...props} />, div)
6461
const button = div.querySelectorAll('button')[1]
6562
ReactDomTestUtils.Simulate.click(button, {})
6663
expect(div.innerHTML).toMatchSnapshot()
6764
})
6865
it('calls previousMonth()', () => {
6966
expect.assertions(1)
7067
const div = document.createElement('div')
71-
ReactDOM.render(<SelectDateRange {...props}/>, div)
68+
ReactDOM.render(<SelectDateRange {...props} />, div)
7269
const button = div.querySelectorAll('button')[2]
7370
ReactDomTestUtils.Simulate.click(button, {})
7471
expect(div.innerHTML).toMatchSnapshot()
7572
})
7673
it('calls nextMonth()', () => {
7774
expect.assertions(1)
7875
const div = document.createElement('div')
79-
ReactDOM.render(<SelectDateRange {...props}/>, div)
76+
ReactDOM.render(<SelectDateRange {...props} />, div)
8077
const button = div.querySelectorAll('button')[3]
8178
ReactDomTestUtils.Simulate.click(button, {})
8279
expect(div.innerHTML).toMatchSnapshot()

src/SelectDateRangeCalendarDay.test.js

+43-36
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,66 @@
11
/*global describe, it, expect, beforeEach */
22
import React from 'react'
33
import renderer from 'react-test-renderer'
4-
import {CalendarDay} from "./SelectDateRange";
4+
import { CalendarDay } from './SelectDateRange'
55

66
describe('SelectDateRange/CalendarDay', () => {
77
it('selected date not given', () => {
88
expect.assertions(1)
9-
const tree = renderer.create(
10-
<CalendarDay
11-
date={new Date(2017, 9, 15)}
12-
startDate={new Date(2017, 9, 15)}
13-
selectedDate={null}
14-
/>
15-
).toJSON()
9+
const tree = renderer
10+
.create(
11+
<CalendarDay
12+
date={new Date(2017, 9, 15)}
13+
startDate={new Date(2017, 9, 15)}
14+
selectedDate={null}
15+
/>
16+
)
17+
.toJSON()
1618
expect(tree).toMatchSnapshot()
1719
})
1820
it('selected date given', () => {
1921
expect.assertions(1)
20-
const tree = renderer.create(
21-
<CalendarDay
22-
date={new Date(2017, 9, 15)}
23-
startDate={new Date(2017, 9, 15)}
24-
selectedDate={new Date(2017, 9, 15)}
25-
/>
26-
).toJSON()
22+
const tree = renderer
23+
.create(
24+
<CalendarDay
25+
date={new Date(2017, 9, 15)}
26+
startDate={new Date(2017, 9, 15)}
27+
selectedDate={new Date(2017, 9, 15)}
28+
/>
29+
)
30+
.toJSON()
2731
expect(tree).toMatchSnapshot()
2832
})
2933
it('day is before the start of month', () => {
3034
expect.assertions(1)
31-
const tree = renderer.create(
32-
<CalendarDay
33-
date={new Date(2017, 8, 15)}
34-
startDate={new Date(2017, 9, 15)}
35-
selectedDate={new Date(2017, 9, 15)}
36-
/>
37-
).toJSON()
35+
const tree = renderer
36+
.create(
37+
<CalendarDay
38+
date={new Date(2017, 8, 15)}
39+
startDate={new Date(2017, 9, 15)}
40+
selectedDate={new Date(2017, 9, 15)}
41+
/>
42+
)
43+
.toJSON()
3844
expect(tree).toMatchSnapshot()
3945
})
4046
it('day is after the start of month', () => {
4147
expect.assertions(1)
42-
const tree = renderer.create(
43-
<CalendarDay
44-
date={new Date(2017, 10, 15)}
45-
startDate={new Date(2017, 9, 15)}
46-
selectedDate={new Date(2017, 9, 15)}
47-
/>
48-
).toJSON()
48+
const tree = renderer
49+
.create(
50+
<CalendarDay
51+
date={new Date(2017, 10, 15)}
52+
startDate={new Date(2017, 9, 15)}
53+
selectedDate={new Date(2017, 9, 15)}
54+
/>
55+
)
56+
.toJSON()
4957
expect(tree).toMatchSnapshot()
5058
})
5159
it('day is today', () => {
5260
expect.assertions(1)
53-
const tree = renderer.create(
54-
<CalendarDay
55-
date={new Date()}
56-
startDate={new Date()}
57-
/>
58-
).toJSON()
61+
const tree = renderer
62+
.create(<CalendarDay date={new Date()} startDate={new Date()} />)
63+
.toJSON()
5964
expect(tree).toMatchSnapshot()
6065
})
6166
it('day is today', () => {
@@ -68,7 +73,9 @@ describe('SelectDateRange/CalendarDay', () => {
6873
onDateSelected={onDateSelected}
6974
/>
7075
)
71-
const {rendered: {props}} = tree.toTree()
76+
const {
77+
rendered: { props }
78+
} = tree.toTree()
7279
props.onClick()
7380
expect(onDateSelected).toBeCalledWith(new Date(2017, 10, 15))
7481
})
+4-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
/*global describe, it, expect, beforeEach */
22
import React from 'react'
33
import renderer from 'react-test-renderer'
4-
import {CalendarMonth} from "./SelectDateRange";
4+
import { CalendarMonth } from './SelectDateRange'
55

66
describe('SelectDateRange/CalendarMonth', () => {
77
it('renders', () => {
88
expect.assertions(1)
9-
const tree = renderer.create(
10-
<CalendarMonth
11-
startDate={new Date(2017, 9, 10)}
12-
/>
13-
).toJSON()
9+
const tree = renderer
10+
.create(<CalendarMonth startDate={new Date(2017, 9, 10)} />)
11+
.toJSON()
1412
expect(tree).toMatchSnapshot()
1513
})
1614
})
+9-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/*global describe, it, expect, beforeEach */
22
import React from 'react'
33
import renderer from 'react-test-renderer'
4-
import {CalendarWeek} from "./SelectDateRange";
4+
import { CalendarWeek } from './SelectDateRange'
55

66
describe('SelectDateRange/CalendarWeek', () => {
77
it('renders', () => {
88
expect.assertions(1)
9-
const tree = renderer.create(
10-
<CalendarWeek
11-
startOfWeekDate={new Date(2017, 9, 10)}
12-
startDate={new Date(2017, 9, 10)}
13-
/>
14-
).toJSON()
9+
const tree = renderer
10+
.create(
11+
<CalendarWeek
12+
startOfWeekDate={new Date(2017, 9, 10)}
13+
startDate={new Date(2017, 9, 10)}
14+
/>
15+
)
16+
.toJSON()
1517
expect(tree).toMatchSnapshot()
1618
})
1719
})

src/SelectDateRangeMonthName.test.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*global describe, it, expect, beforeEach */
2-
import React, {Fragment} from 'react'
2+
import React, { Fragment } from 'react'
33
import renderer from 'react-test-renderer'
4-
import {MonthName} from "./SelectDateRange";
4+
import { MonthName } from './SelectDateRange'
55

66
describe('SelectDateRange/MonthName', () => {
77
let monthDates
@@ -26,10 +26,12 @@ describe('SelectDateRange/MonthName', () => {
2626
expect.assertions(1)
2727
const monthNames = (
2828
<Fragment>
29-
{monthDates.map(date => <MonthName key={date} date={date} />)}
29+
{monthDates.map(date => (
30+
<MonthName key={date} date={date} />
31+
))}
3032
</Fragment>
3133
)
3234
const tree = renderer.create(monthNames).toJSON()
3335
expect(tree).toMatchSnapshot()
3436
})
35-
})
37+
})

0 commit comments

Comments
 (0)