public IEnumerator DraggingChildElementsOfATemplateShouldNotWork()
        {
            AddElementCodeOnly <TextField>();
            AddElementCodeOnly();

            var hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(TextField));

            yield return(UIETestHelpers.ExpandTreeViewItem(hierarchyItem));

            yield return(UIETestHelpers.Pause());

            var textField              = viewport.documentRootElement[0];
            var textFieldLabel         = textField.Q <Label>();
            var visualElement          = viewport.documentRootElement[1];
            var textFieldLabelExplorer = BuilderTestsHelper.GetLinkedExplorerItem(textFieldLabel);
            var visualElementExplorer  = BuilderTestsHelper.GetLinkedExplorerItem(visualElement);

            yield return(UIETestEvents.Mouse.SimulateDragAndDrop(builder,
                                                                 visualElementExplorer.worldBound.center,
                                                                 textFieldLabelExplorer.worldBound.center));

            Assert.That(visualElement.parent, Is.EqualTo(viewport.documentRootElement));

            yield return(UIETestEvents.Mouse.SimulateDragAndDrop(builder,
                                                                 textFieldLabelExplorer.worldBound.center,
                                                                 visualElementExplorer.worldBound.center));

            Assert.That(textFieldLabel.parent, Is.EqualTo(textField));
        }
        public IEnumerator CSharpTypeTemplateChildrenMustBeGrayedOutAndNotEditable()
        {
            AddElementCodeOnly <TextField>();
            var hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(TextField));

            yield return(UIETestHelpers.ExpandTreeViewItem(hierarchyItem));

            var textFieldDocumentElement = GetFirstDocumentElement();

            Assert.That(textFieldDocumentElement.childCount, Is.GreaterThan(0));
            BuilderExplorerItem lastChild = null;

            foreach (var child in textFieldDocumentElement.Children())
            {
                lastChild = BuilderTestsHelper.GetLinkedExplorerItem(child);
                Assert.That(lastChild.row().classList, Contains.Item(BuilderConstants.ExplorerItemHiddenClassName));
            }

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

            inspector.Query <ToggleButtonStrip>().ForEach(toggleButtonStrip =>
            {
                Assert.That(toggleButtonStrip.enabledInHierarchy, Is.False);
            });

            inspector.Query <PercentSlider>().ForEach(percentSlider =>
            {
                Assert.That(percentSlider.enabledInHierarchy, Is.False);
            });
        }
Exemplo n.º 3
0
        public IEnumerator HoveringOverElementsHighlightsThemInHierarchy()
        {
            AddElementCodeOnly <Button>();
            var element       = GetFirstDocumentElement();
            var linkedElement = BuilderTestsHelper.GetLinkedExplorerItem(element);
            var oldColor      = linkedElement.parent.parent.resolvedStyle.backgroundColor;

            // SimulateMove doesn't want to move without SimulateClick or additional move event... weird
            yield return(UIETestEvents.Mouse.SimulateClick(viewport.canvas));

            yield return(UIETestEvents.Mouse.SimulateMouseEvent(builder, EventType.MouseMove,
                                                                element.worldBound.center));

            Assert.That(linkedElement.parent.parent.resolvedStyle.backgroundColor, Is.Not.EqualTo(oldColor));
        }
Exemplo n.º 4
0
        internal BuilderExplorerItem GetFirstExplorerItem()
        {
            var firstDocumentElement = ViewportPane.documentElement[0];

            return(BuilderTestsHelper.GetLinkedExplorerItem(firstDocumentElement));
        }
Exemplo n.º 5
0
        public IEnumerator SampleTest()
        {
            // A new Builder window created when the test started.
            // The created window will be destroyed during the teardown stage.
            Assert.That(BuilderWindow, Is.Not.Null);

            // Fast access to the main builder panes.
            Assert.That(StyleSheetsPane, Is.Not.Null);
            Assert.That(HierarchyPane, Is.Not.Null);
            Assert.That(LibraryPane, Is.Not.Null);
            Assert.That(ViewportPane, Is.Not.Null);
            Assert.That(InspectorPane, Is.Not.Null);

            // Use the following methods to add standard controls to the document.
            AddElementCodeOnly();
            AddElementCodeOnly <TextField>();
            AddElementCodeOnly <Button>();

            // Get created element.
            var createdButton = ViewportPane.documentElement.Q <Button>();

            // Get linked hierarchy item.
            var buttonHierarchyNode = BuilderTestsHelper.GetLinkedExplorerItem(createdButton);

            // Create New selector.
            // There's a requirement that a USS file has already been added to
            // the document in order to add selectors. This function will make
            // sure the document is ready to have new selectors created.
            yield return(EnsureSelectorsCanBeAddedAndReloadBuilder());

            yield return(AddSelector(".my-selector"));

            // Retrieve created selector explorer node.
            var mySelectorNode = GetStyleSelectorNodeWithName(".my-selector");

            // Drag and drop sample. Drag selector onto created button.
            yield return(UIETestEvents.Mouse.SimulateDragAndDrop(BuilderWindow,
                                                                 mySelectorNode.Q <Label>().worldBound.center,
                                                                 buttonHierarchyNode.worldBound.center));

            // Selected created TextField node and inline change style.
            // Avoid using ListView / TreeView / VisualElement API to select / focus an item.
            // Simulate how a user would do it with UIETestEvents API.
            var textFieldHierarchyNode = BuilderTestsHelper.GetLinkedExplorerItem(ViewportPane.documentElement.Q <TextField>());

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

            // Make sure you unfold style properties group before accessing the properties.
            // Keep in mind the amount of time that will be spent by your test. Try to keep it as low as possible.
            // In the code sample below, instead of simulating user interaction, we will just set controls values directly.
            // However, there are no strict rules when you should skip user interaction simulation, use your judgment.
            var displayFoldout = InspectorPane.Query <PersistedFoldout>().Where(f => f.text.Equals("Display")).First();

            displayFoldout.value = true;

            var percentSlider = displayFoldout.Query <PercentSlider>().Where(t => t.label.Equals("Opacity")).First();

            percentSlider.value = 0.5f;

            yield return(UIETestHelpers.Pause());

            var textFieldDocumentItem = BuilderTestsHelper.GetLinkedDocumentElement(textFieldHierarchyNode);

            Assert.That(textFieldDocumentItem.opacity, Is.EqualTo(percentSlider.value));
        }