Add remaining time calculation
This commit is contained in:
@ -3,11 +3,30 @@ require "./spec_helper"
|
||||
module Dayoff::Test
|
||||
extend self
|
||||
|
||||
def d(day)
|
||||
location = Time::Location.load("Europe/Moscow")
|
||||
Time.local(2019, 1, day, location: location)
|
||||
end
|
||||
|
||||
def t(day, hour, min = 0)
|
||||
location = Time::Location.load("Europe/Moscow")
|
||||
Time.local(2019, 1, day, hour, min, location: location)
|
||||
end
|
||||
|
||||
def create_profile
|
||||
storage = MemoryStorage.new
|
||||
storage.set_planned_dates [
|
||||
PlannedDate.new(d(1), 8),
|
||||
PlannedDate.new(d(2), 8),
|
||||
PlannedDate.new(d(3), 8),
|
||||
]
|
||||
storage.set_work_records [
|
||||
WorkRecord.new(t(1, 10), t(1, 20)),
|
||||
WorkRecord.new(t(2, 10), t(2, 20)),
|
||||
]
|
||||
Profile.new(storage)
|
||||
end
|
||||
|
||||
describe Profile do
|
||||
it "can calc work hours" do
|
||||
storage = MemoryStorage.new
|
||||
@ -15,7 +34,7 @@ module Dayoff::Test
|
||||
WorkRecord.new(t(1, 10), t(1, 20)),
|
||||
]
|
||||
prof = Profile.new(storage)
|
||||
prof.get_work_hours.should eq 10
|
||||
prof.get_work_hours(t(2, 0)).total_hours.should eq 10
|
||||
end
|
||||
|
||||
it "can write new record" do
|
||||
@ -44,5 +63,26 @@ module Dayoff::Test
|
||||
records.size.should eq 2
|
||||
records.last.finish_time.should eq finish_time
|
||||
end
|
||||
|
||||
it "can calc planned hours" do
|
||||
prof = create_profile
|
||||
s = prof.get_planned_hours t(3, 12)
|
||||
expected = 8 * 3
|
||||
expected.should eq s.total_hours
|
||||
end
|
||||
|
||||
it "can calc work hours" do
|
||||
prof = create_profile
|
||||
s = prof.get_work_hours t(3, 12)
|
||||
expected = 10 * 2
|
||||
expected.should eq s.total_hours
|
||||
end
|
||||
|
||||
it "can calc remaining time" do
|
||||
prof = create_profile
|
||||
s = prof.remaining_time t(3, 12)
|
||||
expected = 8 * 3 - 10 * 2
|
||||
expected.should eq s.total_hours
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,2 +1,2 @@
|
||||
require "spec"
|
||||
require "../src/**"
|
||||
require "../src/dayoff/**"
|
||||
|
Reference in New Issue
Block a user