test: make button-paints-content render check theme-robust
Some checks failed
CI / build + test (push) Has been cancelled
CI / cargo audit (push) Has been cancelled

The render_pixels button test rendered on a black canvas and asserted some
pixel differed from black. With no theme dir configured the active theme is
the embedded B/W fallback, whose Light mode defines accent (the button fill)
and text-primary as pure black on a white page — so a fallback button is
black-on-black and the assertion spuriously failed. Render on white instead:
the black fallback button stands out, and a real theme's saturated accent
also differs from white, keeping the structural check theme-independent.
This commit is contained in:
yamabush1
2026-06-01 11:33:35 +02:00
parent 48c5a89712
commit 34b3e76ac1

View File

@@ -148,8 +148,16 @@ fn render_hash_is_stable_across_two_back_to_back_passes()
#[ test ]
fn rendering_a_button_produces_pixels_that_differ_from_the_background()
{
// Render on a WHITE canvas, not black: with no theme dir configured the
// active theme is the embedded B/W fallback, whose Light mode defines
// `accent` (the default button fill) and `text-primary` as pure BLACK on
// a white page. A black canvas would therefore hide a fallback button
// entirely (black-on-black) and this structural "button paints content"
// check would spuriously fail. White matches the fallback's page colour,
// so the black button stands out — and a real theme's saturated accent
// (e.g. teal) differs from white too, keeping the test theme-robust.
let mut surface = UiSurface::<()>::new( 240, 120 );
let bg = Color::rgb( 0.0, 0.0, 0.0 );
let bg = Color::WHITE;
let view: Element<()> = column::<()>().push( button( "tap" ) ).into();
let _ = surface.render(
&view,
@@ -158,7 +166,7 @@ fn rendering_a_button_produces_pixels_that_differ_from_the_background()
let buf = extract_pixels( &surface, 240, 120 );
let differs = buf.chunks_exact( 4 ).any( |chunk|
!( chunk[ 0 ] == 0 && chunk[ 1 ] == 0 && chunk[ 2 ] == 0 && chunk[ 3 ] == 255 )
!( chunk[ 0 ] == 255 && chunk[ 1 ] == 255 && chunk[ 2 ] == 255 && chunk[ 3 ] == 255 )
);
assert!( differs, "a button must paint at least one non-background pixel" );
}