## 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.test
from ..stageviewer import StageViewer
from ..content_menu import ContentMenu
from omni.ui.tests.test_base import OmniUiTest
from pathlib import Path
from pxr import Usd
from pxr import UsdGeom
import omni.kit.app
import omni.kit.commands
import omni.ui as ui
import omni.usd

CURRENT_PATH = Path(__file__).parent.joinpath("../../../../../data")


class TestStageviewer(OmniUiTest):
    # Before running each test
    async def setUp(self):
        await super().setUp()
        self._golden_img_dir = CURRENT_PATH.absolute().resolve().joinpath("tests")

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

    async def test_general(self):
        # New stage with a sphere
        stage = Usd.Stage.CreateInMemory("test.usda")
        UsdGeom.Sphere.Define(stage, "/Sphere")

        window = await self.create_test_window()

        stageviewer = StageViewer(stage)
        stageviewer.flags = ui.WINDOW_FLAGS_NO_SCROLLBAR | ui.WINDOW_FLAGS_NO_TITLE_BAR | ui.WINDOW_FLAGS_NO_RESIZE
        stageviewer.position_x = 0
        stageviewer.position_y = 0
        stageviewer.width = 256
        stageviewer.height = 256

        for _ in range(2):
            await omni.kit.app.get_app().next_update_async()

        await self.finalize_test(golden_img_dir=self._golden_img_dir)

        stageviewer.destroy()

    async def test_context_menu(self):
        """This is to test that the content menu is shown when it is a usd file"""
        context_menu = ContentMenu()
        for _ in range(2):
            await omni.kit.app.get_app().next_update_async()
        file_name = f"{self._golden_img_dir}/empty.usd".replace("\\", "/")
        result = context_menu._is_show_visible(file_name)
        self.assertTrue(result, True)
        context_menu.destroy()
