import asyncio
import carb
import omni.usd
import omni.kit.undo
import omni.ui as ui
from pxr import UsdGeom
from omni.kit import ui_test
from carb.input import KeyboardInput
from omni.kit.menu.utils import MenuItemDescription, MenuLayout


async def verify_menu_item_greyed(tester, menu, state):
    # open/close menu to ensure menu state is correct
    menu_widget = ui_test.get_menubar()
    edit_menu = menu_widget.find_menu("Edit")
    await edit_menu.click()
    await edit_menu.click()

    # contextual menu enable/disable has been temportally removed
    # check state
    # widget = edit_menu.find_menu(menu.name if isinstance(menu, MenuItemDescription) else menu)
    # tester.assertTrue(widget.widget.enabled == state)


async def edit_test_func_edit_instance(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Xform")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/Xform'])

    # verify instance is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is grey with sphere selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Xform'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Instance")

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/Xform', '/Xform_01'])


async def edit_test_hotkey_func_edit_instance(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Xform")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Xform'])

    # select prims
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Xform'], True)
    await ui_test.human_delay()

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Xform', '/Xform_01'])


async def edit_test_func_edit_duplicate(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # verify instance is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Duplicate")

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/Sphere_01'])


async def edit_test_hotkey_func_edit_duplicate(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # select prims
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/Sphere_01'])


async def edit_test_func_edit_duplicate___all_layers(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # verify instance is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Duplicate - All Layers")

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/Sphere_01'])


async def edit_test_func_edit_duplicate___collapsed(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # verify instance is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Duplicate - Collapsed")

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/Sphere_01'])


async def edit_test_func_edit_parent(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Xform")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/Xform'])

    # verify instance is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is grey with sphere selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify parent is enabled with prims selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere', '/Xform'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Parent")

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Xform', '/Xform/Sphere'])


async def edit_test_hotkey_func_edit_parent(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Xform")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/Xform'])

    # select prims
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere', '/Xform'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Xform', '/Xform/Sphere'])


async def edit_test_func_edit_unparent(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    await edit_test_func_edit_parent(tester, "Parent")

    # verify unparent is enabled with prims selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Xform/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Unparent")

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertEqual(set(prim_list), set(['/Sphere', '/Xform']))


async def edit_test_hotkey_func_edit_unparent(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    await edit_test_func_edit_parent(tester, "Parent")

    # verify unparent is enabled with prims selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Xform/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertEqual(set(prim_list), set(['/Sphere', '/Xform']))


async def edit_test_func_edit_group(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # verify group is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify group is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Group")

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Group', '/Group/Sphere'])

    # verify you cannot group DefaultPrim
    omni.kit.undo.undo()
    await ui_test.human_delay()

    ## create default prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_path="/World", prim_type="Scope")
    await ui_test.human_delay()
    prim = stage.GetPrimAtPath("/World")
    stage.SetDefaultPrim(prim)

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/World'])

    # group prims
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere', '/World'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)
    await ui_test.menu_click("Edit/Group")

    # verify prims were not grouped
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/World'])


async def edit_test_hotkey_func_edit_group(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # select prims
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Group', '/Group/Sphere'])

    # verify you cannot group DefaultPrim
    omni.kit.undo.undo()
    await ui_test.human_delay()

    ## create default prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_path="/World", prim_type="Scope")
    await ui_test.human_delay()
    prim = stage.GetPrimAtPath("/World")
    stage.SetDefaultPrim(prim)

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/World'])

    # group prims
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere', '/World'], True)
    await ui_test.human_delay()

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    # verify prims were not grouped
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/World'])


async def edit_test_func_edit_ungroup(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertEqual(prim_list, [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertEqual(prim_list, ['/Sphere'])

    # verify ungroup is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify group is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Group")

    # verify prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Group', '/Group/Sphere'])

    # verify ungroup is enabled with sphere selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Group/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # ungroup prims
    await verify_menu_item_greyed(tester, menu_item, True)
    await ui_test.menu_click("Edit/Ungroup")

    # verify prim are ungrouped
    prim_list = tester.get_stage_prims()
    tester.assertEqual(prim_list, ['/Sphere'])


async def edit_test_func_edit_toggle_visibility(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # verify instance is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # verify prim inherited
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Sphere")).ComputeVisibility() == UsdGeom.Tokens.inherited)

    # use menu
    await ui_test.menu_click("Edit/Toggle Visibility")

    # verify prim invisible
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Sphere")).ComputeVisibility() == UsdGeom.Tokens.invisible)

    # use menu
    await ui_test.menu_click("Edit/Toggle Visibility")

    # verify prim inherited
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Sphere")).ComputeVisibility() == UsdGeom.Tokens.inherited)


async def edit_test_hotkey_func_edit_toggle_visibility(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # select prim
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()

    # verify prim inherited
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Sphere")).ComputeVisibility() == UsdGeom.Tokens.inherited)

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    # verify prim invisible
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Sphere")).ComputeVisibility() == UsdGeom.Tokens.invisible)

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    # verify prim inherited
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Sphere")).ComputeVisibility() == UsdGeom.Tokens.inherited)


async def edit_test_func_edit_delete(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # verify instance is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Delete")

    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])


async def edit_test_func_edit_delete___all_layers(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # verify instance is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Delete - All Layers")

    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])


async def edit_test_hotkey_func_edit_delete(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # selected prim
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])


async def edit_test_func_edit_rename(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # verify instance is grey with nothing selected
    omni.usd.get_context().get_selection().set_selected_prim_paths([], True)
    await verify_menu_item_greyed(tester, menu_item, False)

    # verify instance is enabled with xform selected
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)
    await ui_test.human_delay()
    await verify_menu_item_greyed(tester, menu_item, True)

    # use menu
    await ui_test.menu_click("Edit/Rename")

    await ui_test.human_delay()
    widget = ui_test.find("Rename Sphere###context_menu_rename//Frame/**/StringField[*]")
    await widget.click(double=True)
    await ui_test.human_delay()
    await ui_test.emulate_keyboard_press(KeyboardInput.DEL)
    await ui_test.human_delay()
    await ui_test.emulate_char_press("MyPrim")
    await ui_test.human_delay()
    await ui_test.emulate_keyboard_press(KeyboardInput.ENTER)
    await ui_test.human_delay()

    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/MyPrim'])

    # again with bad characters
    await ui_test.menu_click("Edit/Rename")

    await ui_test.human_delay()
    widget = ui_test.find("Rename Sphere###context_menu_rename//Frame/**/StringField[*]")
    await widget.click(double=True)
    await ui_test.human_delay()
    await ui_test.emulate_keyboard_press(KeyboardInput.DEL)
    await ui_test.human_delay()
    await ui_test.emulate_char_press("MyPrim@@@xx/1")
    await ui_test.human_delay()
    await ui_test.emulate_keyboard_press(KeyboardInput.ENTER)
    await ui_test.human_delay()

    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/MyPrim___xx_1'])


async def edit_test_hotkey_func_edit_rename(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere'])

    # select prim
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Sphere'], True)

    # hotkey
    await ui_test.emulate_keyboard_press(menu_item.hotkey[1], menu_item.hotkey[0])

    await ui_test.human_delay()
    widget = ui_test.find("Rename Sphere###context_menu_rename//Frame/**/StringField[*]")
    await widget.click(double=True)
    await ui_test.human_delay()
    await ui_test.emulate_keyboard_press(KeyboardInput.DEL)
    await ui_test.human_delay()
    await ui_test.emulate_char_press("MyPrim")
    await ui_test.human_delay()
    await ui_test.emulate_keyboard_press(KeyboardInput.ENTER)
    await ui_test.human_delay()

    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/MyPrim'])


async def edit_test_func_edit_hide_unselected(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    # verify no prims
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == [])

    ## create prim
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Sphere")
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Cube")
    omni.kit.commands.execute("CreatePrimWithDefaultXform", prim_type="Xform")
    await ui_test.human_delay()

    # verify prims were created
    prim_list = tester.get_stage_prims()
    tester.assertTrue(prim_list == ['/Sphere', '/Cube', '/Xform'])

    # verify prim invisible
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Sphere")).ComputeVisibility() == UsdGeom.Tokens.inherited)
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Cube")).ComputeVisibility() == UsdGeom.Tokens.inherited)
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Xform")).ComputeVisibility() == UsdGeom.Tokens.inherited)

    # select prims
    omni.usd.get_context().get_selection().set_selected_prim_paths(['/Cube'], True)

    # use menu
    await ui_test.menu_click("Edit/Hide Unselected")

    # verify prims
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Sphere")).ComputeVisibility() == UsdGeom.Tokens.invisible)
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Cube")).ComputeVisibility() == UsdGeom.Tokens.inherited)
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Xform")).ComputeVisibility() == UsdGeom.Tokens.invisible)


async def edit_test_func_edit_unhide_all(tester, menu_item: MenuItemDescription):
    stage =  omni.usd.get_context().get_stage()

    await edit_test_func_edit_hide_unselected(tester, None)

    # use menu
    await ui_test.menu_click("Edit/Unhide All")

    # verify prims
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Sphere")).ComputeVisibility() == UsdGeom.Tokens.inherited)
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Cube")).ComputeVisibility() == UsdGeom.Tokens.inherited)
    tester.assertTrue(UsdGeom.Imageable(stage.GetPrimAtPath("/Xform")).ComputeVisibility() == UsdGeom.Tokens.inherited)
