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

use super::*;

#[ test ]
fn text_button_focusable_by_default()
{
	let b = Button::<()>::new( "ok".into() );
	assert!( b.focusable );
}

#[ test ]
fn icon_button_focusable_by_default()
{
	let b = Button::<()>::new_icon( Arc::new( vec![] ), 0, 0 );
	assert!( b.focusable );
}

#[ test ]
fn focusable_builder_disables_focus()
{
	let b = Button::<()>::new( "ok".into() ).focusable( false );
	assert!( !b.focusable );
}

#[ test ]
fn focusable_builder_re_enables_focus()
{
	let b = Button::<()>::new( "ok".into() ).focusable( false ).focusable( true );
	assert!( b.focusable );
}

#[ test ]
fn on_press_none_by_default()
{
	let b = Button::<()>::new( "ok".into() );
	assert!( b.on_press.is_none() );
}

#[ test ]
fn tooltip_none_by_default()
{
	let b = Button::<()>::new( "ok".into() );
	assert!( b.tooltip.is_none() );
	let b = Button::<()>::new_icon( Arc::new( vec![] ), 0, 0 );
	assert!( b.tooltip.is_none() );
}

#[ test ]
fn tooltip_builder_sets_text()
{
	let b = Button::<()>::new( "ok".into() ).tooltip( "Save document" );
	assert_eq!( b.tooltip.as_deref(), Some( "Save document" ) );
}

#[ test ]
fn tooltip_survives_map_msg()
{
	let b = Button::<()>::new( "ok".into() ).tooltip( "Hint" );
	let f: super::super::MapFn<(), u32> = std::sync::Arc::new( |()| 0u32 );
	let mapped = b.map_msg( &f );
	assert_eq!( mapped.tooltip.as_deref(), Some( "Hint" ) );
}

#[ test ]
fn element_tooltip_returns_button_tooltip()
{
	let e: super::super::Element<()> = Button::<()>::new( "ok".into() ).tooltip( "Hi" ).into_element();
	assert_eq!( e.tooltip(), Some( "Hi" ) );
}

#[ test ]
fn element_tooltip_none_for_non_button_widgets()
{
	let t: super::super::Element<()> = super::super::text( "label" ).into();
	assert!( t.tooltip().is_none() );
}

#[ test ]
fn on_press_maybe_none_leaves_disabled()
{
	let b = Button::<()>::new( "ok".into() ).on_press_maybe( None );
	assert!( b.on_press.is_none() );
}

#[ test ]
fn repeating_off_by_default()
{
	let b = Button::<()>::new( "ok".into() );
	assert!( !b.repeating );
}

#[ test ]
fn repeating_builder_sets_flag()
{
	let b = Button::<()>::new( "ok".into() ).repeating( true );
	assert!( b.repeating );
	let b = b.repeating( false );
	assert!( !b.repeating );
}
