Skip to content

Commit

Permalink
[#10] WeekdayService should be used in report.js
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanLin-TWer committed Feb 20, 2017
1 parent dad62b4 commit 2cb2b1a
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 26 deletions.
133 changes: 112 additions & 21 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { Report } from './report'
export { Template } from './template'
export { TimeService } from './services/time-service'
export { TimeService } from './services/time-service'
export { WeekdayService } from './services/weekday-service'
4 changes: 3 additions & 1 deletion src/report.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export class Report {

constructor(timeService) {
constructor(timeService, weekdayService) {
this.timeService = timeService
this.weekdayService = weekdayService
}

getProjectsData(reports, since, until) {
Expand Down Expand Up @@ -41,6 +42,7 @@ export class Report {
return {
totalGrand: this.timeService.millisToHoursAndMinsFormat(totalGrand),
totalDays: this.timeService.daysBetween(since, until),
weekdays: this.weekdayService.weekdaysBetween(since, until),
grandPercentage: `${grandPercentage}%`,
grandHoursPerDay: this.timeService.millisToHoursAndMinsFormat(totalGrand / totalDays)
}
Expand Down
10 changes: 7 additions & 3 deletions test/unit/report.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, beforeEach, before, it } from "mocha"
import { expect } from 'chai'
import sinon from 'sinon'
import { Report, TimeService } from '../../src'
import { Report, TimeService, WeekdayService } from '../../src'

describe('report.js', () => {
let report
Expand All @@ -10,23 +10,27 @@ describe('report.js', () => {
let response

beforeEach('', () => {
report = new Report(new TimeService())
report = new Report(new TimeService(), new WeekdayService())
response = mockReportResponse()
})

describe('getSummaryData(total_grand, since, until)', () => {
it('should call time service to calculate summary data', () => {
let timeService = new TimeService()
let weekdayService = new WeekdayService()
let daysBetween = sinon.spy(timeService, 'daysBetween')
let millisToHoursAndMins = sinon.spy(timeService, 'millisToHoursAndMinsFormat')
let toMillis = sinon.spy(timeService, 'toMillis')
report = new Report(timeService)
let weekdaysBetween = sinon.spy(weekdayService, 'weekdaysBetween')

report = new Report(timeService, weekdayService)

let summary = report.getSummaryData(1000 * 60, '2016-01-01', '2016-01-01')

expect(daysBetween.calledWith('2016-01-01', '2016-01-01')).to.be.true
expect(millisToHoursAndMins.calledWith(1000 * 60)).to.be.true
expect(toMillis.calledWith(1)).to.be.true
expect(weekdaysBetween.calledWith('2016-01-01', '2016-01-01')).to.be.true

expect(summary.totalGrand).to.equal('0h 1min')
expect(summary.totalDays).to.equal(1)
Expand Down

0 comments on commit 2cb2b1a

Please sign in to comment.