# Copyright (c) 2019-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.
#
__all__ = ["TestDocumentation"]

import pathlib

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

from ..documentation_md import DocumentationBuilderMd

EXTENSION_FOLDER_PATH = pathlib.Path(
    omni.kit.app.get_app().get_extension_manager().get_extension_path_by_module(__name__)
)
TESTS_PATH = EXTENSION_FOLDER_PATH.joinpath("data/tests")


class TestDocumentation(OmniUiTest):
    async def test_builder(self):
        builder = DocumentationBuilderMd(f"{TESTS_PATH}/test.md")

        self.assertEqual(
            builder.catalog,
            [{"name": "NVIDIA", "children": [{"name": "Omiverse", "children": [{"name": "Doc", "children": []}]}]}],
        )
        self.assertEqual(builder.blocks[0].text, "NVIDIA")
        self.assertEqual(builder.blocks[0].block_type.name, "H1")
        self.assertEqual(builder.blocks[1].text, "Omiverse")
        self.assertEqual(builder.blocks[1].block_type.name, "H2")
        self.assertEqual(builder.blocks[2].text, "Doc")
        self.assertEqual(builder.blocks[2].block_type.name, "H3")

        self.assertEqual(builder.blocks[3].text, "Text")
        self.assertEqual(builder.blocks[3].block_type.name, "PARAGRAPH")

        clean = builder.get_clean_code(builder.blocks[4])
        self.assertEqual(clean, 'ui.Label("Hello")')
        self.assertEqual(builder.blocks[4].block_type.name, "CODE")

        self.assertEqual(builder.blocks[5].text, ("- List1", "- List2"))
        self.assertEqual(builder.blocks[5].block_type.name, "LIST")

        self.assertEqual(builder.blocks[6].text, ("- [YOUTUBE](https://www.youtube.com)",))
        self.assertEqual(builder.blocks[6].block_type.name, "LINK_IN_LIST")

        self.assertEqual(builder.blocks[7].text, "[NVIDIA](https://www.nvidia.com)")
        self.assertEqual(builder.blocks[7].block_type.name, "LINK")

        self.assertEqual(
            builder.blocks[8].text, ("| Noun | Adjective |", "| ---- | --------- |", "| Omniverse | Awesome |")
        )
        self.assertEqual(builder.blocks[8].block_type.name, "TABLE")

        builder.destroy()
