## Copyright (c) 2021, 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.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
import pathlib


class TestAudioWidget(OmniUiTest):  # pragma: no cover
    # Before running each test
    async def setUp(self):
        await super().setUp()

        from omni.kit.property.audio.scripts.audio_properties import TEST_DATA_PATH
        self._golden_img_dir = TEST_DATA_PATH.absolute().joinpath("golden_img").absolute()
        self._usd_path = TEST_DATA_PATH.absolute()

        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()

    async def test_sound_ui(self):
        usd_context = omni.usd.get_context()

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

        test_file_path = self._usd_path.joinpath("audio_test.usda").absolute()
        await usd_context.open_stage_async(str(test_file_path))
        await omni.kit.app.get_app().next_update_async()

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

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

        await self.finalize_test(golden_img_dir=self._golden_img_dir, golden_img_name="test_sound_ui.png")

    async def test_listener_ui(self):
        usd_context = omni.usd.get_context()

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

        test_file_path = self._usd_path.joinpath("audio_test.usda").absolute()
        await usd_context.open_stage_async(str(test_file_path))
        await omni.kit.app.get_app().next_update_async()

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

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

        await self.finalize_test(golden_img_dir=self._golden_img_dir, golden_img_name="test_listener_ui.png")
