import asyncio
from pathlib import Path

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

from ..extension import OpenPageExtension

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


class TestPage(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_page(self):
        window = await self.create_test_window(width=800, height=800)
        with window.frame:
            ext = OpenPageExtension()
            ext.on_startup("omni.kit.welcome.open-1.1.0")
            ext.build_ui()

        await omni.kit.app.get_app().next_update_async()
        # OM-92413: Wait for icons loaded
        await asyncio.sleep(8)
        await self.finalize_test(golden_img_dir=self._golden_img_dir, golden_img_name="page.png")
