@@ -61,18 +61,20 @@ impl<'a> From<&'a Line> for Row<'a> {
61
61
}
62
62
}
63
63
64
- fn gray_borders ( ) -> BorderColor {
65
- let gray = Color :: parse ( ' ' . fg_rgb :: < 85 , 85 , 85 > ( ) . to_string ( ) ) . clone ( ) ;
64
+ fn gray ( ) -> Color {
65
+ Color :: parse ( ' ' . fg_rgb :: < 85 , 85 , 85 > ( ) . to_string ( ) ) . clone ( )
66
+ }
66
67
68
+ fn gray_borders ( ) -> BorderColor {
67
69
BorderColor :: new ( )
68
- . top ( gray. clone ( ) )
69
- . left ( gray. clone ( ) )
70
- . bottom ( gray. clone ( ) )
71
- . right ( gray. clone ( ) )
72
- . corner_bottom_right ( gray. clone ( ) )
73
- . corner_bottom_left ( gray. clone ( ) )
74
- . corner_top_left ( gray. clone ( ) )
75
- . corner_top_right ( gray. clone ( ) )
70
+ . top ( gray ( ) . clone ( ) )
71
+ . left ( gray ( ) . clone ( ) )
72
+ . bottom ( gray ( ) . clone ( ) )
73
+ . right ( gray ( ) . clone ( ) )
74
+ . corner_bottom_right ( gray ( ) . clone ( ) )
75
+ . corner_bottom_left ( gray ( ) . clone ( ) )
76
+ . corner_top_left ( gray ( ) . clone ( ) )
77
+ . corner_top_right ( gray ( ) . clone ( ) )
76
78
}
77
79
78
80
impl Display for TimeSheet {
@@ -90,6 +92,7 @@ impl Display for TimeSheet {
90
92
Rows :: first ( ) ,
91
93
) )
92
94
. with ( Panel :: footer ( format ! ( "Week {}" , self . week_number) ) )
95
+ . with ( Colorization :: exact ( [ gray ( ) ] , Rows :: last ( ) ) )
93
96
. with ( gray_borders ( ) ) ;
94
97
95
98
write ! ( f, "{table}" )
@@ -99,9 +102,10 @@ impl Display for TimeSheet {
99
102
#[ cfg( test) ]
100
103
mod test {
101
104
use super :: * ;
105
+ use crate :: domain:: models:: { hours:: Hours , time_sheet:: Week } ;
102
106
103
107
#[ test]
104
- fn display_hours_test ( ) {
108
+ fn displays_hours ( ) {
105
109
let hours = [ 1.5 , 0.25 , 12.75 , 0.0 , 23.999 , 10.1 ] ;
106
110
let expected = [ "1:30" , "0:15" , "12:45" , "" , "23:59" , "10:06" ] ;
107
111
@@ -110,4 +114,72 @@ mod test {
110
114
assert_eq ! ( result, expected[ i] , "Failed at index {}" , i) ;
111
115
}
112
116
}
117
+
118
+ fn create_week ( days : [ u8 ; 7 ] ) -> Week {
119
+ let days: Vec < f32 > = days. into_iter ( ) . map ( Into :: into) . collect ( ) ;
120
+ Week {
121
+ monday : Hours ( days[ 0 ] ) ,
122
+ tuesday : Hours ( days[ 1 ] ) ,
123
+ wednesday : Hours ( days[ 2 ] ) ,
124
+ thursday : Hours ( days[ 3 ] ) ,
125
+ friday : Hours ( days[ 4 ] ) ,
126
+ saturday : Hours ( days[ 5 ] ) ,
127
+ sunday : Hours ( days[ 6 ] ) ,
128
+ }
129
+ }
130
+
131
+ #[ test]
132
+ fn display_ansi_stripped_timesheet ( ) {
133
+ let time_sheet = ( TimeSheet {
134
+ lines : vec ! [
135
+ Line {
136
+ job: "Job number one" . to_string( ) ,
137
+ task: "Task number one" . to_string( ) ,
138
+ week: create_week( [ 8 , 8 , 0 , 0 , 0 , 0 , 0 ] ) ,
139
+ } ,
140
+ Line {
141
+ job: "job number two" . to_string( ) ,
142
+ task: "task number two" . to_string( ) ,
143
+ week: create_week( [ 0 , 0 , 8 , 8 , 1 , 1 , 0 ] ) ,
144
+ } ,
145
+ Line {
146
+ job: "job number three" . to_string( ) ,
147
+ task: "task number three" . to_string( ) ,
148
+ week: create_week( [ 0 , 0 , 0 , 0 , 7 , 7 , 8 ] ) ,
149
+ } ,
150
+ ] ,
151
+ week_number : 47 ,
152
+ } )
153
+ . to_string ( ) ;
154
+
155
+ // Strip away ANSI colorsa for easier debugging
156
+ let ansi_stripped_time_sheet = anstream:: adapter:: strip_str ( & time_sheet) ;
157
+ insta:: assert_snapshot!( ansi_stripped_time_sheet. to_string( ) ) ;
158
+ }
159
+
160
+ #[ test]
161
+ fn display_timesheet ( ) {
162
+ let time_sheet = ( TimeSheet {
163
+ lines : vec ! [
164
+ Line {
165
+ job: "Job number one" . to_string( ) ,
166
+ task: "Task number one" . to_string( ) ,
167
+ week: create_week( [ 8 , 8 , 0 , 0 , 0 , 0 , 0 ] ) ,
168
+ } ,
169
+ Line {
170
+ job: "job number two" . to_string( ) ,
171
+ task: "task number two" . to_string( ) ,
172
+ week: create_week( [ 0 , 0 , 8 , 8 , 1 , 1 , 0 ] ) ,
173
+ } ,
174
+ Line {
175
+ job: "job number three" . to_string( ) ,
176
+ task: "task number three" . to_string( ) ,
177
+ week: create_week( [ 0 , 0 , 0 , 0 , 7 , 7 , 8 ] ) ,
178
+ } ,
179
+ ] ,
180
+ week_number : 47 ,
181
+ } )
182
+ . to_string ( ) ;
183
+ insta:: assert_snapshot!( time_sheet. to_string( ) ) ;
184
+ }
113
185
}
0 commit comments