## 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
import omni.client

from omni.kit.test.async_unittest import AsyncTestCase
from omni.kit import ui_test
from omni.kit.test_suite.helpers import get_test_data_path, arrange_windows

from omni.kit.window.content_browser.test_helper import ContentBrowserTestHelper


class HardRangeUI(AsyncTestCase):
    # Before running each test
    async def setUp(self):
        await arrange_windows("Stage", 64)

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

    async def test_fileinfo_ui(self):
        await ui_test.find("Content").focus()
        await ui_test.find("Property").focus()

        # select file to show info
        dir_url = get_test_data_path(__name__, "..")
        async with ContentBrowserTestHelper() as content_browser_helper:
            await content_browser_helper.select_items_async(dir_url, names=["icon.png"])
            await ui_test.human_delay(4)

        # get file info
        file_path = f"{dir_url}/icon.png"
        result, entry = await omni.client.stat_async(str(file_path))
        self.assertEqual(result, omni.client.Result.OK)
        self.assertTrue(entry != None)

        # get file strings
        created_by = entry.created_by
        created_time = entry.created_time.strftime("%x %X")
        modified_by = entry.modified_by
        modified_time = entry.modified_time.strftime("%x %X")
        file_size = f"{entry.size:,} " + ("Bytes" if entry.size > 1 else "Byte")

        # verify ui strings
        # widget = ui_test.find("Property//Frame/**/StringField[*].identifier=='created_time'")
        # self.assertEqual(widget.model.get_value_as_string(), created_time)

        widget = ui_test.find("Property//Frame/**/StringField[*].identifier=='created_by'")
        self.assertEqual(widget.model.get_value_as_string(), created_by)

        # widget = ui_test.find("Property//Frame/**/StringField[*].identifier=='modified_time'")
        # self.assertEqual(widget.model.get_value_as_string(), modified_time)

        widget = ui_test.find("Property//Frame/**/StringField[*].identifier=='modified_by'")
        self.assertEqual(widget.model.get_value_as_string(), modified_by)

        widget = ui_test.find("Property//Frame/**/StringField[*].identifier=='file_size'")
        self.assertEqual(widget.model.get_value_as_string(), file_size)
