from pathlib import Path
import unittest
import carb
import omni.kit.test
import omni.ui as ui
from omni.kit import ui_test
from omni.kit.menu.utils import MenuItemDescription, MenuLayout
from omni.ui.tests.test_base import OmniUiTest
from omni.kit.test_suite.helpers import get_test_data_path


class TestMenuIcon(OmniUiTest):
    async def setUp(self):
        pass

    async def tearDown(self):
        pass

    async def test_menu_icon(self):
        icon_path = Path(omni.kit.app.get_app().get_extension_manager().get_extension_path_by_module(__name__)).joinpath("data/tests/icons/audio_record.svg")
        golden_img_dir = Path(get_test_data_path(__name__, "golden_img"))

        submenu_list = [ MenuItemDescription(name="Menu Item", glyph=str(icon_path)) ]
        menu_list =    [ MenuItemDescription(name="Icon Menu Test", glyph=str(icon_path), sub_menu=submenu_list) ]
        omni.kit.menu.utils.add_menu_items(menu_list, "Icon Test", 99)
        omni.kit.menu.utils.rebuild_menus()
        await ui_test.human_delay(50)

        await ui_test.menu_click("Icon Test/Icon Menu Test", human_delay_speed=4)
        await ui_test.human_delay(10)

        await self.finalize_test(golden_img_dir=golden_img_dir, golden_img_name="test_menu_icon.png", hide_menu_bar=False)
        await ui_test.human_delay(50)

        omni.kit.menu.utils.remove_menu_items(menu_list, "Icon Test")
        self.assertTrue(omni.kit.menu.utils.get_merged_menus() == {})
