## Copyright (c) 2022, NVIDIA CORPORATION.  All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto.  Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##
import omni.kit.test
import os
import omni.kit.app
import omni.usd
from omni.kit.test.async_unittest import AsyncTestCase
from omni.kit import ui_test
from pxr import Gf
from omni.kit.test_suite.helpers import open_stage, get_test_data_path, select_prims, wait_stage_loading, arrange_windows


class PropertyPathAddMenu(AsyncTestCase):
    # Before running each test
    async def setUp(self):
        await arrange_windows("Stage", 64)
        await open_stage(get_test_data_path(__name__, "geometry_test.usda"))

    # After running each test
    async def tearDown(self):
        await wait_stage_loading()

    async def test_property_path_rendering(self):
        await ui_test.find("Property").focus()
        usd_context = omni.usd.get_context()
        stage = usd_context.get_stage()

        # select cube
        await select_prims(["/World/Cube"])
        await ui_test.human_delay()

        # verify not set
        prim = stage.GetPrimAtPath("/World/Cube")
        attr = prim.GetAttribute("primvars:wireframe")
        self.assertFalse(attr.IsValid())

        # click "Add"
        add_widget = [w for w in ui_test.find_all("Property//Frame/**/Button[*].identifier==''") if w.widget.text.endswith("Add")][0]
        await add_widget.click()

        # select wireframe
        await ui_test.select_context_menu("Rendering/Set Wireframe Mode")

        # verify set
        self.assertTrue(attr.IsValid())
        self.assertTrue(attr.Get())

        # undo
        omni.kit.undo.undo()

        # verify not set
        self.assertFalse(attr.IsValid())
