## Copyright (c) 2018-2022, 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
import carb
import asyncio


class TestStatusBar(OmniUiTest):
    # Before running each test
    async def setUp(self):
        self.name_progress = carb.events.type_from_string("omni.kit.window.status_bar@progress")
        self.name_activity = carb.events.type_from_string("omni.kit.window.status_bar@activity")
        self.message_bus = omni.kit.app.get_app().get_message_bus_event_stream()
        self.message_bus.push(self.name_activity, payload={"text": ""})
        self.message_bus.push(self.name_progress, payload={"progress": "-1"})

    # After running each test
    async def tearDown(self):
        pass

    async def test_general(self):
        await self.create_test_area(256, 64)

        async def log():
            # Delayed log because self.finalize_test logs things
            carb.log_warn("StatusBar test")

        asyncio.ensure_future(log())

        await self.finalize_test()

    async def test_activity(self):
        await self.create_test_area(512, 64)

        async def log():
            # Delayed log because self.finalize_test logs things
            carb.log_warn("StatusBar test")

        # Test activity name with spaces URL-encoded
        self.message_bus.push(self.name_activity, payload={"text": "MFC%20For%20NvidiaAnimated.usd"})
        self.message_bus.push(self.name_progress, payload={"progress": "0.2"})
        asyncio.ensure_future(log())

        await self.finalize_test()
