## 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 pathlib
import omni.kit.app
import omni.kit.commands
import omni.kit.test
import omni.ui as ui
from omni.kit import ui_test
from omni.ui.tests.test_base import OmniUiTest
from pxr import Kind, Sdf, Gf


class TestTaggingWidget(OmniUiTest):
    # Before running each test
    async def setUp(self):
        await super().setUp()

        ext_path = omni.kit.app.get_app().get_extension_manager().get_extension_path_by_module(__name__)
        self._golden_img_dir = pathlib.Path(ext_path).joinpath("data/tests/golden_img")

        from omni.kit.property.usd.usd_attribute_widget import UsdPropertiesWidget
        import omni.kit.window.property as p

        self._w = p.get_window()

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

    # Test(s)
    async def test_tagging_ui(self):
        usd_context = omni.usd.get_context()

        await self.docked_test_window(
            window=self._w._window,
            width=450,
            height=250,
            restore_window = ui.Workspace.get_window("Layer") or ui.Workspace.get_window("Stage"),
            restore_position = ui.DockPosition.BOTTOM)

        # new stage
        await omni.usd.get_context().new_stage_async()
        stage = omni.usd.get_context().get_stage()

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

        # verify one prim
        prim_list = [prim.GetPath().pathString for prim in stage.TraverseAll() if prim.GetPath().pathString not in ['/Render', '/Render/Vars']]
        self.assertTrue(prim_list == ['/Sphere'])

        # Select the prim.
        usd_context.get_selection().set_selected_prim_paths(["/Sphere"], True)

        # Need to wait for an additional frames for omni.ui rebuild to take effect
        await ui_test.human_delay(10)

        # verify image
        await self.finalize_test(golden_img_dir=self._golden_img_dir, golden_img_name="test_tagging_ui.png")
