Skip to content

Commit e2d79c4

Browse files
test(snapshots): Add unit tests for pixel limit validation
Cover passing, boundary, single violation, multiple violations, and empty input cases for validate_image_sizes. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 852332e commit e2d79c4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/commands/build/snapshots.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,58 @@ fn upload_images(
314314
}
315315
}
316316
}
317+
318+
#[cfg(test)]
319+
mod tests {
320+
use super::*;
321+
322+
fn make_image(name: &str, width: u32, height: u32) -> ImageInfo {
323+
ImageInfo {
324+
path: PathBuf::from(name),
325+
relative_path: PathBuf::from(name),
326+
width,
327+
height,
328+
}
329+
}
330+
331+
#[test]
332+
fn test_validate_image_sizes_passes_under_limit() {
333+
let images = vec![
334+
make_image("small.png", 1000, 1000),
335+
make_image("medium.png", 5000, 7999),
336+
];
337+
assert!(validate_image_sizes(&images).is_ok());
338+
}
339+
340+
#[test]
341+
fn test_validate_image_sizes_passes_at_limit() {
342+
let images = vec![make_image("exact.png", 8000, 5000)];
343+
assert!(validate_image_sizes(&images).is_ok());
344+
}
345+
346+
#[test]
347+
fn test_validate_image_sizes_fails_over_limit() {
348+
let images = vec![
349+
make_image("ok.png", 100, 100),
350+
make_image("too_big.png", 8001, 5000),
351+
];
352+
let err = validate_image_sizes(&images).unwrap_err();
353+
assert!(err.to_string().contains("1 image exceeded"));
354+
}
355+
356+
#[test]
357+
fn test_validate_image_sizes_reports_multiple_violations() {
358+
let images = vec![
359+
make_image("big1.png", 10000, 5000),
360+
make_image("big2.png", 8000, 6000),
361+
];
362+
let err = validate_image_sizes(&images).unwrap_err();
363+
assert!(err.to_string().contains("2 images exceeded"));
364+
}
365+
366+
#[test]
367+
fn test_validate_image_sizes_empty_list() {
368+
let images: Vec<ImageInfo> = vec![];
369+
assert!(validate_image_sizes(&images).is_ok());
370+
}
371+
}

0 commit comments

Comments
 (0)