public virtual void Setup() { if (EditorApplication.isPlaying) { BuilderWindow = EditorWindow.GetWindow <Builder>(); } else { BuilderWindow = BuilderTestsHelper.MakeNewBuilderWindow(); } Selection = BuilderWindow.selection; Canvas = BuilderWindow.rootVisualElement.Q <BuilderCanvas>(); LibraryPane = BuilderWindow.rootVisualElement.Q <BuilderLibrary>(); HierarchyPane = BuilderWindow.rootVisualElement.Q <BuilderHierarchy>(); StyleSheetsPane = BuilderWindow.rootVisualElement.Q <BuilderStyleSheets>(); ViewportPane = BuilderWindow.rootVisualElement.Q <BuilderViewport>(); InspectorPane = BuilderWindow.rootVisualElement.Q <BuilderInspector>(); if (EditorApplication.isPlaying) { return; } BuilderProjectSettings.Reset(); ForceNewDocument(); var createSelectorField = StyleSheetsPane.Q <TextField>(); createSelectorField.visualInput.Blur(); LibraryPane.SetViewMode(BuilderLibrary.LibraryViewMode.TreeView); }
public IEnumerator SelectorNameValidation() { var createSelectorField = StyleSheetsPane.Q <TextField>(); createSelectorField.visualInput.Focus(); yield return(UIETestEvents.KeyBoard.SimulateTyping(BuilderWindow, "invalid%%selector@$name")); yield return(UIETestEvents.KeyBoard.SimulateKeyDown(BuilderWindow, KeyCode.Return)); yield return(UIETestHelpers.Pause(2)); Assert.That(createSelectorField.text, Is.EqualTo(".invalid%%selector@$name")); // 1 because title is BuilderExplorerItem as well. So 1 means empty in this context Assert.That(StyleSheetsPane.Query <BuilderExplorerItem>().ToList().Count, Is.EqualTo(1)); // Test that we haven't lost field focus and can type valid name. yield return(UIETestEvents.KeyBoard.SimulateTyping(BuilderWindow, TestSelectorName)); yield return(UIETestEvents.KeyBoard.SimulateKeyDown(BuilderWindow, KeyCode.Return)); var explorerItems = BuilderTestsHelper.GetExplorerItemsWithName(StyleSheetsPane, TestSelectorName); Assert.That(explorerItems.Count, Is.EqualTo(1)); }
protected IEnumerator AddSelector(string selectorName) { // TODO: No idea why but the artificial way of adding selectors with AddSelector() produces // selector elements that have no layout. I don't know why they don't layout even // though they are part of the hierarchy and have a panel! The Inspector remains blank because // it needs elements to be layed out. var builderWindow = BuilderWindow; var inputField = StyleSheetsPane.Q <TextField>(className: BuilderNewSelectorField.s_TextFieldUssClassName); inputField.visualInput.Focus(); // Make yield return(UIETestEvents.KeyBoard.SimulateTyping(builderWindow, selectorName)); // TODO: I noticed many times the same key events being sent again (twice). yield return(UIETestEvents.KeyBoard.SimulateKeyDown(builderWindow, KeyCode.Return)); // TODO: This does not always fire. Most of the time, the Blur event never makes // it to the control. inputField.visualInput.Blur(); yield return(UIETestHelpers.Pause(1)); }
public IEnumerator SelectSelectorWithRowAndPillClick() { yield return(AddSelector(TestSelectorName)); var stylesTreeView = StyleSheetsPane.Q <TreeView>(); Assert.That(stylesTreeView.GetSelectedItem(), Is.Null); //Select by clicking on the row var createdSelector = GetStyleSelectorNodeWithName(TestSelectorName); yield return(UIETestEvents.Mouse.SimulateClick(createdSelector)); Assert.That(stylesTreeView.GetSelectedItem(), Is.Not.Null); //Deselect yield return(UIETestEvents.Mouse.SimulateClick(StyleSheetsPane)); Assert.That(stylesTreeView.GetSelectedItem(), Is.Null); //Select by clicking on the style class pill yield return(UIETestEvents.Mouse.SimulateClick(createdSelector.Q <Label>())); Assert.That(stylesTreeView.GetSelectedItem(), Is.Not.Null); }
public IEnumerator CreateSelectorFieldBehaviour() { var createSelectorField = StyleSheetsPane.Q <TextField>(); createSelectorField.visualInput.Blur(); Assert.That(createSelectorField.text, Is.EqualTo(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage)); createSelectorField.visualInput.Focus(); Assert.That(createSelectorField.text, Is.EqualTo(".")); Assert.That(createSelectorField.cursorIndex, Is.EqualTo(1)); yield return(UIETestEvents.KeyBoard.SimulateTyping(BuilderWindow, TestSelectorName)); yield return(UIETestEvents.KeyBoard.SimulateKeyDown(BuilderWindow, KeyCode.Return)); createSelectorField.visualInput.Blur(); var newSelector = BuilderTestsHelper.GetExplorerItemsWithName(StyleSheetsPane, TestSelectorName); Assert.That(newSelector, Is.Not.Null); createSelectorField.visualInput.Focus(); yield return(UIETestEvents.KeyBoard.SimulateTyping(BuilderWindow, TestSelectorName2)); var addButton = StyleSheetsPane.Query <Button>().Where(b => b.text.Equals("Add")).First(); yield return(UIETestEvents.Mouse.SimulateClick(addButton)); newSelector = BuilderTestsHelper.GetExplorerItemsWithName(StyleSheetsPane, TestSelectorName2); Assert.That(newSelector, Is.Not.Null); }
public IEnumerator NewSelectorWithNoUSSCreatesNewUSS() { AddElementCodeOnly("TestElement"); var createSelectorField = StyleSheetsPane.Q <TextField>(); createSelectorField.visualInput.Blur(); Assert.That(createSelectorField.text, Is.EqualTo(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage)); createSelectorField.visualInput.Focus(); Assert.That(createSelectorField.text, Is.EqualTo(".")); Assert.That(createSelectorField.cursorIndex, Is.EqualTo(1)); bool hasSaveDialogBeenOpened = false; BuilderStyleSheetsUtilities.s_SaveFileDialogCallback = () => { hasSaveDialogBeenOpened = true; return(k_TestUSSFilePath); }; yield return(UIETestEvents.KeyBoard.SimulateTyping(BuilderWindow, ".new-selector")); yield return(UIETestEvents.KeyBoard.SimulateKeyDown(BuilderWindow, KeyCode.Return)); Assert.That(hasSaveDialogBeenOpened, Is.True); yield return(UIETestHelpers.Pause(1)); var unityButtonSelectors = BuilderTestsHelper.GetExplorerItemsWithName(StyleSheetsPane, ".new-selector"); Assert.That(unityButtonSelectors.Count, Is.EqualTo(1)); }
public IEnumerator AddExistingUSSViaPlusMenu() { AddElementCodeOnly("TestElement"); var addMenu = StyleSheetsPane.Q <ToolbarMenu>("add-uss-menu"); var addMenuItems = addMenu.menu.MenuItems(); Assert.AreEqual(addMenuItems.Count, 2); var actionMenuItem = addMenuItems[1] as DropdownMenuAction; Assert.AreEqual(actionMenuItem.name, BuilderConstants.ExplorerStyleSheetsPaneAddExistingUSSMenu); bool hasOpenDialogBeenOpened = false; BuilderStyleSheetsUtilities.s_OpenFileDialogCallback = () => { hasOpenDialogBeenOpened = true; return(k_ColorsTestUSSPath); }; actionMenuItem.Execute(); Assert.That(hasOpenDialogBeenOpened, Is.True); yield return(UIETestHelpers.Pause(1)); var newUSSExplorerItems = BuilderTestsHelper.GetExplorerItemsWithName(StyleSheetsPane, k_ColorsTestUSSFileName); Assert.That(newUSSExplorerItems.Count, Is.EqualTo(1)); }
protected IEnumerator AddSelector(string selectorName) { var builderWindow = BuilderWindow; var inputField = StyleSheetsPane.Q <TextField>(); inputField.visualInput.Focus(); // Make yield return(UIETestEvents.KeyBoard.SimulateTyping(builderWindow, selectorName)); yield return(UIETestEvents.KeyBoard.SimulateKeyDown(builderWindow, KeyCode.Return)); }
public void SelectorCheatsheetTooltip() { var builderTooltipPreview = BuilderWindow.rootVisualElement.Q <BuilderTooltipPreview>("stylesheets-pane-tooltip-preview"); var builderTooltipPreviewEnabler = builderTooltipPreview.Q <VisualElement>(BuilderTooltipPreview.s_EnabledElementName); var createSelectorField = StyleSheetsPane.Q <TextField>(); createSelectorField.visualInput.Focus(); Assert.That(builderTooltipPreviewEnabler, Style.Display(DisplayStyle.Flex)); createSelectorField.visualInput.Blur(); Assert.That(builderTooltipPreviewEnabler, Style.Display(DisplayStyle.None)); }
public virtual void Setup() { BuilderWindow = BuilderTestsHelper.MakeNewBuilderWindow(); LibraryPane = BuilderWindow.rootVisualElement.Q <BuilderLibrary>(); HierarchyPane = BuilderWindow.rootVisualElement.Q <BuilderHierarchy>(); StyleSheetsPane = BuilderWindow.rootVisualElement.Q <BuilderStyleSheets>(); ViewportPane = BuilderWindow.rootVisualElement.Q <BuilderViewport>(); InspectorPane = BuilderWindow.rootVisualElement.Q <BuilderInspector>(); ForceNewDocument(); var createSelectorField = StyleSheetsPane.Q <TextField>(); createSelectorField.visualInput.Blur(); }
public void SelectorCheatsheetTooltip() { var builderTooltipPreview = BuilderWindow.rootVisualElement.Q <BuilderTooltipPreview>("stylesheets-pane-tooltip-preview"); var builderTooltipPreviewEnabler = builderTooltipPreview.Q <VisualElement>(BuilderTooltipPreview.s_EnabledElementName); var createSelectorField = StyleSheetsPane.Q <TextField>(className: BuilderNewSelectorField.s_TextFieldUssClassName); // Everything StyleSheet is disabled now if there are no elements to contain the <Style> tag. Assert.That(createSelectorField.enabledInHierarchy, Is.False); AddElementCodeOnly("TestElement"); Assert.That(createSelectorField.enabledInHierarchy, Is.True); createSelectorField.visualInput.Focus(); Assert.That(builderTooltipPreviewEnabler, Style.Display(DisplayStyle.Flex)); createSelectorField.visualInput.Blur(); Assert.That(builderTooltipPreviewEnabler, Style.Display(DisplayStyle.None)); }
public IEnumerator HoveringOverElementsHighlightsMatchingStyleSheets() { yield return(EnsureSelectorsCanBeAddedAndReloadBuilder()); yield return(AddSelector(k_TestStyleName)); yield return(UIETestHelpers.Pause()); AddElementCodeOnly <Button>(); var element = ViewportPane.canvas.Q <Button>(); element.AddToClassList(k_TestStyleName); var selectorBackground = StyleSheetsPane.Q(null, "unity-scroll-view__content-container").Children().ToList()[1]; var oldColor = selectorBackground.resolvedStyle.backgroundColor; yield return(UIETestEvents.Mouse.SimulateClick(InspectorPane)); yield return(UIETestEvents.Mouse.SimulateMouseMove(BuilderWindow, InspectorPane.worldBound.center, element.worldBound.center)); Assert.That(selectorBackground.resolvedStyle.backgroundColor, Is.Not.EqualTo(oldColor)); }
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 CreateSelectorFieldBehaviour() { yield return(EnsureSelectorsCanBeAddedAndReloadBuilder()); var createSelectorField = StyleSheetsPane.Q <TextField>(); createSelectorField.visualInput.Blur(); Assert.That(createSelectorField.text, Is.EqualTo(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage)); createSelectorField.visualInput.Focus(); Assert.That(createSelectorField.text, Is.EqualTo(".")); Assert.That(createSelectorField.cursorIndex, Is.EqualTo(1)); yield return(UIETestEvents.KeyBoard.SimulateTyping(BuilderWindow, TestSelectorName)); yield return(UIETestEvents.KeyBoard.SimulateKeyDown(BuilderWindow, KeyCode.Return)); createSelectorField.visualInput.Blur(); var newSelector = BuilderTestsHelper.GetExplorerItemsWithName(StyleSheetsPane, TestSelectorName); Assert.That(newSelector, Is.Not.Null); }