@@ -197,6 +197,58 @@ def test_frames_with_empty_given_state(config_dir, mocker):
197
197
mocker .patch ('builtins.open' , mocker .mock_open (read_data = content ))
198
198
assert len (watson .frames ) == 0
199
199
200
+ def test_frames_with_note (mocker , watson ):
201
+ """Test loading frames with notes."""
202
+ content = json .dumps ([
203
+ [3601 , 3610 , 'foo' , 'abcdefg' , ['A' , 'B' , 'C' ], 3650 ,
204
+ "My hovercraft is full of eels" ]
205
+ ])
206
+
207
+ mocker .patch ('builtins.open' , mocker .mock_open (read_data = content ))
208
+ assert len (watson .frames ) == 1
209
+ frame = watson .frames ['abcdefg' ]
210
+ assert frame .id == 'abcdefg'
211
+ assert frame .project == 'foo'
212
+ assert frame .start == arrow .get (3601 )
213
+ assert frame .stop == arrow .get (3610 )
214
+ assert frame .tags == ['A' , 'B' , 'C' ]
215
+ assert frame .note == "My hovercraft is full of eels"
216
+
217
+
218
+ def test_frames_without_note (mocker , watson ):
219
+ """Test loading frames without notes."""
220
+ content = json .dumps ([
221
+ [3601 , 3610 , 'foo' , 'abcdefg' ],
222
+ [3611 , 3620 , 'foo' , 'hijklmn' , ['A' , 'B' , 'C' ]],
223
+ [3621 , 3630 , 'foo' , 'opqrstu' , ['A' , 'B' , 'C' ], 3630 ]
224
+ ])
225
+
226
+ mocker .patch ('builtins.open' , mocker .mock_open (read_data = content ))
227
+ assert len (watson .frames ) == 3
228
+ frame = watson .frames ['abcdefg' ]
229
+ assert frame .id == 'abcdefg'
230
+ assert frame .project == 'foo'
231
+ assert frame .start == arrow .get (3601 )
232
+ assert frame .stop == arrow .get (3610 )
233
+ assert frame .tags == []
234
+ assert frame .note is None
235
+
236
+ frame = watson .frames ['hijklmn' ]
237
+ assert frame .id == 'hijklmn'
238
+ assert frame .tags == ['A' , 'B' , 'C' ]
239
+ assert frame .note is None
240
+
241
+ frame = watson .frames ['opqrstu' ]
242
+ assert frame .id == 'opqrstu'
243
+ assert frame .tags == ['A' , 'B' , 'C' ]
244
+ assert frame .updated_at == arrow .get (3630 )
245
+ assert frame .note is None
246
+
247
+
248
+
249
+
250
+
251
+
200
252
201
253
# config
202
254
@@ -355,6 +407,30 @@ def test_stop_started_project_at(watson):
355
407
watson .stop (stop_at = now )
356
408
assert watson .frames [- 1 ].stop == now
357
409
410
+ def test_stop_started_project_without_note (watson ):
411
+ """Test stopping watson without adding a note."""
412
+ watson .start ('foo' )
413
+ watson .stop ()
414
+
415
+ assert watson .current == {}
416
+ assert watson .is_started is False
417
+ assert len (watson .frames ) == 1
418
+ frame = watson .frames [0 ]
419
+ assert frame .project == 'foo'
420
+ assert frame .note is None
421
+
422
+
423
+ def test_stop_started_project_with_note (watson ):
424
+ """Test stopping watson when adding a note."""
425
+ watson .start ('foo' )
426
+ watson .stop (None , "My hovercraft is full of eels" )
427
+
428
+ assert watson .current == {}
429
+ assert watson .is_started is False
430
+ assert len (watson .frames ) == 1
431
+ frame = watson .frames [0 ]
432
+ assert frame .project == 'foo'
433
+ assert frame .note == "My hovercraft is full of eels"
358
434
359
435
# cancel
360
436
@@ -419,7 +495,7 @@ def test_save_empty_current(config_dir, mocker, json_mock):
419
495
420
496
assert json_mock .call_count == 1
421
497
result = json_mock .call_args [0 ][0 ]
422
- assert result == {'project' : 'foo' , 'start' : 4000 , 'tags' : []}
498
+ assert result == {'project' : 'foo' , 'start' : 4000 , 'tags' : [], 'note' : None }
423
499
424
500
watson .current = {}
425
501
watson .save ()
@@ -779,9 +855,12 @@ def test_report(watson):
779
855
assert 'time' in report ['projects' ][0 ]['tags' ][0 ]
780
856
assert report ['projects' ][0 ]['tags' ][1 ]['name' ] == 'B'
781
857
assert 'time' in report ['projects' ][0 ]['tags' ][1 ]
858
+ assert len (report ['projects' ][0 ]['notes' ]) == 0
859
+ assert len (report ['projects' ][0 ]['tags' ][0 ]['notes' ]) == 0
860
+ assert len (report ['projects' ][0 ]['tags' ][1 ]['notes' ]) == 0
782
861
783
862
watson .start ('bar' , tags = ['C' ])
784
- watson .stop ()
863
+ watson .stop (note = 'bar note' )
785
864
786
865
report = watson .report (arrow .now (), arrow .now ())
787
866
assert len (report ['projects' ]) == 2
@@ -790,6 +869,13 @@ def test_report(watson):
790
869
assert len (report ['projects' ][0 ]['tags' ]) == 1
791
870
assert report ['projects' ][0 ]['tags' ][0 ]['name' ] == 'C'
792
871
872
+ assert len (report ['projects' ][1 ]['notes' ]) == 0
873
+ assert len (report ['projects' ][1 ]['tags' ][0 ]['notes' ]) == 0
874
+ assert len (report ['projects' ][1 ]['tags' ][1 ]['notes' ]) == 0
875
+ assert len (report ['projects' ][0 ]['notes' ]) == 0
876
+ assert len (report ['projects' ][0 ]['tags' ][0 ]['notes' ]) == 1
877
+ assert report ['projects' ][0 ]['tags' ][0 ]['notes' ][0 ] == 'bar note'
878
+
793
879
report = watson .report (
794
880
arrow .now (), arrow .now (), projects = ['foo' ], tags = ['B' ]
795
881
)
@@ -799,16 +885,38 @@ def test_report(watson):
799
885
assert report ['projects' ][0 ]['tags' ][0 ]['name' ] == 'B'
800
886
801
887
watson .start ('baz' , tags = ['D' ])
802
- watson .stop ()
888
+ watson .stop (note = 'baz note' )
889
+
890
+ watson .start ('foo' )
891
+ watson .stop (note = 'foo no tags' )
892
+
893
+ watson .start ('foo' , tags = ['A' ])
894
+ watson .stop (note = 'foo one tag A' )
803
895
804
896
report = watson .report (arrow .now (), arrow .now (), projects = ["foo" ])
897
+
805
898
assert len (report ['projects' ]) == 1
899
+ assert len (report ['projects' ][0 ]['notes' ]) == 1
900
+ # A project-level note because this frame has no tags
901
+ assert report ['projects' ][0 ]['notes' ][0 ] == 'foo no tags'
902
+ assert len (report ['projects' ][0 ]['tags' ]) == 2
903
+ assert report ['projects' ][0 ]['tags' ][0 ]['name' ] == 'A'
904
+ assert report ['projects' ][0 ]['tags' ][1 ]['name' ] == 'B'
905
+ assert len (report ['projects' ][0 ]['tags' ][0 ]['notes' ]) == 1
906
+ assert len (report ['projects' ][0 ]['tags' ][1 ]['notes' ]) == 0
907
+ # A tag-level note because this frame has tags
908
+ assert report ['projects' ][0 ]['tags' ][0 ]['notes' ][0 ] == 'foo one tag A'
909
+
910
+
806
911
807
912
report = watson .report (arrow .now (), arrow .now (), ignore_projects = ["bar" ])
808
913
assert len (report ['projects' ]) == 2
809
914
810
915
report = watson .report (arrow .now (), arrow .now (), tags = ["A" ])
811
916
assert len (report ['projects' ]) == 1
917
+ assert len (report ['projects' ][0 ]['notes' ]) == 0
918
+ assert len (report ['projects' ][0 ]['tags' ][0 ]['notes' ]) == 1
919
+ assert report ['projects' ][0 ]['tags' ][0 ]['notes' ][0 ] == 'foo one tag A'
812
920
813
921
report = watson .report (arrow .now (), arrow .now (), ignore_tags = ["D" ])
814
922
assert len (report ['projects' ]) == 2
0 commit comments