forked from akerl/githubchart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
101 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,3 +89,6 @@ pub fn fetch_github_stats( | |
|
||
Ok(stats) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::{Chart, COLOR_SCHEMES}; | ||
|
||
fn sample_stats() -> Vec<(String, i32)> { | ||
vec![ | ||
("2024-01-01".to_string(), 0), | ||
("2024-01-02".to_string(), 1), | ||
("2024-01-03".to_string(), 4), | ||
("2024-01-04".to_string(), 7), | ||
("2024-01-05".to_string(), 10), | ||
] | ||
} | ||
|
||
#[test] | ||
fn test_chart_creation() { | ||
let stats = sample_stats(); | ||
let chart = Chart::new(stats.clone(), None); | ||
assert_eq!(chart.stats, stats); | ||
assert_eq!(chart.colors.len(), 5); | ||
} | ||
|
||
#[test] | ||
fn test_chart_with_custom_colors() { | ||
let stats = sample_stats(); | ||
let colors = Some(COLOR_SCHEMES[2].1.to_vec()); // Halloween scheme | ||
let chart = Chart::new(stats, colors.clone()); | ||
assert_eq!(chart.colors, colors.unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_svg_rendering() { | ||
let stats = sample_stats(); | ||
let chart = Chart::new(stats, None); | ||
let svg = chart.render().unwrap(); | ||
|
||
// Basic SVG structure | ||
assert!(svg.starts_with("<svg")); | ||
assert!(svg.ends_with("</svg>")); | ||
|
||
// Check for required elements | ||
assert!(svg.contains("<rect")); // Contribution squares | ||
assert!(svg.contains("Mon")); // Weekday labels | ||
assert!(svg.contains("Jan")); // Month label | ||
|
||
// Check color usage | ||
assert!(svg.contains("#eeeeee")); // Default color scheme | ||
assert!(svg.contains("#c6e48b")); | ||
} | ||
|
||
#[test] | ||
fn test_color_schemes() { | ||
// Test default scheme | ||
assert_eq!(COLOR_SCHEMES[0].0, "default"); | ||
assert_eq!(COLOR_SCHEMES[0].1.len(), 5); | ||
|
||
// Test old scheme | ||
assert_eq!(COLOR_SCHEMES[1].0, "old"); | ||
assert_eq!(COLOR_SCHEMES[1].1.len(), 5); | ||
|
||
// Test halloween scheme | ||
assert_eq!(COLOR_SCHEMES[2].0, "halloween"); | ||
assert_eq!(COLOR_SCHEMES[2].1.len(), 5); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use regex::Regex; | ||
|
||
use githubchart::{fetch_github_stats, Chart, COLOR_SCHEMES}; | ||
|
||
#[test] | ||
fn test_github_stats_fetching() { | ||
// Note: This test requires internet connection | ||
match fetch_github_stats("frytg") { | ||
Ok(stats) => { | ||
assert!(!stats.is_empty()); | ||
// Check date format | ||
assert!(Regex::new(r"^\d{4}-\d{2}-\d{2}$") | ||
.unwrap() | ||
.is_match(&stats[0].0)); | ||
// Check contribution count is non-negative | ||
assert!(stats[0].1 >= 0); | ||
} | ||
Err(e) => panic!("Failed to fetch stats: {}", e), | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_full_chart_generation() { | ||
let stats = vec![("2024-01-01".to_string(), 0), ("2024-01-02".to_string(), 5)]; | ||
let chart = Chart::new(stats, Some(COLOR_SCHEMES[0].1.to_vec())); | ||
let svg = chart.render().expect("Failed to render chart"); | ||
|
||
assert!(svg.contains("svg")); | ||
assert!(svg.contains("rect")); | ||
assert!(svg.contains("Jan")); // Month label | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.