## 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 omni.ui.tests.test_base import OmniUiTest
from omni.kit.window.console import ConsoleWidget
from pathlib import Path
import omni.kit.app
import omni.kit.ui_test as ui_test


class TestConsoleWindow(OmniUiTest):
    # Before running each test
    async def setUp(self):
        await super().setUp()
        extension_path = omni.kit.app.get_app().get_extension_manager().get_extension_path_by_module(__name__)
        self._golden_img_dir = Path(extension_path).joinpath("data").joinpath("tests").absolute()

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

    async def test_console(self):
        window = await self.create_test_window(1000, 600)

        with window.frame:
            console_widget = ConsoleWidget()
            console_widget.exec_command("clear")
        console_window = ui_test.find("Console")
        console_window._widget._console_widget.exec_command("clear")

        for i in range(5):
            await omni.kit.app.get_app().next_update_async()

        await self.finalize_test(golden_img_dir=self._golden_img_dir, golden_img_name="test_console.png", use_log=False)

        console_widget.visible =False
        console_widget.destroy()
        console_window._widget.visible =False
        console_window._widget.destroy()
