Skip to content

Commit 61009ae

Browse files
committed
Make footer gray
Also, add some rendering snapshot tests
1 parent b145e31 commit 61009ae

5 files changed

+126
-18
lines changed

Cargo.lock

+9-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ assert_cmd = "2.0.16"
4141
wiremock = "0.6.2"
4242
predicates = "3.1.2"
4343
insta = { version = "1.41.1", features = ["yaml", "json"] }
44+
anstyle = "1.0.10"
45+
anstream = "0.6.18"
4446

4547
# Improved insta runtime
4648
[profile.dev.package]

src/cli/rendering.rs

+83-11
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,20 @@ impl<'a> From<&'a Line> for Row<'a> {
6161
}
6262
}
6363

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+
}
6667

68+
fn gray_borders() -> BorderColor {
6769
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())
7678
}
7779

7880
impl Display for TimeSheet {
@@ -90,6 +92,7 @@ impl Display for TimeSheet {
9092
Rows::first(),
9193
))
9294
.with(Panel::footer(format!("Week {}", self.week_number)))
95+
.with(Colorization::exact([gray()], Rows::last()))
9396
.with(gray_borders());
9497

9598
write!(f, "{table}")
@@ -99,9 +102,10 @@ impl Display for TimeSheet {
99102
#[cfg(test)]
100103
mod test {
101104
use super::*;
105+
use crate::domain::models::{hours::Hours, time_sheet::Week};
102106

103107
#[test]
104-
fn display_hours_test() {
108+
fn displays_hours() {
105109
let hours = [1.5, 0.25, 12.75, 0.0, 23.999, 10.1];
106110
let expected = ["1:30", "0:15", "12:45", "", "23:59", "10:06"];
107111

@@ -110,4 +114,72 @@ mod test {
110114
assert_eq!(result, expected[i], "Failed at index {}", i);
111115
}
112116
}
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+
}
113185
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
source: src/cli/rendering.rs
3+
expression: ansi_stripped_time_sheet.to_string()
4+
snapshot_kind: text
5+
---
6+
╭───────────────────────────────────────────────────────────────────────────────╮
7+
Job name Task name Mon Tue Wed Thu Fri Sat Sun
8+
├───────────────────────────────────────────────────────────────────────────────┤
9+
Job number one Task number one 8:00 8:00
10+
├───────────────────────────────────────────────────────────────────────────────┤
11+
job number two task number two 8:00 8:00 1:00 1:00
12+
├───────────────────────────────────────────────────────────────────────────────┤
13+
job number three task number three 7:00 7:00 8:00
14+
├───────────────────────────────────────────────────────────────────────────────┤
15+
Week 47
16+
╰───────────────────────────────────────────────────────────────────────────────╯
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
source: src/cli/rendering.rs
3+
expression: time_sheet.to_string()
4+
snapshot_kind: text
5+
---
6+
╭───────────────────────────────────────────────────────────────────────────────╮
7+
│ Job name   Task name   Mon   Tue   Wed   Thu   Fri   Sat   Sun  │
8+
├───────────────────────────────────────────────────────────────────────────────┤
9+
│ Job number one Task number one 8:00 8:00 │
10+
├───────────────────────────────────────────────────────────────────────────────┤
11+
│ job number two task number two 8:00 8:00 1:00 1:00 │
12+
├───────────────────────────────────────────────────────────────────────────────┤
13+
│ job number three task number three 7:00 7:00 8:00 │
14+
├───────────────────────────────────────────────────────────────────────────────┤
15+
│ Week 47  │
16+
╰───────────────────────────────────────────────────────────────────────────────╯

0 commit comments

Comments
 (0)