Change getCycleDayNumber signature and some PR improvements

This commit is contained in:
Julia Friesel
2018-06-11 14:03:45 +02:00
parent f98a60192b
commit ab1ed96966
5 changed files with 21 additions and 23 deletions
+2 -3
View File
@@ -11,9 +11,8 @@ import { saveBleeding } from './db'
import { formatDateForViewHeader } from './format'
import { bleeding as labels } from './labels'
import cycleDayModule from './get-cycle-day-number'
import { bleedingDaysSortedByDate } from './db'
const getCycleDay = cycleDayModule(bleedingDaysSortedByDate)
const getCycleDayNumber = cycleDayModule()
export default class Bleeding extends Component {
constructor(props) {
@@ -43,7 +42,7 @@ export default class Bleeding extends Component {
return (
<View style={styles.container}>
<Text style={styles.welcome}>{formatDateForViewHeader(day.date)}</Text>
<Text>Cycle day {getCycleDay(day.date)}</Text>
<Text>Cycle day {getCycleDayNumber(day.date)}</Text>
<Text>Bleeding</Text>
<RadioForm
radio_props={bleedingRadioProps}
+4 -4
View File
@@ -10,14 +10,14 @@ import { bleeding as labels} from './labels'
import cycleDayModule from './get-cycle-day-number'
import { bleedingDaysSortedByDate } from './db'
const getCycleDay = cycleDayModule(bleedingDaysSortedByDate)
const getCycleDayNumber = cycleDayModule()
export default class DayView extends Component {
constructor(props) {
super(props)
this.cycleDay = props.navigation.state.params.cycleDay
this.state = {
cycleDayNumber: getCycleDay(this.cycleDay.date),
cycleDayNumber: getCycleDayNumber(this.cycleDay.date),
}
bleedingDaysSortedByDate.addListener(setStateWithCurrentCycleDayNumber.bind(this))
}
@@ -40,7 +40,7 @@ export default class DayView extends Component {
return (
<View style={styles.container}>
<Text style={styles.welcome}>{formatDateForViewHeader(day.date)}</Text>
<Text>Cycle day {getCycleDay(day.date)}</Text>
<Text>Cycle day {getCycleDayNumber(day.date)}</Text>
<Text style={styles.welcome}>{bleedingLabel}</Text>
<Button
onPress={() => navigate('bleeding', { cycleDay: day })}
@@ -53,6 +53,6 @@ export default class DayView extends Component {
function setStateWithCurrentCycleDayNumber() {
this.setState({
cycleDayNumber: getCycleDay(this.cycleDay.date)
cycleDayNumber: getCycleDayNumber(this.cycleDay.date)
})
}
+6 -6
View File
@@ -1,15 +1,15 @@
import * as joda from 'js-joda'
import { bleedingDaysSortedByDate as bleedingDaysSortedByDateView} from './db'
const LocalDate = joda.LocalDate
export default function config(bleedingDaysSortedByDateView, opts) {
opts = opts || {
maxBreakInBleeding: 1
}
export default function config(opts = {}) {
const bleedingDaysSortedByDate = opts.bleedingDaysSortedByDate || bleedingDaysSortedByDateView
const maxBreakInBleeding = opts.maxBreakInBleeding || 1
return function getCycleDayNumber(targetDateString) {
const targetDate = LocalDate.parse(targetDateString)
const withWrappedDates = bleedingDaysSortedByDateView
const withWrappedDates = bleedingDaysSortedByDate
.filter(day => !day.bleeding.exclude)
.map(day => {
day.wrappedDate = LocalDate.parse(day.date)
@@ -21,7 +21,7 @@ export default function config(bleedingDaysSortedByDateView, opts) {
const previousBleedingDays = withWrappedDates.slice(firstBleedingDayBeforeTargetDayIndex)
const lastPeriodStart = previousBleedingDays.find((day, i) => {
return thereIsNoPreviousBleedingDayWithinTheThreshold(day, previousBleedingDays.slice(i + 1), opts.maxBreakInBleeding)
return thereIsNoPreviousBleedingDayWithinTheThreshold(day, previousBleedingDays.slice(i + 1), maxBreakInBleeding)
})
const diffInDays = lastPeriodStart.wrappedDate.until(targetDate, joda.ChronoUnit.DAYS)
+2 -3
View File
@@ -9,13 +9,12 @@ import cycleDayModule from './get-cycle-day-number'
import { bleedingDaysSortedByDate, deleteAll } from './db'
import { LocalDate } from 'js-joda'
const getCycleDayNumber = cycleDayModule(bleedingDaysSortedByDate)
const getCycleDayNumber = cycleDayModule()
export default class Home extends Component {
constructor(props) {
super(props)
const now = new Date()
this.todayDateString = LocalDate.of(now.getFullYear(), now.getMonth() + 1, now.getDate()).toString()
this.todayDateString = LocalDate.now().toString()
const cycleDayNumber = getCycleDayNumber(this.todayDateString)
this.state = {
+7 -7
View File
@@ -24,7 +24,7 @@ describe('getCycleDay', () => {
value: 2
}
}]
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays)
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays})
const targetDate = '2018-05-17'
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(9)
@@ -50,7 +50,7 @@ describe('getCycleDay', () => {
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays)
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays})
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(15)
})
@@ -74,7 +74,7 @@ describe('getCycleDay', () => {
}]
const targetDate = '2018-04-27'
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays)
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays})
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(18)
})
@@ -84,14 +84,14 @@ describe('getCycleDay returns null', () => {
it('if there are no bleeding days', function () {
const bleedingDays = []
const targetDate = '2018-05-17'
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays)
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays})
const result = getCycleDayNumber(targetDate)
expect(result).to.be.null()
})
})
describe('getCycleDay with cycle thresholds', () => {
const opts = { maxBreakInBleeding: 3 }
const maxBreakInBleeding = 3
it('disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period', () => {
const bleedingDays = [{
@@ -107,7 +107,7 @@ describe('getCycleDay with cycle thresholds', () => {
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays, opts)
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding })
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(8)
})
@@ -125,7 +125,7 @@ describe('getCycleDay with cycle thresholds', () => {
}
}]
const targetDate = '2018-05-17'
const getCycleDayNumber = getCycleDayNumberModule(bleedingDays, opts)
const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding })
const result = getCycleDayNumber(targetDate)
expect(result).to.eql(4)
})