diff --git a/bleeding.js b/bleeding.js index 01fc4ce..31dc8c6 100644 --- a/bleeding.js +++ b/bleeding.js @@ -10,7 +10,9 @@ import styles from './styles' import { saveBleeding } from './db' import { formatDateForViewHeader } from './format' import { bleeding as labels } from './labels' -import getCycleDay from './get-cycle-day' +import cycleDayModule from './get-cycle-day-number' + +const getCycleDayNumber = cycleDayModule() export default class Bleeding extends Component { constructor(props) { @@ -39,7 +41,7 @@ export default class Bleeding extends Component { return ( {formatDateForViewHeader(day.date)} - Cycle day {getCycleDay()} + Cycle day {getCycleDayNumber(day.date)} Bleeding {formatDateForViewHeader(cycleDay.date)} - Cycle day {getCycleDay()} + Cycle day {getCycleDayNumber(cycleDay.date)} {bleedingLabel} {temperatureLabel} + ) } } + +function determineWelcomeText(cycleDayNumber) { + const welcomeTextWithCycleDay = `Welcome! Today is day ${cycleDayNumber} of your current cycle` + const welcomeText = `Welcome! We don't have enough information to know what your current cycle day is` + return cycleDayNumber ? welcomeTextWithCycleDay : welcomeText +} + +function setStateWithCurrentWelcomeText() { + this.setState({ welcomeText: determineWelcomeText(getCycleDayNumber(this.todayDateString)) }) +} diff --git a/index.js b/index.js index f1543b7..408a2f0 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,4 @@ import { AppRegistry } from 'react-native' -import Home from './app' -import { openDatabase } from './db' +import App from './app' -// TODO error handling -openDatabase() - .then(() => { - AppRegistry.registerComponent('home', () => Home) - }) \ No newline at end of file +AppRegistry.registerComponent('home', () => App) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 615ce54..4ec7dc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2766,6 +2766,12 @@ "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true }, + "dirty-chai": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/dirty-chai/-/dirty-chai-2.0.1.tgz", + "integrity": "sha512-ys79pWKvDMowIDEPC6Fig8d5THiC0DJ2gmTeGzVAoEH18J8OzLud0Jh7I9IWg3NSk8x2UocznUuFmfHCXYZx9w==", + "dev": true + }, "doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", diff --git a/package.json b/package.json index 98d3dae..ff64b52 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "devDependencies": { "babel-preset-react-native": "4.0.0", "chai": "^4.1.2", + "dirty-chai": "^2.0.1", "eslint": "^4.19.1", "eslint-plugin-react": "^7.8.2", "mocha": "^5.2.0", diff --git a/temperature.js b/temperature.js index ba7121c..5e2f00a 100644 --- a/temperature.js +++ b/temperature.js @@ -10,7 +10,9 @@ import { import styles from './styles' import { saveTemperature, getPreviousTemperature } from './db' import { formatDateForViewHeader } from './format' -import getCycleDay from './get-cycle-day' +import cycleDayModule from './get-cycle-day-number' + +const getCycleDayNumber = cycleDayModule() export default class Temp extends Component { constructor(props) { @@ -37,7 +39,7 @@ export default class Temp extends Component { return ( {formatDateForViewHeader(cycleDay.date)} - Cycle day {getCycleDay()} + Cycle day {getCycleDayNumber()} Temperature { + it('works for a simple example', function () { + const bleedingDays = [{ + date: '2018-05-10', + bleeding: { + value: 2 + } + }, { + date: '2018-05-09', + bleeding: { + value: 2 + } + }, { + date: '2018-05-03', + bleeding: { + value: 2 + } + }] + const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays}) + const targetDate = '2018-05-17' + const result = getCycleDayNumber(targetDate) + expect(result).to.eql(9) + }) + + it('works if some bleedings are exluded', function () { + const bleedingDays = [{ + date: '2018-05-10', + bleeding: { + value: 2, + exclude: true + } + }, { + date: '2018-05-09', + bleeding: { + value: 2, + exclude: true + } + }, { + date: '2018-05-03', + bleeding: { + value: 2 + } + }] + const targetDate = '2018-05-17' + const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays}) + const result = getCycleDayNumber(targetDate) + expect(result).to.eql(15) + }) + + it('gets the correct number if the target day is not in the current cycle', () => { + const bleedingDays = [{ + date: '2018-05-13', + bleeding: { + value: 2 + } + }, { + date: '2018-04-11', + bleeding: { + value: 2 + } + }, { + date: '2018-04-10', + bleeding: { + value: 2 + } + }] + + const targetDate = '2018-04-27' + const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays}) + const result = getCycleDayNumber(targetDate) + expect(result).to.eql(18) + }) + + it('gets the correct number if the target day is the only bleeding day', () => { + const bleedingDays = [{ + date: '2018-05-13', + bleeding: { + value: 2 + } + }] + + const targetDate = '2018-05-13' + const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays}) + const result = getCycleDayNumber(targetDate) + expect(result).to.eql(1) + }) +}) + +describe('getCycleDay returns null', () => { + it('if there are no bleeding days', function () { + const bleedingDays = [] + const targetDate = '2018-05-17' + const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays}) + const result = getCycleDayNumber(targetDate) + expect(result).to.be.null() + }) +}) + +describe('getCycleDay with cycle thresholds', () => { + const maxBreakInBleeding = 3 + + it('disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period', () => { + const bleedingDays = [{ + date: '2018-05-14', + bleeding: { + value: 2 + } + }, { + date: '2018-05-10', + bleeding: { + value: 2 + } + }] + + const targetDate = '2018-05-17' + const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }) + const result = getCycleDayNumber(targetDate) + expect(result).to.eql(8) + }) + + it('counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period', () => { + const bleedingDays = [{ + date: '2018-05-14', + bleeding: { + value: 2 + } + }, { + date: '2018-05-09', + bleeding: { + value: 2 + } + }] + const targetDate = '2018-05-17' + const getCycleDayNumber = getCycleDayNumberModule({bleedingDaysSortedByDate: bleedingDays, maxBreakInBleeding }) + const result = getCycleDayNumber(targetDate) + expect(result).to.eql(4) + }) +}) \ No newline at end of file