// SPDX-License-Identifier: LGPL-2.1-only
// Copyright (C) 2026 Liberux Labs, S. L. <info@liberux.net>

use super::*;
use crate::layout::spacer::spacer;
use crate::render::Canvas;

fn make_canvas() -> Canvas { Canvas::new( 800, 600 ) }

#[ test ]
fn new_defaults_to_weight_one()
{
	let f = Flex::<()>::new( spacer() );
	assert_eq!( f.weight, 1 );
}

#[ test ]
fn weight_builder_sets_relative_weight()
{
	let f = Flex::<()>::new( spacer() ).weight( 5 );
	assert_eq!( f.weight, 5 );
}

#[ test ]
fn preferred_size_reports_zero_width_so_row_treats_it_as_filler()
{
	let canvas = make_canvas();
	let f = Flex::<()>::new( spacer().width( 100.0 ).height( 40.0 ) );
	let ( w, _ ) = f.preferred_size( 600.0, &canvas );
	assert_eq!( w, 0.0, "flex must contribute zero width to the row's intrinsic-width sum" );
}

#[ test ]
fn preferred_size_passes_child_height_through()
{
	let canvas = make_canvas();
	let f = Flex::<()>::new( spacer().width( 100.0 ).height( 40.0 ) );
	let ( _, h ) = f.preferred_size( 600.0, &canvas );
	assert_eq!( h, 40.0 );
}
