示例#1
0
            public static EventBase MakeEvent(EventType type, KeyCode code, EventModifiers modifiers = EventModifiers.None)
            {
                var evt = new Event {
                    type = type, keyCode = code, character = '\0', modifiers = modifiers
                };

                return(UIETestEvents.MakeEvent(evt));
            }
        public IEnumerator StandardShortCuts()
        {
            yield return(AddVisualElement());

            var explorerItems = BuilderTestsHelper.GetExplorerItems(hierarchy);

            Assert.That(explorerItems.Count, Is.EqualTo(1));
            yield return(UIETestEvents.Mouse.SimulateClick(explorerItems[0]));

            // Rename
            const string renameString = "renameString";

            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Rename));

            yield return(UIETestEvents.KeyBoard.SimulateTyping(builder, renameString));

            yield return(UIETestEvents.Mouse.SimulateClick(viewport));

            explorerItems = BuilderTestsHelper.GetExplorerItems(hierarchy);
            var explorerItemLabel = explorerItems[0].Q <Label>();

            Assert.That(explorerItemLabel.text, Is.EqualTo("#" + renameString));

            yield return(UIETestEvents.Mouse.SimulateClick(explorerItems[0]));

            // Duplicate
            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Duplicate));

            explorerItems = BuilderTestsHelper.GetExplorerItems(hierarchy);
            Assert.That(explorerItems.Count, Is.EqualTo(2));

            // Copy/Paste
            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Copy));

            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Paste));

            explorerItems = BuilderTestsHelper.GetExplorerItems(hierarchy);
            Assert.That(explorerItems.Count, Is.EqualTo(3));

            // Delete
            yield return(UIETestEvents.KeyBoard.SimulateKeyDown(builder, KeyCode.Delete));

            explorerItems = BuilderTestsHelper.GetExplorerItems(hierarchy);
            Assert.That(explorerItems.Count, Is.EqualTo(2));

            // Pasted as children of the parent of the currently selected element.

            AddElementCodeOnly <TextField>();
            var textField = viewport.documentRootElement.Q <TextField>();

            Assert.That(textField.childCount, Is.EqualTo(2));

            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Paste));

            Assert.That(textField.childCount, Is.EqualTo(2));
        }
        public IEnumerator CopyPasteUXML()
        {
            AddElementCodeOnly();
            AddElementCodeOnly();
            yield return(UIETestHelpers.Pause());

            var hierarchyItems = BuilderTestsHelper.GetExplorerItemsWithName(hierarchy, nameof(VisualElement));
            var hierarchyItem1 = hierarchyItems[0];
            var hierarchyItem2 = hierarchyItems[1];

            yield return(UIETestEvents.Mouse.SimulateDragAndDrop(builder,
                                                                 hierarchyItem1.worldBound.center,
                                                                 hierarchyItem2.worldBound.center));

            var complexItem = GetFirstExplorerItem();

            var newlineFixedExpectedUXML = m_ExpectedUXMLString;

            if (BuilderConstants.NewlineChar != BuilderConstants.newlineCharFromEditorSettings)
            {
                newlineFixedExpectedUXML = newlineFixedExpectedUXML.Replace(
                    BuilderConstants.NewlineChar,
                    BuilderConstants.newlineCharFromEditorSettings);
            }

            // Copy to UXML
            yield return(UIETestEvents.Mouse.SimulateClick(complexItem));

            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Copy));

            Assert.That(BuilderEditorUtility.systemCopyBuffer, Is.EqualTo(newlineFixedExpectedUXML));

            ForceNewDocument();
            BuilderEditorUtility.systemCopyBuffer = string.Empty;
            yield return(UIETestEvents.Mouse.SimulateClick(hierarchy));

            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Paste));

            var explorerItems = BuilderTestsHelper.GetExplorerItems(hierarchy);

            Assert.That(explorerItems, Is.Empty);

            BuilderEditorUtility.systemCopyBuffer = newlineFixedExpectedUXML;
            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Paste));

            // var newItem = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(VisualElement));
            var hierarchyTreeView = hierarchy.Q <TreeView>();

            hierarchyTreeView.ExpandItem(hierarchyTreeView.items.ToList()[1].id);

            explorerItems = BuilderTestsHelper.GetExplorerItems(hierarchy);
            Assert.That(explorerItems.Count, Is.EqualTo(2));
            Assert.That(BuilderTestsHelper.GetLinkedDocumentElement(explorerItems[1]).parent, Is.EqualTo(BuilderTestsHelper.GetLinkedDocumentElement(explorerItems[0])));
        }
        public IEnumerator SelectorToAndFromUSSConversion()
        {
            // Create and new selector and select
            yield return(AddSelector(TestSelectorName));

            var selector = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, TestSelectorName);

            yield return(UIETestEvents.Mouse.SimulateClick(selector));

            // Set style
            var displayFoldout = InspectorPane.Query <PersistedFoldout>().Where(f => f.text.Equals("Display")).First();

            displayFoldout.value = true;

            var displayStrip = displayFoldout.Query <ToggleButtonStrip>().Where(t => t.label.Equals("Display")).First();

            yield return(UIETestEvents.Mouse.SimulateClick(displayStrip.Q <Button>("flex")));

            var visibilityStrip = displayFoldout.Query <ToggleButtonStrip>().Where(t => t.label.Equals("Visibility")).First();

            yield return(UIETestEvents.Mouse.SimulateClick(visibilityStrip.Q <Button>("hidden")));

            // Copy to USS
            yield return(UIETestEvents.Mouse.SimulateClick(selector));

            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Copy));

            Assert.That(BuilderEditorUtility.SystemCopyBuffer, Is.EqualTo(m_ExpectedSelectorString));

            // Paste from USS
            ForceNewDocument();
            BuilderEditorUtility.SystemCopyBuffer = string.Empty;
            yield return(UIETestEvents.Mouse.SimulateClick(StyleSheetsPane));

            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Paste));

            var explorerItems = BuilderTestsHelper.GetExplorerItemsWithName(StyleSheetsPane, TestSelectorName);

            Assert.That(explorerItems.Count, Is.EqualTo(0));

            BuilderEditorUtility.SystemCopyBuffer = m_ExpectedSelectorString;
            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Paste));

            explorerItems = BuilderTestsHelper.GetExplorerItemsWithName(StyleSheetsPane, TestSelectorName);
            Assert.That(explorerItems.Count, Is.EqualTo(1));

            // Foldout out state should be persisted, so we assume it is open already.
            displayFoldout = InspectorPane.Query <PersistedFoldout>().Where(f => f.text.Equals("Display")).First();
            displayStrip   = displayFoldout.Query <ToggleButtonStrip>().Where(t => t.label.Equals("Display")).First();
            Assert.True(displayStrip.Q <Button>("flex").pseudoStates.HasFlag(PseudoStates.Checked));

            visibilityStrip = displayFoldout.Query <ToggleButtonStrip>().Where(t => t.label.Equals("Visibility")).First();
            Assert.True(visibilityStrip.Q <Button>("hidden").pseudoStates.HasFlag(PseudoStates.Checked));
        }
示例#5
0
            public static EventBase SimulateScroll(Vector2 delta, Vector2 position)
            {
                var evt = new Event
                {
                    type          = EventType.ScrollWheel,
                    delta         = delta,
                    mousePosition = position
                };

                return(UIETestEvents.MakeEvent(evt));
            }
示例#6
0
            public static IEnumerator SimulateScroll(Vector2 delta, Vector2 position)
            {
                var evt = new Event
                {
                    type          = EventType.ScrollWheel,
                    delta         = delta,
                    mousePosition = position
                };

                UIETestEvents.MakeEvent(evt);
                yield return(UIETestHelpers.Pause());
            }
示例#7
0
        public IEnumerator SelectorToAndFromUSSConversion()
        {
            yield return EnsureSelectorsCanBeAddedAndReloadBuilder();

            // Create and new selector and select
            yield return AddSelector(TestSelectorName);
            var selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, TestSelectorName);
            yield return UIETestEvents.Mouse.SimulateClick(selector);

            // Set style
            var displayFoldout = inspector.Query<PersistedFoldout>().Where(f => f.text.Equals("Display")).First();
            displayFoldout.value = true;

            var displayStrip = displayFoldout.Query<ToggleButtonStrip>().Where(t => t.label.Equals("Display")).First();
            yield return UIETestEvents.Mouse.SimulateClick(displayStrip.Q<Button>("none"));

            var visibilityStrip = displayFoldout.Query<ToggleButtonStrip>().Where(t => t.label.Equals("Visibility")).First();
            yield return UIETestEvents.Mouse.SimulateClick(visibilityStrip.Q<Button>("hidden"));
            yield return UIETestEvents.Mouse.SimulateClick(selector);

            var newlineFixedExpectedUSS = m_ExpectedSelectorString;
            if (BuilderConstants.NewlineChar != BuilderConstants.newlineCharFromEditorSettings)
                newlineFixedExpectedUSS = newlineFixedExpectedUSS.Replace(
                    BuilderConstants.NewlineChar,
                    BuilderConstants.newlineCharFromEditorSettings);

            // Copy to USS
            yield return UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Copy);
            Assert.That(BuilderEditorUtility.systemCopyBuffer, Is.EqualTo(newlineFixedExpectedUSS));

            // Paste from USS
            ForceNewDocument();
            yield return EnsureSelectorsCanBeAddedAndReloadBuilder();
            BuilderEditorUtility.systemCopyBuffer = string.Empty;
            yield return UIETestEvents.Mouse.SimulateClick(styleSheetsPane);
            yield return UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Paste);
            var explorerItems = BuilderTestsHelper.GetExplorerItemsWithName(styleSheetsPane, TestSelectorName);
            Assert.That(explorerItems.Count, Is.EqualTo(0));

            BuilderEditorUtility.systemCopyBuffer = newlineFixedExpectedUSS;
            yield return UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Paste);
            explorerItems = BuilderTestsHelper.GetExplorerItemsWithName(styleSheetsPane, TestSelectorName);
            Assert.That(explorerItems.Count, Is.EqualTo(1));

            // Foldout out state should be persisted, so we assume it is open already.
            displayFoldout = inspector.Query<PersistedFoldout>().Where(f => f.text.Equals("Display")).First();
            displayStrip = displayFoldout.Query<ToggleButtonStrip>().Where(t => t.label.Equals("Display")).First();
            Assert.True(displayStrip.Q<Button>("none").pseudoStates.HasFlag(PseudoStates.Checked));

            visibilityStrip = displayFoldout.Query<ToggleButtonStrip>().Where(t => t.label.Equals("Visibility")).First();
            Assert.True(visibilityStrip.Q<Button>("hidden").pseudoStates.HasFlag(PseudoStates.Checked));
        }
示例#8
0
        public IEnumerator SelectorCopyPasteDuplicateDelete()
        {
            yield return(EnsureSelectorsCanBeAddedAndReloadBuilder());

            yield return(AddSelector(TestSelectorName));

            var explorerItems = BuilderTestsHelper.GetExplorerItemsWithName(styleSheetsPane, TestSelectorName);

            Assert.That(explorerItems.Count, Is.EqualTo(1));

            yield return(UIETestEvents.Mouse.SimulateClick(explorerItems[0]));

            // Duplicate
            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Duplicate));

            explorerItems = BuilderTestsHelper.GetExplorerItemsWithName(styleSheetsPane, TestSelectorName);
            Assert.That(explorerItems.Count, Is.EqualTo(2));

            // Copy
            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Copy));

            yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Paste));

            explorerItems = BuilderTestsHelper.GetExplorerItemsWithName(styleSheetsPane, TestSelectorName);
            Assert.That(explorerItems.Count, Is.EqualTo(3));

            var styleSheetElement = builder.documentRootElement.parent.Q(k_TestEmptyUSSFileNameNoExt);

            Assert.That(styleSheetElement, Is.Not.Null);
            Assert.That(styleSheetElement.childCount, Is.EqualTo(3));
            Assert.That(
                styleSheetElement.GetProperty(BuilderConstants.ElementLinkedStyleSheetVEPropertyName) as StyleSheet,
                Is.EqualTo(builder.document.firstStyleSheet));

            var selectedSelectorElement = styleSheetElement[2];
            var selectedSelector        = selectedSelectorElement.GetProperty(BuilderConstants.ElementLinkedStyleSelectorVEPropertyName) as StyleComplexSelector;

            Assert.That(selectedSelector, Is.Not.Null);
            Assert.That(selection.selection.Any(), Is.True);
            Assert.That(selection.selection.First(), Is.EqualTo(selectedSelectorElement));
            Assert.That(selectedSelectorElement.GetClosestStyleSheet(), Is.EqualTo(builder.document.firstStyleSheet));

            // Delete
            yield return(UIETestEvents.KeyBoard.SimulateKeyDown(builder, KeyCode.Delete));

            yield return(UIETestHelpers.Pause(1));

            explorerItems = BuilderTestsHelper.GetExplorerItemsWithName(styleSheetsPane, TestSelectorName);
            Assert.That(explorerItems.Count, Is.EqualTo(2));
        }
示例#9
0
            public static IEnumerator SimulateScroll(VisualElement target, Vector2 delta, Vector2 position)
            {
                Assert.That(target.panel, Is.Not.Null);
                var root = UIETestHelpers.GetRoot(target);

                var evt = new Event
                {
                    type          = EventType.ScrollWheel,
                    delta         = delta,
                    mousePosition = position
                };

                var scrollEvent = UIETestEvents.MakeEvent(evt);

                root.SendEvent(scrollEvent);
                yield return(UIETestHelpers.Pause());
            }
        public IEnumerator CopyPasteUXML()
        {
            yield return(AddVisualElement());

            yield return(AddVisualElement());

            var hierarchyItems = BuilderTestsHelper.GetExplorerItemsWithName(HierarchyPane, nameof(VisualElement));
            var hierarchyItem1 = hierarchyItems[0];
            var hierarchyItem2 = hierarchyItems[1];

            yield return(UIETestEvents.Mouse.SimulateDragAndDrop(BuilderWindow,
                                                                 hierarchyItem1.worldBound.center,
                                                                 hierarchyItem2.worldBound.center));

            var complexItem = GetFirstExplorerItem();

            // Copy to UXML
            yield return(UIETestEvents.Mouse.SimulateClick(complexItem));

            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Copy));

            Assert.That(BuilderEditorUtility.SystemCopyBuffer, Is.EqualTo(m_ExpectedUXMLString));

            ForceNewDocument();
            BuilderEditorUtility.SystemCopyBuffer = string.Empty;
            yield return(UIETestEvents.Mouse.SimulateClick(HierarchyPane));

            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Paste));

            var explorerItems = BuilderTestsHelper.GetExplorerItems(HierarchyPane);

            Assert.That(explorerItems, Is.Empty);

            BuilderEditorUtility.SystemCopyBuffer = m_ExpectedUXMLString;
            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Paste));

            // var newItem = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(VisualElement));
            var hierarchyTreeView = HierarchyPane.Q <TreeView>();

            hierarchyTreeView.ExpandItem(hierarchyTreeView.items.ToList()[1].id);

            explorerItems = BuilderTestsHelper.GetExplorerItems(HierarchyPane);
            Assert.That(explorerItems.Count, Is.EqualTo(2));
            Assert.That(BuilderTestsHelper.GetLinkedDocumentElement(explorerItems[1]).parent, Is.EqualTo(BuilderTestsHelper.GetLinkedDocumentElement(explorerItems[0])));
        }
        public IEnumerator StandardShortCuts()
        {
            yield return(AddVisualElement());

            var explorerItems = BuilderTestsHelper.GetExplorerItems(HierarchyPane);

            Assert.That(explorerItems.Count, Is.EqualTo(1));
            yield return(UIETestEvents.Mouse.SimulateClick(explorerItems[0]));

            // Duplicate
            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Duplicate));

            explorerItems = BuilderTestsHelper.GetExplorerItems(HierarchyPane);
            Assert.That(explorerItems.Count, Is.EqualTo(2));

            // Copy/Paste
            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Copy));

            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Paste));

            explorerItems = BuilderTestsHelper.GetExplorerItems(HierarchyPane);
            Assert.That(explorerItems.Count, Is.EqualTo(3));

            // Delete
            yield return(UIETestEvents.KeyBoard.SimulateKeyDown(BuilderWindow, KeyCode.Delete));

            explorerItems = BuilderTestsHelper.GetExplorerItems(HierarchyPane);
            Assert.That(explorerItems.Count, Is.EqualTo(2));

            // Pasted as children of the parent of the currently selected element.

            yield return(AddTextFieldElement());

            var textField = ViewportPane.documentElement.Q <TextField>();

            Assert.That(textField.childCount, Is.EqualTo(2));

            yield return(UIETestEvents.ExecuteCommand(BuilderWindow, UIETestEvents.Command.Paste));

            Assert.That(textField.childCount, Is.EqualTo(2));
        }