Exemplo n.º 1
0
        public IEnumerator ZoomWithMouseScrollAndRightClick()
        {
            var toolbar      = ViewportPane.Q <BuilderToolbar>();
            var zoomMenuItem = toolbar.Query <ToolbarMenu>().Where(menu => menu.Q <TextElement>().text == "100%").First();

            Assert.That(zoomMenuItem, Is.Not.Null);

            // Zoom With Scroll Wheel
            yield return(UIETestEvents.Mouse.SimulateClick(ViewportPane));

            yield return(UIETestEvents.Mouse.SimulateScroll(Vector2.one * 100, ViewportPane.worldBound.center));

            yield return(UIETestEvents.Mouse.SimulateMouseEvent(BuilderWindow,
                                                                EventType.MouseDown,
                                                                ViewportPane.worldBound.center,
                                                                MouseButton.RightMouse,
                                                                EventModifiers.Alt));

            yield return(UIETestEvents.Mouse.SimulateMouseMove(BuilderWindow,
                                                               ViewportPane.worldBound.center,
                                                               ViewportPane.worldBound.center + Vector2.one * 20,
                                                               MouseButton.RightMouse,
                                                               EventModifiers.Alt));

            yield return(UIETestHelpers.Pause(1));

            Assert.That(zoomMenuItem.text, Is.Not.EqualTo("100%"));
        }
Exemplo n.º 2
0
        public IEnumerator CanResetViewAndFitCanvas()
        {
            var toolbar         = ViewportPane.Q <BuilderToolbar>();
            var fitCanvasButton = toolbar.Q <ToolbarButton>(BuilderToolbar.FitCanvasButtonName);

            Assert.That(fitCanvasButton, Is.Not.Null);

            var canvas   = ViewportPane.Q <BuilderCanvas>();
            var viewport = ViewportPane.Q <VisualElement>("viewport");

            // A new document, when opened, is centered by default, thus we need to offset it before
            // clicking on the FitCanvas button
            yield return(UIETestEvents.Mouse.SimulateMouseEvent(BuilderWindow,
                                                                EventType.MouseDown,
                                                                canvas.worldBound.center,
                                                                MouseButton.MiddleMouse));

            yield return(UIETestEvents.Mouse.SimulateMouseMove(BuilderWindow,
                                                               ViewportPane.worldBound.center,
                                                               canvas.worldBound.center + Vector2.one * 100,
                                                               MouseButton.MiddleMouse));

            yield return(UIETestEvents.Mouse.SimulateMouseEvent(BuilderWindow,
                                                                EventType.MouseUp,
                                                                canvas.worldBound.center,
                                                                MouseButton.MiddleMouse));

            Assert.That(canvas.worldBound.center, Is.Not.EqualTo(viewport.worldBound.center));

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

            Assert.True(Mathf.Abs(canvas.worldBound.center.x - viewport.worldBound.center.x) < 1f);
            Assert.True(Mathf.Abs(canvas.worldBound.center.y - viewport.worldBound.center.y) < 1f);
        }
        public IEnumerator PreviewModeBehaviour()
        {
            var toolbar       = ViewportPane.Q <BuilderToolbar>();
            var previewToggle = toolbar.Query <ToolbarToggle>().Where(toggle => toggle.text == "Preview").First();

            Assert.That(previewToggle, Is.Not.Null);

            yield return(AddButtonElement());

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

            Assert.True(BuilderWindow.selection.isEmpty);

            var button = (Button)GetFirstDocumentElement();

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

            Assert.True(button.pseudoStates == 0);
            Assert.That(BuilderWindow.selection.selection.First(), Is.EqualTo(button));

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

            Assert.True(BuilderWindow.selection.isEmpty);
            yield return(UIETestEvents.Mouse.SimulateClick(previewToggle));

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

            Assert.True(BuilderWindow.selection.isEmpty);
            Assert.True(button.pseudoStates.HasFlag(PseudoStates.Hover));
        }
Exemplo n.º 4
0
        public IEnumerator PreviewModeBehaviour()
        {
            var toolbar       = ViewportPane.Q <BuilderToolbar>();
            var previewToggle = toolbar.Q <ToolbarToggle>(BuilderToolbar.PreviewToggleName);

            Assert.That(previewToggle, Is.Not.Null);

            // Fit Canvas to make sure added button will be visible
            var fitCanvasButton = toolbar.Q <ToolbarButton>(BuilderToolbar.FitCanvasButtonName);

            Assert.That(fitCanvasButton, Is.Not.Null);
            yield return(UIETestEvents.Mouse.SimulateClick(fitCanvasButton));

            AddElementCodeOnly <Button>();
            yield return(UIETestEvents.Mouse.SimulateClick(ViewportPane));

            Assert.True(BuilderWindow.selection.isEmpty);

            var button = (Button)GetFirstDocumentElement();

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

            Assert.True(button.pseudoStates == 0);
            Assert.That(BuilderWindow.selection.selection.First(), Is.EqualTo(button));

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

            Assert.True(BuilderWindow.selection.isEmpty);
            yield return(UIETestEvents.Mouse.SimulateClick(previewToggle));

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

            Assert.True(BuilderWindow.selection.isEmpty);
            Assert.True(button.pseudoStates.HasFlag(PseudoStates.Hover));
        }
Exemplo n.º 5
0
        public IEnumerator MultipleSelectedElementsHaveNoBlueBorderOrHeaderDisplayed()
        {
            const string buttonOneName = "ButtonOne";
            const string buttonTwoName = "ButtonTwo";

            AddElementCodeOnly <Button>(buttonOneName);
            AddElementCodeOnly <Button>(buttonTwoName);
            var selector = ViewportPane.Q("selection-indicator");
            var header   = ViewportPane.Q("selection-indicator").Q("header");

            BuilderWindow.selection.ClearSelection(null);
            yield return(UIETestHelpers.Pause());

            Assert.That(selector.resolvedStyle.display, Is.EqualTo(DisplayStyle.None));
            Assert.That(header.layout.size.magnitude, Is.Zero);

            BuilderWindow.selection.AddToSelection(null, ViewportPane.Q(buttonOneName));
            yield return(UIETestHelpers.Pause());

            Assert.That(selector.resolvedStyle.display, Is.EqualTo(DisplayStyle.Flex));
            Assert.That(header.layout.size.magnitude, Is.Not.Zero);

            BuilderWindow.selection.AddToSelection(null, ViewportPane.Q(buttonTwoName));
            yield return(UIETestHelpers.Pause());

            Assert.That(selector.resolvedStyle.display, Is.EqualTo(DisplayStyle.None));
            Assert.That(header.layout.size.magnitude, Is.Zero);
        }
        public IEnumerator HeaderTooltipContainsUXMLAssetPath()
        {
            var asset   = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_TestUXMLFilePath);
            var toolbar = ViewportPane.Q <BuilderToolbar>();

            toolbar.LoadDocument(asset);

            yield return(UIETestHelpers.Pause());

            Assert.That(Canvas.TitleLabel.tooltip, Is.EqualTo(k_TestUXMLFilePath));
        }
        public IEnumerator ViewportHeaderTitleText()
        {
            Assert.True(ViewportPane.subTitle.Contains("<unsaved file>"));

            var asset   = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_TestUXMLFilePath);
            var toolbar = ViewportPane.Q <BuilderToolbar>();

            toolbar.LoadDocument(asset);

            yield return(UIETestHelpers.Pause(1));

            Assert.True(ViewportPane.subTitle.Contains(k_TestUXMLFileName));
        }
        public IEnumerator DocumentUnsavedChangesShouldAddIndicationToTheToolbar()
        {
            var asset   = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_TestUXMLFilePath);
            var toolbar = ViewportPane.Q <BuilderToolbar>();

            toolbar.LoadDocument(asset);

            yield return(UIETestHelpers.Pause(1));

            Assert.False(ViewportPane.subTitle.Contains("*"));

            yield return(AddVisualElement());

            Assert.True(ViewportPane.subTitle.Contains("*"));
        }
        public IEnumerator DocumentUnsavedChangesShouldAddIndicationToTheToolbar()
        {
            var asset   = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_TestUXMLFilePath);
            var toolbar = ViewportPane.Q <BuilderToolbar>();

            toolbar.LoadDocument(asset);

            yield return(UIETestHelpers.Pause());

            Assert.That(Canvas.TitleLabel.text, Is.EqualTo(k_TestUXMLFileName));

            yield return(AddVisualElement());

            Assert.That(Canvas.TitleLabel.text, Is.EqualTo($"{k_TestUXMLFileName}*"));
        }
Exemplo n.º 10
0
        public IEnumerator SelectedElementHasBlueBorder()
        {
            AddElementCodeOnly <Button>();
            var element  = GetFirstDocumentElement();
            var selector = ViewportPane.Q("selection-indicator");

            BuilderWindow.selection.ClearSelection(null);
            yield return(UIETestHelpers.Pause());

            Assert.That(selector, Style.Display(DisplayStyle.None));
            Assert.IsFalse(selector.worldBound.Overlaps(element.worldBound));

            BuilderWindow.selection.AddToSelection(null, element);
            yield return(UIETestHelpers.Pause());

            Assert.That(selector, Style.Display(DisplayStyle.Flex));
            Assert.IsTrue(selector.worldBound.Overlaps(element.worldBound));
        }
Exemplo n.º 11
0
        public IEnumerator CanvasSizeRememberedPerDocument()
        {
            CreateTestUXMLFile();
            var asset   = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_TestUXMLFilePath);
            var toolbar = ViewportPane.Q <BuilderToolbar>();

            toolbar.LoadDocument(asset);
            yield return(UIETestHelpers.Pause());

            BuilderWindow.canvas.ResetSize();
            BuilderWindow.canvas.width = k_TestCanvasSizeValue;
            Assert.That(BuilderWindow.canvas.width, Is.EqualTo(k_TestCanvasSizeValue));

            ForceNewDocument();
            Assert.That(BuilderWindow.canvas.width, Is.Not.EqualTo(k_TestCanvasSizeValue));

            toolbar.LoadDocument(asset);
            Assert.That(BuilderWindow.canvas.width, Is.EqualTo(k_TestCanvasSizeValue));
        }
        public IEnumerator CreatingNewDocumentClearsSelectionAndExplorer()
        {
            var toolbar = ViewportPane.Q <BuilderToolbar>();

            // Make sure File menu exists
            var menuItem = toolbar.Query <ToolbarMenu>().Where(menu => menu.Q <TextElement>().text == "File").First();

            Assert.That(menuItem, Is.Not.Null);

            yield return(AddVisualElement());

            yield return(AddSelector(StyleSheetsPaneTests.TestSelectorName));

            ForceNewDocument();
            Assert.That(ViewportPane.documentElement.childCount, Is.EqualTo(0));
            Assert.That(BuilderTestsHelper.GetExplorerItems(StyleSheetsPane).Count, Is.EqualTo(0));
            Assert.That(BuilderTestsHelper.GetExplorerItems(HierarchyPane).Count, Is.EqualTo(0));
            Assert.True(BuilderWindow.selection.isEmpty);
        }
Exemplo n.º 13
0
        public IEnumerator SettingsCopiedFromUnsavedDocument()
        {
            var toolbar = ViewportPane.Q <BuilderToolbar>();
            var documentHierarchyHeader = HierarchyPane.Q <BuilderExplorerItem>();

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

            var colorButton = InspectorPane.Q <Button>("Color");

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

            var colorField = InspectorPane.Q <ColorField>("background-color-field");

            colorField.value = Color.green;
            yield return(UIETestHelpers.Pause(1));

            toolbar.SaveDocument(k_NewUxmlFilePath, k_NewUssFilePath);
            Assert.That(BuilderWindow.document.settings.CanvasBackgroundMode, Is.EqualTo(BuilderCanvasBackgroundMode.Color));
            Assert.That(BuilderWindow.document.settings.CanvasBackgroundColor, Is.EqualTo(Color.green));
        }
Exemplo n.º 14
0
        public IEnumerator SelectedElementHasATitleOfItsNameOtherwiseItsType()
        {
            AddElementCodeOnly <Button>();
            var element = GetFirstDocumentElement();

            BuilderWindow.selection.Select(null, element);
            yield return(UIETestHelpers.Pause());

            var header = ViewportPane.Q("selection-indicator").Q <Label>("header-label");

            Assert.That(header.text, Is.EqualTo(element.typeName));

            ForceNewDocument();
            AddElementCodeOnly <Button>("MyButton");
            element = GetFirstDocumentElement();
            BuilderWindow.selection.Select(null, element);
            yield return(UIETestHelpers.Pause());

            header = ViewportPane.Q("selection-indicator").Q <Label>("header-label");
            Assert.That(header.text, Is.EqualTo("#" + element.name));
        }
Exemplo n.º 15
0
        public IEnumerator SelectingElementInsideTemplateInstanceOrCSharpSelectsIt()
        {
            //Template Instance
            yield return(LoadTestUXMLDocument(k_ParentTestUXMLPath));

            var element = ViewportPane.Q <TemplateContainer>().Children().First();

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

            Assert.That(ViewportPane.FindSelectedElements()[0].typeName,
                        Is.EqualTo(ViewportPane.Q <TemplateContainer>().typeName));

            //C# type
            ForceNewDocument();
            AddElementCodeOnly <TextField>();
            var textInput = ViewportPane.Q("unity-text-input");

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

            Assert.That(ViewportPane.FindSelectedElements()[0].typeName, Is.EqualTo("TextField"));
        }
        public IEnumerator SubDocumentFunctionalityViaRightClickMenu()
        {
            var panel = BuilderWindow.rootVisualElement.panel as BaseVisualElementPanel;
            var menu  = panel.contextualMenuManager as BuilderTestContextualMenuManager;

            Assert.That(menu, Is.Not.Null);
            Assert.That(menu.menuIsDisplayed, Is.False);

            // Load Test UXML File
            var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_ParentTestUXMLPath);

            Assert.That(asset, Is.Not.Null);
            BuilderWindow.LoadDocument(asset);
            yield return(UIETestHelpers.Pause(1));

            // Check that Breadcrumbs toolbar is NOT present
            var toolbar            = ViewportPane.Q <BuilderToolbar>();
            var breadcrumbsToolbar = toolbar.Q <Toolbar>(BuilderToolbar.BreadcrumbsToolbarName);
            var breadcrumbs        = toolbar.Q <ToolbarBreadcrumbs>(BuilderToolbar.BreadcrumbsName);

            Assert.IsNotNull(breadcrumbsToolbar);
            Assert.AreEqual((StyleEnum <DisplayStyle>)DisplayStyle.None, breadcrumbsToolbar.style.display);
            Assert.AreEqual(0, breadcrumbs.childCount);

            // Check that child is instantiated
            string nameOfChildSubDocument = "#ChildTestUXMLDocument";
            var    childInHierarchy       = BuilderTestsHelper.GetExplorerItemsWithName(HierarchyPane, nameOfChildSubDocument);

            Assert.AreEqual(1, childInHierarchy.Count);
            Assert.NotNull(childInHierarchy[0]);

            // Simulate right click on child TemplateContainer
            yield return(UIETestEvents.Mouse.SimulateClick(childInHierarchy[0], MouseButton.RightMouse));

            Assert.That(menu.menuIsDisplayed, Is.True);

            var subdocumentClick = menu.FindMenuAction(BuilderConstants.ExplorerHierarchyPaneOpenSubDocument);

            Assert.That(subdocumentClick, Is.Not.Null);

            subdocumentClick.Execute();
            yield return(UIETestHelpers.Pause(1));

            // Get parent document
            var parentRoot = BuilderTestsHelper.GetHeaderItem(HierarchyPane);

            Assert.NotNull(parentRoot);

            // Breadcrumbs is displaying
            Assert.AreEqual(2, breadcrumbs.childCount);
            Assert.AreEqual(breadcrumbsToolbar.style.display, (StyleEnum <DisplayStyle>)DisplayStyle.Flex);

            // Click back to get to Parent
            yield return(UIETestEvents.Mouse.SimulateClick(parentRoot, MouseButton.RightMouse));

            Assert.That(menu.menuIsDisplayed, Is.True);

            var parentClick = menu.FindMenuAction(BuilderConstants.ExplorerHierarchyReturnToParentDocument);

            Assert.That(parentClick, Is.Not.Null);
            parentClick.Execute();

            yield return(UIETestHelpers.Pause(1));

            Assert.AreEqual(1, BuilderWindow.documentRootElement.childCount);

            Assert.AreEqual(0, breadcrumbs.childCount);
            Assert.AreEqual(breadcrumbsToolbar.style.display, (StyleEnum <DisplayStyle>)DisplayStyle.None);
        }