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

use super::*;

#[ test ]
fn defaults()
{
	let t: Tooltip<()> = tooltip( "hi", WidgetId( "x" ) );
	assert_eq!( t.message, "hi" );
	assert_eq!( t.anchor_id.0, "x" );
	assert_eq!( t.max_width, theme::MAX_W );
	assert!( t.on_dismiss.is_none() );
}

#[ test ]
fn overlay_uses_anchor_widget_id()
{
	let id = WidgetId( "btn/save" );
	let o: OverlaySpec<()> = tooltip( "Save", id ).overlay();
	assert_eq!( o.anchor_widget_id, Some( id ) );
}

#[ test ]
fn overlay_id_includes_tooltip_namespace()
{
	// Same WidgetId used for a tooltip and (hypothetically) some
	// other overlay must yield distinct OverlayIds. The tooltip's
	// hash includes the literal "tooltip" prefix to namespace it
	// against e.g. combo overlays that hash only the WidgetId.
	let id = WidgetId( "foo" );
	let tooltip_overlay_id = {
		let mut h = DefaultHasher::new();
		"tooltip".hash( &mut h );
		id.0.hash( &mut h );
		OverlayId( h.finish() as u32 )
	};
	let combo_style_id = {
		let mut h = DefaultHasher::new();
		id.0.hash( &mut h );
		OverlayId( h.finish() as u32 )
	};
	assert_ne!( tooltip_overlay_id, combo_style_id );

	let o: OverlaySpec<()> = tooltip( "x", id ).overlay();
	assert_eq!( o.id, tooltip_overlay_id );
}

#[ test ]
fn max_width_builder_applies()
{
	let t: Tooltip<()> = tooltip( "x", WidgetId( "a" ) ).max_width( 120 );
	assert_eq!( t.max_width, 120 );
}
