Пример #1
0
        public IEnumerator ExpandCollapseCategoryTests()
        {
            Assert.IsNotNull(m_BlackboardTestController.addBlackboardItemsMenu, "Blackboard Add Items menu reference owned by BlackboardTestController is null.");

            CreateBlackboardCategory(m_BlackboardTestController);
            yield return(null);

            var categories = m_BlackboardTestController.blackboard.Query <SGBlackboardCategory>().ToList();

            if (categories != null)
            {
                var newCategory = categories[1];
                if (newCategory == null)
                {
                    Assert.Fail("Failed to create Category during RenameCategoryTests");
                }

                var categoryClickOffset = new Vector2(10, 10);
                // Trigger category collapse
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, newCategory, EventType.MouseDown, positionOffset: categoryClickOffset);
                yield return(null);

                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, newCategory, EventType.MouseUp, positionOffset: categoryClickOffset);
                Assert.IsTrue(newCategory.viewModel.isExpanded == false, "Failed to collapse blackboard category");

                // Trigger category expand
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, newCategory, EventType.MouseDown, positionOffset: categoryClickOffset);
                yield return(null);

                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, newCategory, EventType.MouseUp, positionOffset: categoryClickOffset);
                Assert.IsTrue(newCategory.viewModel.isExpanded, "Failed to collapse blackboard category");
            }

            m_BlackboardTestController.ResetBlackboardState();
        }
Пример #2
0
        public IEnumerator DeleteCategoryTests()
        {
            Assert.IsNotNull(m_BlackboardTestController.addBlackboardItemsMenu, "Blackboard Add Items menu reference owned by BlackboardTestController is null.");

            CreateBlackboardCategory(m_BlackboardTestController);
            yield return(null);

            var categories = m_BlackboardTestController.blackboard.Query <SGBlackboardCategory>().ToList();

            if (categories != null)
            {
                var newCategory = categories[1];
                if (newCategory == null)
                {
                    Assert.Fail("Failed to create Category during DuplicateCategoryTests");
                }

                // Select the new category
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, newCategory, EventType.MouseDown, positionOffset: new Vector2(40, 10));
                // Wait a frame
                yield return(null);

                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, newCategory, EventType.MouseUp, positionOffset: new Vector2(40, 10));
                yield return(null);

                // Then send delete command
                ShaderGraphUITestHelpers.SendDeleteCommand(m_Window, newCategory);
                yield return(null);

                Assert.IsTrue(m_BlackboardTestController.blackboard.Query <SGBlackboardCategory>().ToEnumerable().Count() == 1, "Failed to delete blackboard category view");
            }

            m_BlackboardTestController.ResetBlackboardState();
        }
Пример #3
0
        public IEnumerator RemoveInputTests()
        {
            Assert.IsNotNull(m_BlackboardTestController.addBlackboardItemsMenu, "Blackboard Add Items menu reference owned by BlackboardTestController is null.");

            var menuItems = m_BlackboardTestController.addBlackboardItemsMenu.GetPrivateProperty <IList>("menuItems");

            Assert.IsNotNull(menuItems, "Could not retrieve reference to the menu items of the Blackboard Add Items menu");

            // invoke all menu items on the "add Blackboard Items Menu" to add all property types
            foreach (var item in menuItems)
            {
                var menuFunction = item.GetNonPrivateField <GenericMenu.MenuFunction>("func");
                menuFunction?.Invoke();
                yield return(null);
            }

            var cachedPropertyList = m_Window.graphObject.graph.properties.ToList();

            foreach (var property in cachedPropertyList)
            {
                var blackboardRow = m_BlackboardTestController.GetBlackboardRow(property);
                Assert.IsNotNull(blackboardRow, "No blackboard row found associated with blackboard property.");
                var blackboardPropertyView = blackboardRow.Q <SGBlackboardField>();
                Assert.IsNotNull(blackboardPropertyView, "No blackboard property view found in the blackboard row.");
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, blackboardPropertyView, EventType.MouseDown, MouseButton.LeftMouse, 1, EventModifiers.None, new Vector2(5, 1));
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, blackboardPropertyView, EventType.MouseUp, MouseButton.LeftMouse, 1, EventModifiers.None, new Vector2(5, 1));
                yield return(null);

                ShaderGraphUITestHelpers.SendDeleteCommand(m_Window, m_GraphEditorView.graphView);
                yield return(null);
            }

            var cachedKeywordList = m_Window.graphObject.graph.keywords.ToList();

            foreach (var keyword in cachedKeywordList)
            {
                var blackboardRow = m_BlackboardTestController.GetBlackboardRow(keyword);
                Assert.IsNotNull(blackboardRow, "No blackboard row found associated with blackboard keyword.");
                var blackboardPropertyView = blackboardRow.Q <SGBlackboardField>();
                Assert.IsNotNull(blackboardPropertyView, "No blackboard property view found in the blackboard row.");
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, blackboardPropertyView, EventType.MouseDown, MouseButton.LeftMouse, 1, EventModifiers.None, new Vector2(5, 1));
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, blackboardPropertyView, EventType.MouseUp, MouseButton.LeftMouse, 1, EventModifiers.None, new Vector2(5, 1));
                yield return(null);

                ShaderGraphUITestHelpers.SendDeleteCommand(m_Window, m_GraphEditorView.graphView);
                yield return(null);
            }


            yield return(null);
        }
Пример #4
0
        public IEnumerator ResetPropertyReference()
        {
            var fieldViewElements = m_GraphEditorView.Query("blackboardFieldView");

            foreach (var visualElement in fieldViewElements.ToList())
            {
                var blackboardPropertyView = (SGBlackboardField)visualElement;
                if (blackboardPropertyView == null)
                {
                    continue;
                }

                var shaderInput           = (AbstractShaderProperty)blackboardPropertyView.shaderInput;
                var originalReferenceName = shaderInput.referenceName;
                var propertyType          = shaderInput.GetPropertyTypeString();
                var modifiedReferenceName = $"{propertyType}_Test";
                shaderInput.SetReferenceNameAndSanitizeForGraph(m_Graph, modifiedReferenceName);

                Assert.IsTrue(shaderInput.referenceName != originalReferenceName);
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, blackboardPropertyView, EventType.MouseDown);

                // Needed so that the inspector gets triggered and the callbacks and triggers are initialized
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, blackboardPropertyView, EventType.MouseDown);

                // Wait a frame for the inspector updates to trigger
                yield return(null);

                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, blackboardPropertyView, EventType.MouseUp);

                // Wait a frame for the inspector updates to trigger
                yield return(null);

                // Cannot actually spawn the right click menu for testing due to ContextMenuManipulators spawning
                // an OS level menu that steals focus from Editor and preventing any future events from being processed
                // Instead, we trigger the action directly from code, for now...
                shaderInput.ResetReferenceName(m_Graph);

                if (shaderInput.referenceName != originalReferenceName)
                {
                    Assert.Fail("Failed to reset reference name to original value.");
                }
            }
        }
Пример #5
0
        public IEnumerator RenameCategoryTests()
        {
            Assert.IsNotNull(m_BlackboardTestController.addBlackboardItemsMenu, "Blackboard Add Items menu reference owned by BlackboardTestController is null.");

            CreateBlackboardCategory(m_BlackboardTestController);
            yield return(null);

            var categories = m_BlackboardTestController.blackboard.Query <SGBlackboardCategory>().ToList();

            if (categories != null)
            {
                var newCategory = categories[1];
                if (newCategory == null)
                {
                    Assert.Fail("Failed to create Category during RenameCategoryTests");
                }

                var categoryClickOffset = new Vector2(40, 10);
                // Trigger category rename
                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, newCategory, EventType.MouseDown, positionOffset: categoryClickOffset, clickCount: 2);
                yield return(null);

                ShaderGraphUITestHelpers.SendMouseEvent(m_Window, newCategory, EventType.MouseUp, positionOffset: categoryClickOffset);

                // Send the test rename input
                ShaderGraphUITestHelpers.SendKeyEvent(m_Window, newCategory.textField, keyboardCharacter: 'T', keyCode: KeyCode.T);
                ShaderGraphUITestHelpers.SendKeyEvent(m_Window, newCategory.textField, keyboardCharacter: 'e', keyCode: KeyCode.E);
                ShaderGraphUITestHelpers.SendKeyEvent(m_Window, newCategory.textField, keyboardCharacter: 's', keyCode: KeyCode.S);
                ShaderGraphUITestHelpers.SendKeyEvent(m_Window, newCategory.textField, keyboardCharacter: 't', keyCode: KeyCode.T);

                // Confirm the change to the text field
                ShaderGraphUITestHelpers.SendKeyEvent(m_Window, newCategory.textField, keyboardCharacter: '\n', keyCode: KeyCode.Return);
                yield return(null);

                Assert.IsTrue(newCategory.title == "Test", "Failed to rename blackboard category");
            }

            m_BlackboardTestController.ResetBlackboardState();
        }