public IEnumerator DisplayNameStyleAndRenameOption() { const string testItemName = "test_name"; AddElementCodeOnly(); var hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(VisualElement)); var documentElement = BuilderTestsHelper.GetLinkedDocumentElement(hierarchyItem); var nameLabel = hierarchyItem.Q <Label>(className: BuilderConstants.ExplorerItemLabelClassName); Assert.That(nameLabel.text, Is.EqualTo(nameof(VisualElement))); Assert.That(nameLabel.classList, Contains.Item(BuilderConstants.ElementTypeClassName)); yield return(UIETestEvents.Mouse.SimulateDoubleClick(hierarchyItem)); yield return(UIETestEvents.KeyBoard.SimulateTyping(builder, testItemName)); yield return(UIETestEvents.KeyBoard.SimulateKeyDown(builder, KeyCode.Return)); Assert.That(documentElement.name, Is.EqualTo(testItemName)); hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, BuilderConstants.UssSelectorNameSymbol + testItemName); nameLabel = hierarchyItem.Q <Label>(className: BuilderConstants.ExplorerItemLabelClassName); Assert.That(nameLabel.classList, Contains.Item(BuilderConstants.ElementNameClassName)); hierarchyItem = GetFirstExplorerItem(); yield return(UIETestEvents.Mouse.SimulateDoubleClick(hierarchyItem)); yield return(UIETestEvents.KeyBoard.SimulateTyping(builder, "invalid&name")); yield return(UIETestEvents.KeyBoard.SimulateKeyDown(builder, KeyCode.Return)); Assert.That(documentElement.name, Is.EqualTo(testItemName)); }
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); }); }
public IEnumerator PastingAddsSelectorToActiveStyleSheet() { yield return(CodeOnlyAddUSSToDocument(k_ColorsTestUSSPath)); yield return(CodeOnlyAddUSSToDocument(k_LayoutTestUSSPath)); // Copy Selector. var unityButtonSelectors = BuilderTestsHelper.GetExplorerItemsWithName(styleSheetsPane, ".unity-button"); yield return(UIETestEvents.Mouse.SimulateClick(unityButtonSelectors[0])); yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Copy)); // Activate the second StyleSheet. var layoutExplorerItem = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, k_LayoutTestUSSFileName); Assert.That(layoutExplorerItem, Is.Not.Null); var layoutStyleSheet = GetStyleSheetFromExplorerItem(layoutExplorerItem, k_LayoutTestUSSPath); var previousNumberOfSelectors = layoutStyleSheet.complexSelectors.Length; BuilderStyleSheetsUtilities.SetActiveUSS(selection, styleSheetsPane.paneWindow, layoutStyleSheet); Assert.That(builder.document.activeStyleSheet, Is.EqualTo(layoutStyleSheet)); // Paste Selector. yield return(UIETestEvents.ExecuteCommand(builder, UIETestEvents.Command.Paste)); Assert.That(layoutStyleSheet.complexSelectors.Length, Is.EqualTo(previousNumberOfSelectors + 2)); // 2 for the extra fake rule added to the stylesheet for the pasted selector. see BuilderSharedStyles.CreateNewSelectorElement }
public IEnumerator HasVariableIndicator() { var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_NewVariableUxmlFilePath); builder.LoadDocument(asset); yield return(UIETestHelpers.Pause(1)); hierarchy.elementHierarchyView.ExpandRootItems(); styleSheetsPane.elementHierarchyView.ExpandRootItems(); yield return(UIETestHelpers.Pause(1)); // Select test-selector-1 var selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, k_Selector_1); yield return(UIETestEvents.Mouse.SimulateClick(selector)); var textFoldout = inspector.Query <PersistedFoldout>().Where(f => f.text.Equals("Text")).First(); textFoldout.value = true; var colorField = FindStyleField(textFoldout, "Color"); Assert.IsTrue(colorField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableClassName)); var sizeField = FindStyleField(textFoldout, "Size"); Assert.IsFalse(sizeField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableClassName)); yield return(null); }
public IEnumerator DragStylePillOntoTemplateElementInHierarchy() { AddElementCodeOnly <TextField>(); // Ensure we can add selectors. yield return(EnsureSelectorsCanBeAddedAndReloadBuilder()); yield return(AddSelector(TestSelectorName)); var createdSelector = GetStyleSelectorNodeWithName(TestSelectorName); yield return(UIETestHelpers.Pause(1)); var hierarchyTreeView = HierarchyPane.Q <TreeView>(); hierarchyTreeView.ExpandItem(hierarchyTreeView.items.ToList()[1].id); var textFieldLabel = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(Label)).Q <Label>(); yield return(UIETestHelpers.Pause(1)); yield return(UIETestEvents.Mouse.SimulateDragAndDrop(BuilderWindow, createdSelector.Q <Label>().worldBound.center, textFieldLabel.worldBound.center)); var documentElement = GetFirstDocumentElement(); Assert.That(documentElement.classList, Is.Not.Contain(TestSelectorName.TrimStart('.'))); }
public IEnumerator DraggingChildElementsOfATemplateShouldNotWork() { AddElementCodeOnly <TextField>(); AddElementCodeOnly(); var hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(TextField)); yield return(UIETestHelpers.ExpandTreeViewItem(hierarchyItem)); yield return(UIETestHelpers.Pause()); var textField = ViewportPane.documentElement[0]; var textFieldLabel = textField.Q <Label>(); var visualElement = ViewportPane.documentElement[1]; var textFieldLabelExplorer = BuilderTestsHelper.GetLinkedExplorerItem(textFieldLabel); var visualElementExplorer = BuilderTestsHelper.GetLinkedExplorerItem(visualElement); yield return(UIETestEvents.Mouse.SimulateDragAndDrop(BuilderWindow, visualElementExplorer.worldBound.center, textFieldLabelExplorer.worldBound.center)); Assert.That(visualElement.parent, Is.EqualTo(ViewportPane.documentElement)); yield return(UIETestEvents.Mouse.SimulateDragAndDrop(BuilderWindow, textFieldLabelExplorer.worldBound.center, visualElementExplorer.worldBound.center)); Assert.That(textFieldLabel.parent, Is.EqualTo(textField)); }
public IEnumerator ReparentFlowWhenDraggingOntoCSharpTypeElement() { AddElementCodeOnly <TextField>(); AddElementCodeOnly(); yield return(UIETestHelpers.Pause()); var textFieldItem = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(TextField)); var visualElementItem = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(VisualElement)); var visualElementDocItem = BuilderTestsHelper.GetLinkedDocumentElement(visualElementItem); yield return(UIETestEvents.Mouse.SimulateDragAndDrop(BuilderWindow, visualElementItem.worldBound.center, textFieldItem.worldBound.center)); Assert.That(visualElementDocItem.parent, Is.InstanceOf <TextField>()); ForceNewDocument(); AddElementCodeOnly <TextField>(); AddElementCodeOnly(); yield return(UIETestHelpers.Pause()); textFieldItem = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(TextField)); visualElementItem = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(VisualElement)); visualElementDocItem = BuilderTestsHelper.GetLinkedDocumentElement(visualElementItem); var textFieldDocItem = BuilderTestsHelper.GetLinkedDocumentElement(textFieldItem); yield return(UIETestEvents.Mouse.SimulateDragAndDrop(BuilderWindow, visualElementItem.worldBound.center, textFieldDocItem.worldBound.center)); Assert.That(visualElementDocItem.parent, Is.InstanceOf <TextField>()); }
public IEnumerator SetAsActiveUSSChangesActiveUSS() { // Active StyleSheet is null when no USS are added. Assert.That(BuilderWindow.document.firstStyleSheet, Is.Null); Assert.That(BuilderWindow.document.activeStyleSheet, Is.Null); yield return(CodeOnlyAddUSSToDocument(k_ColorsTestUSSPath)); yield return(CodeOnlyAddUSSToDocument(k_LayoutTestUSSPath)); 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); // First StyleSheet should be active by default. var colorsExplorerItem = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, k_ColorsTestUSSFileName); Assert.That(colorsExplorerItem, Is.Not.Null); var colorStyleSheet = GetStyleSheetFromExplorerItem(colorsExplorerItem, k_ColorsTestUSSPath); Assert.That(BuilderWindow.document.firstStyleSheet, Is.EqualTo(colorStyleSheet)); Assert.That(BuilderWindow.document.activeStyleSheet, Is.EqualTo(colorStyleSheet)); // Activate second StyleSheet. var layoutExplorerItem = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, k_LayoutTestUSSFileName); Assert.That(layoutExplorerItem, Is.Not.Null); var layoutStyleSheet = GetStyleSheetFromExplorerItem(layoutExplorerItem, k_LayoutTestUSSPath); yield return(UIETestEvents.Mouse.SimulateClick(layoutExplorerItem, MouseButton.RightMouse)); Assert.That(menu.menuIsDisplayed, Is.True); var activateUSSMenuEntry = menu.FindMenuAction(BuilderConstants.ExplorerStyleSheetsPaneSetActiveUSS); Assert.That(activateUSSMenuEntry, Is.Not.Null); activateUSSMenuEntry.Execute(); Assert.That(BuilderWindow.document.firstStyleSheet, Is.EqualTo(colorStyleSheet)); Assert.That(BuilderWindow.document.activeStyleSheet, Is.EqualTo(layoutStyleSheet)); // Check sub-title. Assert.AreEqual(layoutStyleSheet.name + BuilderConstants.UssExtension, StyleSheetsPane.pane.subTitle); // Re-activate first StyleSheet. colorsExplorerItem = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, k_ColorsTestUSSFileName); Assert.That(colorsExplorerItem, Is.Not.Null); yield return(UIETestEvents.Mouse.SimulateClick(colorsExplorerItem, MouseButton.RightMouse)); Assert.That(menu.menuIsDisplayed, Is.True); activateUSSMenuEntry = menu.FindMenuAction(BuilderConstants.ExplorerStyleSheetsPaneSetActiveUSS); Assert.That(activateUSSMenuEntry, Is.Not.Null); activateUSSMenuEntry.Execute(); Assert.That(BuilderWindow.document.activeStyleSheet, Is.EqualTo(colorStyleSheet)); }
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)); }
public IEnumerator SetVariable() { var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_NewVariableUxmlFilePath); builder.LoadDocument(asset); yield return(UIETestHelpers.Pause(1)); hierarchy.elementHierarchyView.ExpandRootItems(); styleSheetsPane.elementHierarchyView.ExpandRootItems(); yield return(UIETestHelpers.Pause(1)); // Select test-selector-1 var selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, k_Selector_1); yield return(UIETestEvents.Mouse.SimulateClick(selector)); var textFoldout = base.inspector.Query <PersistedFoldout>().Where(f => f.text.Equals("Text")).First(); textFoldout.value = true; // Show variable field for the Size field var sizeField = FindStyleField <DimensionStyleField>(textFoldout, "Size"); var handler = StyleVariableUtilities.GetVarHandler(sizeField); Assert.IsFalse(sizeField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableClassName)); handler.ShowVariableField(); // Enter variable name var textField = handler.variableField.Q <TextField>(); textField.value = k_LengthVarName; selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, k_Selector_1); // Click anywhere else to remove focus yield return(UIETestEvents.Mouse.SimulateClick(selector)); yield return(UIETestHelpers.Pause(1)); Assert.IsTrue(sizeField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableClassName)); var inspector = handler.inspector; var styleProperty = BuilderInspectorStyleFields.GetStyleProperty(inspector.currentRule, handler.styleName); Assert.IsTrue(styleProperty != null && styleProperty.IsVariable()); Assert.AreEqual(inspector.styleSheet.ReadVariable(styleProperty), k_LengthVarName); yield return(null); }
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)); }
public IEnumerator UnsetVariable() { var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_NewVariableUxmlFilePath); BuilderWindow.LoadDocument(asset); yield return(UIETestHelpers.Pause(1)); HierarchyPane.elementHierarchyView.ExpandAllChildren(); StyleSheetsPane.elementHierarchyView.ExpandAllChildren(); yield return(UIETestHelpers.Pause(1)); // Select test-selector-1 var selector = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, k_Selector_1); yield return(UIETestEvents.Mouse.SimulateClick(selector)); var textFoldout = InspectorPane.Query <PersistedFoldout>().Where(f => f.text.Equals("Text")).First(); textFoldout.value = true; // Show variable field for the Color field var colorField = FindStyleField <ColorField>(textFoldout, "Color"); var handler = StyleVariableUtilities.GetVarHandler(colorField); Assert.IsTrue(colorField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableClassName)); handler.ShowVariableField(); // Enter variable name var textField = handler.variableField.Q <TextField>(); textField.value = ""; selector = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, k_Selector_1); // Click anywhere else to remove focus yield return(UIETestEvents.Mouse.SimulateClick(selector)); Assert.IsFalse(colorField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableClassName)); var inspector = handler.inspector; var styleProperty = BuilderInspectorStyleFields.GetStyleProperty(inspector.currentRule, handler.styleName); Assert.IsNull(styleProperty); yield return(null); }
public IEnumerator ShowHideVariableField() { var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_NewVariableUxmlFilePath); builder.LoadDocument(asset); yield return(UIETestHelpers.Pause(1)); hierarchy.elementHierarchyView.ExpandRootItems(); styleSheetsPane.elementHierarchyView.ExpandRootItems(); yield return(UIETestHelpers.Pause(1)); // Select test-selector-1 var selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, k_Selector_1); yield return(UIETestEvents.Mouse.SimulateClick(selector)); var textFoldout = inspector.Query <PersistedFoldout>().Where(f => f.text.Equals("Text")).First(); textFoldout.value = true; var colorField = FindStyleField <ColorField>(textFoldout, "Color"); var handler = StyleVariableUtilities.GetVarHandler(colorField); Assert.IsNull(handler.variableField); handler.ShowVariableField(); Assert.IsTrue(colorField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableEditingClassName)); Assert.IsFalse(colorField.ClassListContains(BuilderConstants.ReadOnlyStyleClassName)); Assert.IsNotNull(handler.variableField); yield return(UIETestHelpers.Pause(1)); var inputField = handler.variableField.Q(TextField.textInputUssName); Assert.AreEqual(handler.variableField.resolvedStyle.display, DisplayStyle.Flex); Assert.IsTrue(HasFocus(inputField)); selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, k_Selector_1); // Click anywhere else to remove focus yield return(UIETestEvents.Mouse.SimulateClick(selector)); Assert.IsFalse(colorField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableEditingClassName)); Assert.AreEqual(handler.variableField.resolvedStyle.display, DisplayStyle.None); yield return(null); }
public IEnumerator ShowHideVariableField() { var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_NewVariableUxmlFilePath); BuilderWindow.LoadDocument(asset); yield return(UIETestHelpers.Pause(1)); // Select test-selector-1 var selector = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, k_Selector_1); yield return(UIETestEvents.Mouse.SimulateClick(selector)); var textFoldout = InspectorPane.Query <PersistedFoldout>().Where(f => f.text.Equals("Text")).First(); textFoldout.value = true; var colorField = FindStyleField <ColorField>(textFoldout, "Color"); var handler = StyleVariableUtilities.GetVarHandler(colorField); Assert.IsNull(handler.variableField); yield return(UIETestEvents.Mouse.SimulateDoubleClick(colorField.labelElement)); Assert.IsTrue(colorField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableEditingClassName)); Assert.IsFalse(colorField.ClassListContains(BuilderConstants.ReadOnlyStyleClassName)); // Check VariableEditingHandler.variableInfoTooltip == null as double click may be to fast so that the tooltip is not shown for the first time. Assert.IsTrue(handler.variableInfoTooltip == null || handler.variableInfoTooltip.resolvedStyle.display == DisplayStyle.None); Assert.IsNotNull(handler.variableField); yield return(UIETestHelpers.Pause(1)); var inputField = handler.variableField.Q(TextField.textInputUssName); Assert.AreEqual(handler.variableField.resolvedStyle.display, DisplayStyle.Flex); Assert.IsTrue(HasFocus(inputField)); selector = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, k_Selector_1); // Click anywhere else to remove focus yield return(UIETestEvents.Mouse.SimulateClick(selector)); Assert.IsFalse(colorField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableEditingClassName)); Assert.AreEqual(handler.variableField.resolvedStyle.display, DisplayStyle.None); yield return(null); }
IEnumerator EditVariable(string fieldPath, bool editorExtensionMode = false) { var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_NewVariableUxmlFilePath); builder.LoadDocument(asset); builder.document.fileSettings.editorExtensionMode = editorExtensionMode; currentHandler = null; yield return(UIETestHelpers.Pause(1)); hierarchy.elementHierarchyView.ExpandRootItems(); styleSheetsPane.elementHierarchyView.ExpandRootItems(); yield return(UIETestHelpers.Pause(1)); // Select test-selector-1 var selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, k_Selector_1); yield return(UIETestEvents.Mouse.SimulateClick(selector)); var texts = fieldPath.Split('/'); PersistedFoldout lastFoldout = null; VisualElement currentParent = inspector; for (var i = 0; i < (texts.Length - 1); i++) { var text = texts[i]; lastFoldout = currentParent.Query <PersistedFoldout>().Where(f => f.text.Equals(text)).First(); lastFoldout.value = true; currentParent = lastFoldout; } var propertyField = FindStyleField <BindableElement>(lastFoldout, texts.Last()); currentHandler = StyleVariableUtilities.GetVarHandler(propertyField); currentHandler.ShowVariableField(); // Wait a frame for the variable field to receive focus and dispatch focus in event yield return(null); // Wait another frame for the completer popup to show up yield return(null); }
public IEnumerator StyleSheetsItemsDeselect() { yield return EnsureSelectorsCanBeAddedAndReloadBuilder(); var styleSheetsTreeView = styleSheetsPane.Q<TreeView>(); Assert.That(styleSheetsTreeView.GetSelectedItem(), Is.Null); // Create and new selector and select yield return AddSelector(TestSelectorName); var selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, TestSelectorName); yield return UIETestEvents.Mouse.SimulateClick(selector); Assert.That(styleSheetsTreeView.GetSelectedItem(), Is.Not.Null); AddElementCodeOnly(); var documentElement = GetFirstDocumentElement(); yield return UIETestEvents.Mouse.SimulateClick(documentElement); Assert.That(styleSheetsTreeView.GetSelectedItem(), Is.Null); }
public IEnumerator VariableSearch_ShowHidePopup() { yield return(EditVariable("Text/Color")); var propertyField = currentHandler.targetField; Assert.IsTrue(propertyField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableEditingClassName)); Assert.IsFalse(propertyField.ClassListContains(BuilderConstants.ReadOnlyStyleClassName)); Assert.AreEqual(currentHandler.completer.popup.resolvedStyle.display, DisplayStyle.Flex); // Click anywhere else to remove focus var selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, k_Selector_1); yield return(UIETestEvents.Mouse.SimulateClick(selector)); Assert.IsFalse(propertyField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableEditingClassName)); Assert.AreEqual(currentHandler.completer.popup.resolvedStyle.display, DisplayStyle.None); yield return(null); }
public IEnumerator ShowHideVariableInfoPopup() { var asset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_NewVariableUxmlFilePath); BuilderWindow.LoadDocument(asset); yield return(UIETestHelpers.Pause(1)); HierarchyPane.elementHierarchyView.ExpandAllChildren(); StyleSheetsPane.elementHierarchyView.ExpandAllChildren(); yield return(UIETestHelpers.Pause(1)); // Select test-selector-1 var selector = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, k_Selector_1); yield return(UIETestEvents.Mouse.SimulateClick(selector)); var textFoldout = InspectorPane.Query <PersistedFoldout>().Where(f => f.text.Equals("Text")).First(); textFoldout.value = true; var colorField = FindStyleField <ColorField>(textFoldout, "Color"); var handler = StyleVariableUtilities.GetVarHandler(colorField); handler.ShowVariableField(); Assert.IsTrue(colorField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableEditingClassName)); Assert.IsFalse(colorField.ClassListContains(BuilderConstants.ReadOnlyStyleClassName)); Assert.IsTrue(handler.variableInfoTooltip.visible); Assert.IsNotNull(handler.variableInfoTooltip.currentHandler); Assert.AreEqual(handler.variableInfoTooltip.currentHandler, handler); // Click anywhere else to remove focus selector = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, k_Selector_1); yield return(UIETestEvents.Mouse.SimulateClick(selector)); Assert.IsFalse(colorField.ClassListContains(BuilderConstants.InspectorLocalStyleVariableEditingClassName)); Assert.IsFalse(handler.variableInfoTooltip.isShowing); yield return(null); }
public IEnumerator SelectingStyleSelectorOrStyleSheetDeselectsHierarchyItems() { AddElementCodeOnly(); yield return(EnsureSelectorsCanBeAddedAndReloadBuilder()); yield return(AddSelector(StyleSheetsPaneTests.TestSelectorName)); // Deselect yield return(UIETestEvents.Mouse.SimulateClick(hierarchy)); var hierarchyTreeView = hierarchy.Q <TreeView>(); Assert.That(hierarchyTreeView.GetSelectedItem(), Is.Null); // Select hierarchy item var hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(VisualElement)); yield return(UIETestEvents.Mouse.SimulateClick(hierarchyItem)); Assert.That(hierarchyTreeView.GetSelectedItem(), Is.Not.Null); // Select test selector var selector = BuilderTestsHelper.GetExplorerItemWithName(styleSheetsPane, StyleSheetsPaneTests.TestSelectorName); yield return(UIETestEvents.Mouse.SimulateClick(selector)); Assert.That(hierarchyTreeView.GetSelectedItem(), Is.Null); // Select hierarchy item yield return(UIETestEvents.Mouse.SimulateClick(hierarchyItem)); Assert.That(hierarchyTreeView.GetSelectedItem(), Is.Not.Null); // Select Uss file name header var header = BuilderTestsHelper.GetHeaderItem(styleSheetsPane); yield return(UIETestEvents.Mouse.SimulateClick(header)); Assert.That(hierarchyTreeView.GetSelectedItem(), Is.Null); }
public IEnumerator EscKeyWillCancelRename() { const string testItemName = "test_name"; AddElementCodeOnly(); var hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(VisualElement)); var documentElement = BuilderTestsHelper.GetLinkedDocumentElement(hierarchyItem); Assert.That(string.IsNullOrEmpty(documentElement.name)); yield return(UIETestEvents.Mouse.SimulateDoubleClick(hierarchyItem)); yield return(UIETestEvents.KeyBoard.SimulateTyping(builder, testItemName)); yield return(UIETestEvents.KeyBoard.SimulateKeyDown(builder, KeyCode.Escape)); // Test that not only the name has not changed to the new value entered... hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(VisualElement)); documentElement = BuilderTestsHelper.GetLinkedDocumentElement(hierarchyItem); Assert.AreNotEqual(documentElement.name, testItemName); // But is also equal to its original name Assert.That(string.IsNullOrEmpty(documentElement.name)); }
public IEnumerator StyleSheetsItemsDeselect() { var styleSheetsTreeView = StyleSheetsPane.Q <TreeView>(); Assert.That(styleSheetsTreeView.GetSelectedItem(), Is.Null); // Create and new selector and select yield return(AddSelector(TestSelectorName)); var selector = BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, TestSelectorName); yield return(UIETestEvents.Mouse.SimulateClick(selector)); Assert.That(styleSheetsTreeView.GetSelectedItem(), Is.Not.Null); yield return(AddVisualElement()); var documentElement = GetFirstDocumentElement(); yield return(UIETestEvents.Mouse.SimulateClick(documentElement)); Assert.That(styleSheetsTreeView.GetSelectedItem(), Is.Null); }
public IEnumerator DragBetweenAndLivePreview() { AddElementCodeOnly(); AddElementCodeOnly(); AddElementCodeOnly <TextField>(); yield return(UIETestHelpers.Pause()); var textFieldCanvas = ViewportPane.documentElement[2]; var firstVisualElementHierarchy = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(VisualElement)); var textFieldHierarchy = BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nameof(TextField)); Assert.That(ViewportPane.documentElement.IndexOf(textFieldCanvas), Is.EqualTo(2)); yield return(UIETestEvents.Mouse.SimulateMouseEvent(BuilderWindow, EventType.MouseDown, textFieldHierarchy.worldBound.center)); var textFieldCenter = textFieldHierarchy.worldBound.center; var veBottomPosition = new Vector2(textFieldCenter.x, firstVisualElementHierarchy.worldBound.yMax); yield return(UIETestEvents.Mouse.SimulateMouseMove(BuilderWindow, textFieldCenter, veBottomPosition)); Assert.That(ViewportPane.documentElement.IndexOf(textFieldCanvas), Is.EqualTo(1)); yield return(UIETestEvents.Mouse.SimulateMouseEvent(BuilderWindow, EventType.MouseUp, veBottomPosition)); }
public IEnumerator ReparentFlowWhenDraggingOntoCSharpTypeElement() { AddElementCodeOnly <TextField>(); AddElementCodeOnly(); yield return(UIETestHelpers.Pause()); var textFieldItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(TextField)); var visualElementItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(VisualElement)); var visualElementDocItem = BuilderTestsHelper.GetLinkedDocumentElement(visualElementItem); yield return(UIETestEvents.Mouse.SimulateDragAndDrop(builder, visualElementItem.worldBound.center, textFieldItem.worldBound.center)); Assert.That(visualElementDocItem.parent, Is.InstanceOf <TextField>()); ForceNewDocument(); AddElementCodeOnly <TextField>(); AddElementCodeOnly(); yield return(UIETestHelpers.Pause()); textFieldItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(TextField)); visualElementItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(VisualElement)); visualElementDocItem = BuilderTestsHelper.GetLinkedDocumentElement(visualElementItem); var textFieldDocItem = BuilderTestsHelper.GetLinkedDocumentElement(textFieldItem); // Need to make it taller to avoid the placement indicator triggering: textFieldDocItem.style.height = 200; yield return(UIETestHelpers.Pause()); yield return(UIETestEvents.Mouse.SimulateDragAndDrop(builder, visualElementItem.worldBound.center, textFieldDocItem.worldBound.center)); Assert.That(visualElementDocItem.parent, Is.InstanceOf <TextField>()); }
public IEnumerator OutsideClickWillCommitRename() { const string testItemName = "test_name"; AddElementCodeOnly(); var hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, nameof(VisualElement)); var documentElement = BuilderTestsHelper.GetLinkedDocumentElement(hierarchyItem); var nameLabel = hierarchyItem.Q <Label>(className: BuilderConstants.ExplorerItemLabelClassName); Assert.That(nameLabel.text, Is.EqualTo(nameof(VisualElement))); Assert.That(nameLabel.classList, Contains.Item(BuilderConstants.ElementTypeClassName)); yield return(UIETestEvents.Mouse.SimulateDoubleClick(hierarchyItem)); yield return(UIETestEvents.KeyBoard.SimulateTyping(builder, testItemName)); yield return(UIETestEvents.Mouse.SimulateClick(viewport)); Assert.That(documentElement.name, Is.EqualTo(testItemName)); hierarchyItem = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, BuilderConstants.UssSelectorNameSymbol + testItemName); nameLabel = hierarchyItem.Q <Label>(className: BuilderConstants.ExplorerItemLabelClassName); Assert.That(nameLabel.classList, Contains.Item(BuilderConstants.ElementNameClassName)); }
protected IEnumerator ReturnToParentDocumentThroughEntryItem(BuilderTestContextualMenuManager menu, string parentString, string parentName = null) { // Go back to root document through 'entry' item context menu BuilderExplorerItem parentRoot; if (parentName != null) { parentRoot = BuilderTestsHelper.GetExplorerItemWithName(hierarchy, parentName); } else { parentRoot = BuilderTestsHelper.GetHeaderItem(hierarchy); } Assert.NotNull(parentRoot); yield return(UIETestEvents.Mouse.SimulateClick(parentRoot, MouseButton.RightMouse)); Assert.That(menu.menuIsDisplayed, Is.True); var parentClick = menu.FindMenuAction(parentString); Assert.That(parentClick, Is.Not.Null); parentClick.Execute(); yield return(UIETestHelpers.Pause(1)); }
internal BuilderExplorerItem GetFirstExplorerVisualElementNode(string nodeName) { return(BuilderTestsHelper.GetExplorerItemWithName(HierarchyPane, nodeName)); }
internal BuilderExplorerItem GetStyleSelectorNodeWithName(string selectorName) { return(BuilderTestsHelper.GetExplorerItemWithName(StyleSheetsPane, selectorName)); }