-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDESK-1172] Repeat summary for recurring events (#190)
[SDESK-1172] Test case fix [SDESK-1172] Changes after review
- Loading branch information
Showing
4 changed files
with
283 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import { RepeatEventSummary } from './index' | ||
import moment from 'moment' | ||
|
||
class TestForm extends React.Component { | ||
render() { | ||
const { byDay, interval, frequency, endRepeatMode, until, count, startDate } = this.props | ||
return ( | ||
<RepeatEventSummary byDay={byDay} | ||
interval={interval} | ||
frequency={frequency} | ||
endRepeatMode={endRepeatMode} | ||
until={until} | ||
count={count} | ||
startDate={startDate} /> | ||
) | ||
} | ||
} | ||
|
||
TestForm.propTypes = { | ||
byDay: React.PropTypes.string, | ||
interval: React.PropTypes.number, | ||
frequency: React.PropTypes.string, | ||
endRepeatMode: React.PropTypes.string, | ||
until: React.PropTypes.object, | ||
count: React.PropTypes.string, | ||
startDate: React.PropTypes.object, | ||
} | ||
|
||
describe('<RepeatEventSummary />', () => { | ||
const event = { | ||
_id: '5800d71930627218866f1e80', | ||
dates: { | ||
start: moment('2016-10-15T14:30+0000'), | ||
end: moment('2016-10-20T15:00+0000'), | ||
}, | ||
definition_short: 'definition_short 1', | ||
location: [{ name: 'location1' }], | ||
name: 'name1', | ||
files: [{ | ||
media: { | ||
name: 'file.pdf', | ||
length: 1000, | ||
}, | ||
filemeta: { media_id: 'media1' }, | ||
}], | ||
links: ['http://www.google.com'], | ||
_plannings: [], | ||
} | ||
|
||
const mountForm = (recEvent) => { | ||
const { byday, interval, frequency, endRepeatMode, until, count } = | ||
recEvent.dates.recurring_rule | ||
return ( | ||
mount(<TestForm byDay={byday} | ||
interval={interval} | ||
frequency={frequency} | ||
endRepeatMode={endRepeatMode} | ||
until={until} | ||
count={count} | ||
startDate={recEvent.dates.start} />) | ||
) | ||
} | ||
|
||
it('Shows appropriate repeat summary for a given frequency with intervals', () => { | ||
const recEvent = { | ||
...event, | ||
dates: { | ||
start: moment('2016-10-15T14:30+0000'), | ||
end: moment('2016-10-20T15:00+0000'), | ||
recurring_rule: { | ||
frequency: 'MONTHLY', | ||
interval: '3', | ||
}, | ||
}, | ||
} | ||
let wrapper = mountForm(recEvent) | ||
expect(wrapper.find('.repeatSummary').text()).toBe('Repeat summary: Every 3 months on day 15') | ||
}) | ||
it('Shows appropriate repeat summary for a given frequency with intervals and until a date', () => { | ||
const recEvent = { | ||
...event, | ||
dates: { | ||
start: moment('2016-10-15T14:30+0000'), | ||
end: moment('2016-10-20T15:00+0000' ), | ||
recurring_rule: { | ||
endRepeatMode: 'until', | ||
frequency: 'DAILY', | ||
interval: '3', | ||
until: moment('2020-07-01T00:00'), | ||
}, | ||
}, | ||
} | ||
let wrapper = mountForm(recEvent) | ||
expect(wrapper.find('.repeatSummary').text()).toBe('Repeat summary: Every 3 days, until 1 Jul 2020') | ||
}) | ||
it('Shows appropriate repeat summary for a given frequency with intervals and for a number of occurances', () => { | ||
const recEvent = { | ||
...event, | ||
dates: { | ||
start: moment('2016-10-15T14:30+0000'), | ||
end: moment('2016-10-20T15:00+0000'), | ||
recurring_rule: { | ||
endRepeatMode: 'count', | ||
frequency: 'DAILY', | ||
interval: '3', | ||
count: '9', | ||
}, | ||
}, | ||
} | ||
let wrapper = mountForm(recEvent) | ||
expect(wrapper.find('.repeatSummary').text()).toBe('Repeat summary: Every 3 days, 9 times') | ||
}) | ||
it('Shows appropriate repeat summary for a given weekly frequency with intervals and by days', () => { | ||
const recEvent = { | ||
...event, | ||
dates: { | ||
start: moment('2016-10-15T14:30+0000'), | ||
end: moment('2016-10-20T15:00+0000'), | ||
recurring_rule: { | ||
frequency: 'WEEKLY', | ||
interval: '3', | ||
byday: 'TH FR', | ||
}, | ||
}, | ||
} | ||
let wrapper = mountForm(recEvent) | ||
expect(wrapper.find('.repeatSummary').text()).toBe('Repeat summary: Every 3 weeks on Thursday, Friday') | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React from 'react' | ||
|
||
export class RepeatEventSummary extends React.Component { | ||
constructor(props) { | ||
super(props) | ||
} | ||
|
||
getDaysFromByDays() { | ||
let byDays = this.props.byDay && this.props.byDay.length > 0 ? this.props.byDay : | ||
this.props.startDate ? this.props.startDate.format('dd').toUpperCase() : '' | ||
|
||
if (byDays) { | ||
const days = { | ||
'MO': 'Monday', | ||
'TU': 'Tuesday', | ||
'WE': 'Wednesday', | ||
'TH': 'Thursday', | ||
'FR': 'Friday', | ||
'SA': 'Saturday', | ||
'SU': 'Sunday', | ||
} | ||
|
||
let dayNames = [] | ||
|
||
byDays.split(' ').forEach((day) => { | ||
dayNames.push(days[day]) | ||
}) | ||
return dayNames | ||
} | ||
} | ||
|
||
getPrefix() { | ||
let prefix = '' | ||
if (this.props.interval > 1) { | ||
const duration = this.props.frequency === 'DAILY' ? 'days' : | ||
this.props.frequency.replace('LY', 's').toLowerCase() | ||
prefix = 'Every ' + this.props.interval + ' ' + duration | ||
} else { | ||
if (this.props.frequency) { | ||
const f = this.props.frequency | ||
prefix = f === 'YEARLY' ? 'Annualy' : (f.charAt(0).toUpperCase() + f.slice(1).toLowerCase()) | ||
} | ||
} | ||
return prefix | ||
} | ||
|
||
getStemText() { | ||
let stemText = '' | ||
const days = this.getDaysFromByDays() | ||
switch(this.props.frequency) { | ||
case 'WEEKLY': | ||
stemText = days && days.length > 0 ? ('on ' + days.join(', ')) : '' | ||
break | ||
case 'MONTHLY': | ||
stemText = this.props.startDate ? ('on day ' + this.props.startDate.format('D')) : '' | ||
break | ||
case 'YEARLY': | ||
stemText = this.props.startDate ? ('on ' + this.props.startDate.format('MMM D')) : '' | ||
break | ||
} | ||
return stemText | ||
} | ||
|
||
getSuffix() { | ||
let suffix = '' | ||
if (this.props.endRepeatMode !== 'unlimited') { | ||
if (this.props.endRepeatMode === 'count' && parseInt(this.props.count) > 0) { | ||
suffix = ', ' + this.props.count + ' times' | ||
} else if (this.props.endRepeatMode === 'until' && this.props.until && | ||
this.props.until.isValid()) { | ||
suffix = ', until ' + this.props.until.format('D MMM YYYY') | ||
} | ||
} | ||
return suffix | ||
} | ||
|
||
getRepeatSummary() { | ||
const stemText = this.getStemText() | ||
return this.getPrefix() + (stemText !== '' ? ( ' ' + stemText ) : '') + this.getSuffix() | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<span><strong className='repeatSummary'>{'Repeat summary: ' + this.getRepeatSummary()}</strong> | ||
</span> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
RepeatEventSummary.propTypes = { | ||
byDay: React.PropTypes.string, | ||
interval: React.PropTypes.string, | ||
frequency: React.PropTypes.string, | ||
endRepeatMode: React.PropTypes.string, | ||
until: React.PropTypes.object, | ||
count: React.PropTypes.string, | ||
startDate: React.PropTypes.object, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters