## 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.
##
from pathlib import Path

import omni.kit.app
import omni.kit.test
import omni.ui as ui
from omni.ui.tests.test_base import OmniUiTest

CURRENT_PATH = Path(__file__).parent
TEST_DATA_PATH = CURRENT_PATH.parent.parent.parent.parent.parent.joinpath("data").joinpath("tests")

class TestAboutWindow(OmniUiTest):
    # Before running each test
    async def setUp(self):
        await super().setUp()
        self._golden_img_dir = TEST_DATA_PATH.absolute().joinpath("golden_img").absolute()

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

    async def test_about_ui(self):
        class FakePluginImpl():
            def __init__(self, name):
                self.name = name

        class FakePlugin():
            def __init__(self, name):
                self.libPath = "Lib Path " + name
                self.impl = FakePluginImpl("Impl " + name)
                self.interfaces = "Interface " + name

        about = omni.kit.window.about.get_instance()
        about.show(True)
        await omni.kit.app.get_app().next_update_async()
        await omni.kit.app.get_app().next_update_async()
        about._window._widget.app_info = "#App Name# #App Version#"
        about._window._widget.versions = [
            "Omniverse Kit #Version#",
            "Client Library Version: #Client Library Version#",
            "USD Resolver Version: #USD Resolver Version#",
            "USD Version: #USD Version#",
            "MDL SDK Version: #MDL SDK Version#",
        ]
        about._window._widget.plugins = [FakePlugin("Test 1"), FakePlugin("Test 2"), FakePlugin("Test 3"), FakePlugin("Test 4")]
        for _ in range(10):
            await omni.kit.app.get_app().next_update_async()

        await self.docked_test_window(
            window=about._window,
            width=800,
            height=510)

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