Skip to content

Commit

Permalink
Added amounts for week perDay functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Mendiola committed Dec 14, 2015
1 parent 84b7fa7 commit fcc24f0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/todo-parser.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
moment = require 'moment'
textConsts = require './todo-text-consts'
utils = require './utils'

module.exports =
todoModel: []
Expand Down Expand Up @@ -72,10 +73,12 @@ module.exports =

getTotalAmountPerDay: (unit) ->
dailyAmounts = [0, 0, 0, 0, 0, 0, 0]
(item.getTotalAmountPerDay(unit) for section in @children).reduce()
(section.getTotalAmountPerDay(unit) for section in @children)
.reduce(utils.elementSumArray, dailyAmounts)
getCompletedAmountPerDay: (unit) ->
dailyAmounts = [0, 0, 0, 0, 0, 0, 0]
(item.getTotalAmountPerDay(unit) for section in @children)
(section.getCompletedAmountPerDay(unit) for section in @children)
.reduce(utils.elementSumArray, dailyAmounts)

parseH3Line: (index, text) ->
title = text.substring(4)
Expand Down Expand Up @@ -114,6 +117,8 @@ module.exports =
(item.getAmount(unit) for item in @children).reduce( (p, c) -> p + c)
getCompletedAmount: (unit) ->
(item.getCompletedAmount(unit) for item in @children).reduce( (p, c) -> p + c)
getTotalAmountPerDay: (unit) ->
getCompletedAmountPerDay: (unit) ->

parseTodoLine: (rowIndex, text) ->
doneIndex = text.search(textConsts.regex.doneBadge)
Expand Down
32 changes: 32 additions & 0 deletions spec/parser-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,38 @@ describe "TodoParser", ->
testCompleted = week.getCompletedAmount('pants')
expect(testCompleted).toEqual(13)

describe 'per day amount functions', ->
week = section1 = section2 = null
beforeEach ->
week = parser.parseH2Line(rowIndex, h2_valid)
section1 = parser.parseH3Line(rowIndex, "### project 1 ")
section2 = parser.parseH3Line(rowIndex, "### project 2 ")
week.children.push(section1)
week.children.push(section2)
spyOn(section1, 'getTotalAmountPerDay').andReturn([10, 20, 30, 40, 50, 60, 70])
spyOn(section1, 'getCompletedAmountPerDay').andReturn([1, 2, 3, 4, 5, 6, 7])

spyOn(section2, 'getTotalAmountPerDay').andReturn([90, 80, 70, 60, 50, 40, 30])
spyOn(section2, 'getCompletedAmountPerDay').andReturn([9, 8, 7, 6, 5, 4, 3])

describe 'getTotalAmountsPerDay', ->
it 'calls section functions with the right unit', ->
week.getTotalAmountPerDay('pants')
expect(section1.getTotalAmountPerDay).toHaveBeenCalledWith('pants')
expect(section2.getTotalAmountPerDay).toHaveBeenCalledWith('pants')
it 'adds amounts correctly', ->
testResult = week.getTotalAmountPerDay('pants')
expect(testResult).toEqual([100, 100, 100, 100, 100, 100, 100])

describe 'getCompletedAmountPerDay', ->
it 'calls section functions with the right unit', ->
week.getCompletedAmountPerDay('pants')
expect(section1.getCompletedAmountPerDay).toHaveBeenCalledWith('pants')
expect(section2.getCompletedAmountPerDay).toHaveBeenCalledWith('pants')
it 'adds amounts correctly', ->
testResult = week.getCompletedAmountPerDay('pants')
expect(testResult).toEqual([10, 10, 10, 10, 10, 10, 10])

describe 'parseH3Line', ->

describe 'with valid input', ->
Expand Down

0 comments on commit fcc24f0

Please sign in to comment.