95 lines
3.1 KiB
Python
95 lines
3.1 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from engine.character import Character, ClothingPiece
|
|
from engine.defs import DefRegistry
|
|
from engine.ui import CharacterMenu
|
|
|
|
DEFS_DIR = Path(__file__).resolve().parent.parent / "resources" / "defs"
|
|
|
|
|
|
@pytest.fixture()
|
|
def registry():
|
|
return DefRegistry.load(DEFS_DIR)
|
|
|
|
|
|
def make_human(registry, **kwargs) -> Character:
|
|
return Character(species_id="human", default_body_parts=registry.new_default_body_parts("human"), **kwargs)
|
|
|
|
|
|
def test_defaults_to_the_bio_tab():
|
|
menu = CharacterMenu()
|
|
assert menu.active_tab == "bio"
|
|
|
|
|
|
def test_select_tab_switches_to_equipment():
|
|
menu = CharacterMenu()
|
|
menu.select_tab("equipment")
|
|
assert menu.active_tab == "equipment"
|
|
|
|
|
|
def test_select_tab_ignores_unknown_tab_names():
|
|
menu = CharacterMenu()
|
|
menu.select_tab("inventory") # not a real tab
|
|
assert menu.active_tab == "bio"
|
|
|
|
|
|
def test_switching_tabs_closes_any_open_backpack_popup(registry):
|
|
menu = CharacterMenu()
|
|
character = make_human(registry, clothing=[ClothingPiece("back", "backpack_basic")])
|
|
menu.right_click_equipment_slot("back", character, registry)
|
|
assert menu.open_backpack_slot == "back"
|
|
menu.select_tab("bio")
|
|
assert menu.open_backpack_slot is None
|
|
|
|
|
|
def test_right_click_backpack_opens_popup(registry):
|
|
menu = CharacterMenu()
|
|
character = make_human(registry, clothing=[ClothingPiece("back", "backpack_basic")])
|
|
opened = menu.right_click_equipment_slot("back", character, registry)
|
|
assert opened is True
|
|
assert menu.open_backpack_slot == "back"
|
|
|
|
|
|
def test_right_click_same_slot_again_closes_the_popup(registry):
|
|
menu = CharacterMenu()
|
|
character = make_human(registry, clothing=[ClothingPiece("back", "backpack_basic")])
|
|
menu.right_click_equipment_slot("back", character, registry)
|
|
closed = menu.right_click_equipment_slot("back", character, registry)
|
|
assert closed is False
|
|
assert menu.open_backpack_slot is None
|
|
|
|
|
|
def test_right_click_a_different_backpack_slot_switches_the_popup(registry):
|
|
menu = CharacterMenu()
|
|
character = make_human(
|
|
registry,
|
|
clothing=[ClothingPiece("back", "backpack_basic"), ClothingPiece("torso", "leather_jacket")],
|
|
)
|
|
# leather_jacket grants no inventory, so this is really just proving "back" is what opens
|
|
menu.right_click_equipment_slot("back", character, registry)
|
|
assert menu.open_backpack_slot == "back"
|
|
|
|
|
|
def test_right_click_non_inventory_item_does_not_open_a_popup(registry):
|
|
menu = CharacterMenu()
|
|
character = make_human(registry, clothing=[ClothingPiece("torso", "leather_jacket")])
|
|
opened = menu.right_click_equipment_slot("torso", character, registry)
|
|
assert opened is False
|
|
assert menu.open_backpack_slot is None
|
|
|
|
|
|
def test_right_click_empty_slot_is_a_no_op(registry):
|
|
menu = CharacterMenu()
|
|
character = make_human(registry)
|
|
opened = menu.right_click_equipment_slot("torso", character, registry)
|
|
assert opened is False
|
|
assert menu.open_backpack_slot is None
|
|
|
|
|
|
def test_close_backpack_popup_clears_it():
|
|
menu = CharacterMenu(open_backpack_slot="back")
|
|
menu.close_backpack_popup()
|
|
assert menu.open_backpack_slot is None
|