test: make button-paints-content render check theme-robust
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:
@@ -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" );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user