| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
 | require 'test_helper'
class CommandTest < HCl::TestCase
  include HCl::Commands
  include HCl::Utility
  def setup
    @settings = {}
  end
  # the current_time utility method needs to be deterministic
  def current_time
    'high noon'
  end
  # stub settings helpers
  def write_settings; end
  def read_settings
    @settings
  end
  def test_tasks
    HCl::Task.expects(:all).returns([HCl::Task.new(
      id:123,
      name: 'Dev',
      project: HCl::Project.new(id:456, name:'App', client:'Bob', code:'b')
    )])
    result = tasks
    assert_equal "456 123\tBob - [b] App - Dev", result
  end
  def test_show
    HCl::DayEntry.expects(:all).returns([HCl::DayEntry.new({
      hours:'2.06',
      notes: 'hi world',
      project: 'App'
    })])
    result = show
    assert_equal \
      "\t2:03\tApp: hi world\n\t-------------\n\t2:03\ttotal (as of high noon)\n",
      result
  end
  def test_aliases
    HCl::Task.expects(:all).returns([HCl::Task.new(
      id:123,
      name: 'Dev',
      project: HCl::Project.new(id:456, name:'App', client:'Bob', code:'b')
    )])
    result = send :alias, *%w[ hcl 456 123 ]
    assert_equal '456 123', @settings['task.hcl']
    result = aliases
    assert_equal ["@hcl"], result
    result = unalias 'hcl'
    assert !@settings.key?('task.hcl'), 'hcl alias is no longer defined'
  end
  def test_start
    task = HCl::Task.new(
      id:123,
      name: 'Dev',
      project: HCl::Project.new(id:456, name:'App', client:'Bob', code:'b')
    )
    HCl::Task.expects(:find).with('456','123').returns(task)
    task.expects(:start).with(starting_time:nil, note:'do stuff')
    start *%w[ 456 123 do stuff ]
  end
  def test_stop
    entry = stub
    HCl::DayEntry.expects(:with_timer).returns(entry)
    entry.expects(:append_note).with('all done')
    entry.expects(:toggle)
    stop 'all done'
  end
  def test_resume
    entry = stub
    HCl::DayEntry.expects(:last).returns(entry)
    entry.expects(:toggle)
    resume
  end
  def test_resume_with_task_alias
    entry = stub
    expects(:get_task_ids).with('mytask',[]).returns(%w[ 456 789 ])
    HCl::DayEntry.expects(:last_by_task).with('456', '789').returns(entry)
    entry.expects(:toggle)
    resume 'mytask'
  end
  def test_cancel
    entry = stub
    HCl::DayEntry.expects(:with_timer).returns(entry)
    entry.expects(:cancel).returns(true)
    cancel
  end
  def test_note
    entry = stub
    HCl::DayEntry.expects(:with_timer).returns(entry)
    entry.expects(:append_note).with('hi world')
    note 'hi world'
  end
  def test_note_display
    entry = stub(notes:"your face")
    HCl::DayEntry.expects(:with_timer).returns(entry)
    assert_equal "your face", note
  end
end
 |