## Copyright (c) 2018-2019, 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.kit.widget.graph.graph_node_delegate import GraphNodeDelegate
from omni.kit.widget.graph.graph_view import GraphView
from omni.ui.tests.test_base import OmniUiTest
from .test_graph import Model
import omni.kit.app


class TestDelegate(OmniUiTest):
    async def test_general(self):
        """Testing general properties of the GraphView default delegate"""
        window = await self.create_test_window(768, 512)

        style = GraphNodeDelegate.get_style()
        # Don't use the image because the image scaling looks different in editor and kit-mini
        style["Graph.Node.Footer.Image"]["image_url"] = ""
        style["Graph.Node.Header.Collapse"]["image_url"] = ""
        style["Graph.Node.Header.Collapse::Minimized"]["image_url"] = ""
        style["Graph.Node.Header.Collapse::Closed"]["image_url"] = ""

        with window.frame:
            delegate = GraphNodeDelegate()
            model = Model()
            graph_view = GraphView(model=model, delegate=delegate, style=style, pan_x=600, pan_y=170)

        # Two frames because the first frame is to draw, the second frame is to auto-layout.
        for i in range(3):
            await omni.kit.app.get_app().next_update_async()

        await self.finalize_test()

    async def test_zoom(self):
        """Testing zooming of the GraphView default delegate"""
        window = await self.create_test_window(384, 256)

        style = GraphNodeDelegate.get_style()
        # Don't use the image because the image scaling looks different in editor and kit-mini
        style["Graph.Node.Footer.Image"]["image_url"] = ""
        style["Graph.Node.Header.Collapse"]["image_url"] = ""
        style["Graph.Node.Header.Collapse::Minimized"]["image_url"] = ""
        style["Graph.Node.Header.Collapse::Closed"]["image_url"] = ""

        with window.frame:
            delegate = GraphNodeDelegate()
            model = Model()
            graph_view = GraphView(model=model, delegate=delegate, style=style, zoom=0.5, pan_x=300, pan_y=85)

        # Two frames because the first frame is to draw, the second frame is to auto-layout.
        for i in range(3):
            await omni.kit.app.get_app().next_update_async()

        await self.finalize_test()

    async def test_focus(self):
        """Testing focusing of the GraphView default delegate"""
        window = await self.create_test_window(768, 512)

        style = GraphNodeDelegate.get_style()
        # Don't use the image because the image scaling looks different in editor and kit-mini
        style["Graph.Node.Footer.Image"]["image_url"] = ""
        style["Graph.Node.Header.Collapse"]["image_url"] = ""
        style["Graph.Node.Header.Collapse::Minimized"]["image_url"] = ""
        style["Graph.Node.Header.Collapse::Closed"]["image_url"] = ""

        with window.frame:
            delegate = GraphNodeDelegate()
            model = Model()
            graph_view = GraphView(model=model, delegate=delegate, style=style)

        # Two frames because the first frame is to draw, the second frame is to auto-layout.
        for i in range(3):
            await omni.kit.app.get_app().next_update_async()

        graph_view.focus_on_nodes()

        for i in range(2):
            await omni.kit.app.get_app().next_update_async()

        await self.finalize_test()
