Add comprehensive testing infrastructure: visual snapshots, unit, property, and theme tests
Introduces a multi-layered testing strategy for the libcosmic widget toolkit: - Visual snapshot testing: Renders widgets via tiny-skia software renderer and compares pixel output against reference PNGs. Generates diff images on failure. Covers containers, dividers, text styles, progress bars, and layouts. - Widget unit tests: Thorough behavioral tests for segmented button model (selection, ordering, data storage, enable/disable, closable, indent), calendar model (month navigation, year wrapping, date selection, grid layout), spin button (clamping, increment/decrement, float support), and color picker. - Property-based tests (proptest): Randomized input testing for spin button bounds invariants, calendar first-day-of-week correctness, segmented model length/clear/toggle invariants, and theme spacing monotonicity. - Theme consistency tests: Validates all four theme variants (dark, light, high-contrast dark/light) have valid spacing, corner radii ordering, non-zero-alpha colors, visible text-on-background, and RON round-trip serialization. - Expanded inline tests: 16 new spin_button unit tests covering increment, decrement, clamping, float types, and constructor value bounds. - CI integration: New visual-tests job runs snapshot, theme, property, and widget tests with artifact upload on failure for snapshot diffs. https://claude.ai/code/session_01P3WLXMif9wmNXbWDo5FhRQ
This commit is contained in:
parent
3e78eb2381
commit
d25a51bd32
17 changed files with 1788 additions and 2 deletions
|
|
@ -318,8 +318,98 @@ fn container_style(theme: &crate::Theme) -> iced_widget::container::Style {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn decrement() {
|
||||
assert_eq!(super::decrement(0i32, 10, 15, 35), 15);
|
||||
fn decrement_clamps_to_min() {
|
||||
assert_eq!(decrement(0i32, 10, 15, 35), 15);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decrement_normal_step() {
|
||||
assert_eq!(decrement(20i32, 5, 0, 100), 15);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decrement_at_min_stays_at_min() {
|
||||
assert_eq!(decrement(0i32, 1, 0, 100), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decrement_near_min_clamps() {
|
||||
assert_eq!(decrement(3i32, 5, 0, 100), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn increment_normal_step() {
|
||||
assert_eq!(increment(20i32, 5, 0, 100), 25);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn increment_clamps_to_max() {
|
||||
assert_eq!(increment(98i32, 5, 0, 100), 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn increment_at_max_stays_at_max() {
|
||||
assert_eq!(increment(100i32, 1, 0, 100), 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn increment_near_max_clamps() {
|
||||
assert_eq!(increment(97i32, 5, 0, 100), 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn increment_then_decrement_round_trips() {
|
||||
let val = 50i32;
|
||||
let step = 10;
|
||||
let min = 0;
|
||||
let max = 100;
|
||||
let up = increment(val, step, min, max);
|
||||
let back = decrement(up, step, min, max);
|
||||
assert_eq!(back, val);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_increment() {
|
||||
let result = increment(0.5f64, 0.1, 0.0, 1.0);
|
||||
assert!((result - 0.6).abs() < f64::EPSILON);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_decrement() {
|
||||
let result = decrement(0.5f64, 0.1, 0.0, 1.0);
|
||||
assert!((result - 0.4).abs() < f64::EPSILON);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_clamps_value_below_min() {
|
||||
let sb = SpinButton::new("test", -5i32, 1, 0, 100, Orientation::Horizontal, |v| v);
|
||||
assert_eq!(sb.value, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_clamps_value_above_max() {
|
||||
let sb = SpinButton::new("test", 200i32, 1, 0, 100, Orientation::Horizontal, |v| v);
|
||||
assert_eq!(sb.value, 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_accepts_value_in_range() {
|
||||
let sb = SpinButton::new("test", 50i32, 1, 0, 100, Orientation::Horizontal, |v| v);
|
||||
assert_eq!(sb.value, 50);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_accepts_value_at_min() {
|
||||
let sb = SpinButton::new("test", 0i32, 1, 0, 100, Orientation::Horizontal, |v| v);
|
||||
assert_eq!(sb.value, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_accepts_value_at_max() {
|
||||
let sb = SpinButton::new("test", 100i32, 1, 0, 100, Orientation::Horizontal, |v| v);
|
||||
assert_eq!(sb.value, 100);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue