## Tests for OutfitItem — applies outfit layer when dropped near a character.
extends GutTest


func test_outfit_item_default_layer_is_one() -> void:
	var item: OutfitItem = OutfitItem.new()
	add_child_autofree(item)
	assert_eq(item.outfit_layer, 1)


func test_outfit_item_applies_to_character_on_release_in_range() -> void:
	var character: Character = preload("res://scenes/characters/Character.tscn").instantiate() as Character
	add_child_autofree(character)
	var data: CharacterData = CharacterData.new()
	character.data = data
	var item: OutfitItem = OutfitItem.new()
	add_child_autofree(item)
	item.item_id = "white_coat"
	item.outfit_layer = 1
	item.outfit_sprite = null
	item.global_position = character.global_position
	item._on_drag_released(item.global_position)
	assert_eq(character.get_outfit(1), "white_coat")


func test_outfit_item_hides_after_applying() -> void:
	var character: Character = preload("res://scenes/characters/Character.tscn").instantiate() as Character
	add_child_autofree(character)
	var data: CharacterData = CharacterData.new()
	character.data = data
	var item: OutfitItem = OutfitItem.new()
	add_child_autofree(item)
	item.item_id = "white_coat"
	item.outfit_layer = 1
	item.global_position = character.global_position
	item._on_drag_released(item.global_position)
	assert_false(item.visible)


func test_outfit_item_stays_visible_if_no_character_in_range() -> void:
	var item: OutfitItem = OutfitItem.new()
	add_child_autofree(item)
	item.item_id = "white_coat"
	item.outfit_layer = 1
	item.global_position = Vector2(9999.0, 9999.0)
	item._on_drag_released(item.global_position)
	assert_true(item.visible)
	assert_false(item.is_in_hand_slot())


func test_outfit_item_does_not_apply_if_far_from_character() -> void:
	var character: Character = preload("res://scenes/characters/Character.tscn").instantiate() as Character
	add_child_autofree(character)
	var data: CharacterData = CharacterData.new()
	character.data = data
	var item: OutfitItem = OutfitItem.new()
	add_child_autofree(item)
	item.item_id = "white_coat"
	item.outfit_layer = 1
	item.global_position = Vector2(9999.0, 9999.0)
	item._on_drag_released(item.global_position)
	assert_eq(character.get_outfit(1), "")
	assert_true(item.visible)
