# 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

from omni.ui.tests.test_base import OmniUiTest

import omni.kit
import omni.ui as ui

from ..imageviewer import ViewerWindows


class TestImageViewer(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):
        self._golden_img_dir = None
        await super().tearDown()

    async def test_general(self):
        window = await self.create_test_window()  # noqa: PLW0612, F841

        await omni.kit.app.get_app().next_update_async()

        viewer = ViewerWindows().open_window(f"{self._golden_img_dir.joinpath('lenna.png')}")
        viewer.flags = ui.WINDOW_FLAGS_NO_SCROLLBAR | ui.WINDOW_FLAGS_NO_TITLE_BAR | ui.WINDOW_FLAGS_NO_RESIZE
        viewer.position_x = 0
        viewer.position_y = 0
        viewer.width = 256
        viewer.height = 256

        # One frame to show the window and another to build the frame
        # And a dozen frames more to let the asset load
        for _ in range(20):
            await omni.kit.app.get_app().next_update_async()

        await self.finalize_test(golden_img_dir=self._golden_img_dir)
