Example #1
0
        public IEnumerator InstructionsAreExpandedAndDisabled_WhenRevisitingCompletedPage()
        {
            using (var automatedWindow = new AutomatedWindow <TutorialWindow>(m_Window))
            {
                // complete criterion, go to next page, and then come back
                firstPageCriterion.Complete(true);
                yield return(null);

                m_Window.RepaintImmediately();
                automatedWindow.Click(FindElementWithText(automatedWindow, nextButtonText, "next button"));
                yield return(null);

                m_Window.RepaintImmediately();
                automatedWindow.Click(FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.backButton, "back button"));
                yield return(null);

                m_Window.RepaintImmediately();

                // instruction should now be expanded and user cannot collapse it
                FindElementWithText(automatedWindow, firstPageInstructionText, "instruction text", Assert.IsNotNull);
                automatedWindow.Click(FindElementWithText(automatedWindow, firstPageInstructionSummary, "instruction summary"));
                yield return(null);

                m_Window.RepaintImmediately();
                FindElementWithText(automatedWindow, firstPageInstructionText, "instruction text", Assert.IsNotNull);
            }
        }
Example #2
0
        public IEnumerator InstructionsAreStyledAsCompleteButNotActive_WhenRevisitingCompletedPage()
        {
            m_Window.RepaintImmediately();

            using (var automatedWindow = new AutomatedWindow <TutorialWindow>(m_Window))
            {
                m_Window.RepaintImmediately();
                // instruction should be styled as active
                FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.activeElementBackground, "active instruction");
                FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.instructionLabelIconNotCompleted, "incomplete instruction icon");

                // complete criterion and ensure it is styled as complete
                firstPageCriterion.Complete(true);
                yield return(null);

                m_Window.RepaintImmediately();
                FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.completedElementBackground, "completed instruction background");
                FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.instructionLabelIconCompleted, "completed instruction icon");

                // go to next page and then come back
                automatedWindow.Click(FindElementWithText(automatedWindow, nextButtonText, "next button"));
                yield return(null);

                m_Window.RepaintImmediately();
                automatedWindow.Click(FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.backButton, "back button"));
                yield return(null);

                m_Window.RepaintImmediately();

                // ensure instruction is still marked as completed
                FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.completedElementBackground, "completed instruction background");
                FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.instructionLabelIconCompleted, "completed instruction icon");
            }
        }
Example #3
0
        public IEnumerator FirstInstructionIsExpandedAndInteractable_WhenPageLoads()
        {
            using (var automatedWindow = new AutomatedWindow <TutorialWindow>(m_Window))
            {
                // yield once so that AnimBool for instruction text can expand
                yield return(null);

                m_Window.RepaintImmediately();

                // instruction should be expanded by default
                FindElementWithText(automatedWindow, firstPageInstructionText, "instruction text", Assert.IsNotNull);

                // ensure text can be collapsed
                automatedWindow.Click(FindElementWithText(automatedWindow, firstPageInstructionSummary, "instruction summary"));
                yield return(null);

                m_Window.RepaintImmediately();
                // wait for anim bool to expand
                var expandSpeed = defaultAnimBoolSpeed;
                var prevTime    = DateTime.Now;
                var expanded    = 0f;
                while (expanded < 1f)
                {
                    expanded += (float)(DateTime.Now - prevTime).TotalSeconds * expandSpeed;
                    prevTime  = DateTime.Now;
                    yield return(null);
                }
                yield return(null);

                FindElementWithText(automatedWindow, firstPageInstructionText, "instruction text", Assert.IsNull);
            }
        }
Example #4
0
        static IAutomatedUIElement FindElementWithStyle(AutomatedWindow <TutorialWindow> automatedWindow, GUIStyle style, string elementName)
        {
            var result = automatedWindow.FindElementsByGUIStyle(style).FirstOrDefault();

            Assert.IsNotNull(result, string.Format("Finding {0} with expected style: {1}", elementName, style));
            return(result);
        }
Example #5
0
        static IAutomatedUIElement FindElementWithText(AutomatedWindow <TutorialWindow> automatedWindow, string text, string elementName, Action <object, string, object[]> assert = null)
        {
            var result = automatedWindow.FindElementsByGUIContent(new GUIContent(text)).LastOrDefault();

            assert = assert ?? Assert.IsNotNull;
            assert(result, string.Format("Finding {0} with expected text: \"{1}\"", elementName, text), null);
            return(result);
        }
Example #6
0
        public IEnumerator ApplyMasking_ToAllViewsExceptTutorialWindowAndTooltips_WhenRevisitingCompletedPage()
        {
            firstPage.m_Paragraphs[0].maskingSettings.SetUnmaskedViews(new[] { UnmaskedView.CreateInstanceForGUIView <Toolbar>() });
            firstPage.m_Paragraphs[0].maskingSettings.enabled = true;
            firstPage.RaiseTutorialPageMaskingSettingsChangedEvent();

            firstPageCriterion.Complete(true);

            m_Window.RepaintImmediately();

            List <GUIView> views = new List <GUIView>();

            GUIViewDebuggerHelper.GetViews(views);

            // masking of final instruction still applied when it is complete
            var rects = new List <Rect>();

            foreach (var view in views)
            {
                if (view == m_Window.m_Parent || view == Toolbar.get || view is TooltipView)
                {
                    Assert.IsFalse(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
                else
                {
                    Assert.IsTrue(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
            }

            using (var automatedWindow = new AutomatedWindow <TutorialWindow>(m_Window))
            {
                m_Window.RepaintImmediately();

                // go to next page and then come back
                automatedWindow.Click(FindElementWithText(automatedWindow, nextButtonText, "next button"));
                yield return(null);

                m_Window.RepaintImmediately();
                automatedWindow.Click(FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.backButton, "back button"));
                yield return(null);

                m_Window.RepaintImmediately();
            }

            // now only tutorial window should be unmasked
            foreach (var view in views)
            {
                if (view == m_Window.m_Parent || view is TooltipView)
                {
                    Assert.IsFalse(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
                else
                {
                    Assert.IsTrue(MaskingManager.IsMasked(new GUIViewProxy(view), rects));
                }
            }
        }
        public IEnumerator CanClickNextButton_WhenRevistingCompletedPage_WhenItsCriteriaHaveBeenLaterInvalidated()
        {
            using (var automatedWindow = new AutomatedWindow <TutorialWindow>(m_Window))
            {
                m_Window.RepaintImmediately();

                // next button should be disabled
                automatedWindow.Click(FindElementWithText(automatedWindow, nextButtonText, "next button"));
                yield return(null);

                m_Window.RepaintImmediately();
                Assert.AreEqual(firstPage, m_Window.currentTutorial.CurrentPage);

                // complete criterion; next button should now be enabled
                firstPageCriterion.Complete(true);
                yield return(null);

                m_Window.RepaintImmediately();
                automatedWindow.Click(FindElementWithText(automatedWindow, nextButtonText, "next button"));
                yield return(null);

                m_Window.RepaintImmediately();
                Assert.AreEqual(secondPage, m_Window.currentTutorial.CurrentPage);

                // go back
                // TODO Broken as allTutorialStyles was removed in IET 2.0.
                automatedWindow.Click(FindElementWithStyle(automatedWindow, null /*m_Window.allTutorialStyles.backButton*/, "back button"));
                yield return(null);

                m_Window.RepaintImmediately();
                Assert.AreEqual(firstPage, m_Window.currentTutorial.CurrentPage);

                // invalidate criterion; next button should still be enabled
                firstPageCriterion.Complete(false);
                automatedWindow.Click(FindElementWithText(automatedWindow, nextButtonText, "next button"));
                yield return(null);

                m_Window.RepaintImmediately();
                Assert.AreEqual(secondPage, m_Window.currentTutorial.CurrentPage);
            }
        }
Example #8
0
        public IEnumerator ClickingBackButton_WhenPreviousPageHasAutoAdvanceOnCompleteSet_MovesToPreviousPage()
        {
            // let first page auto-advance on completion
            firstPage.autoAdvanceOnComplete = true;

            using (var automatedWindow = new AutomatedWindow <TutorialWindow>(m_Window))
            {
                m_Window.RepaintImmediately();

                // complete criterion and auto-advance to next page, then press back button to come back
                firstPageCriterion.Complete(true);
                yield return(null);

                m_Window.RepaintImmediately();
                automatedWindow.Click(FindElementWithStyle(automatedWindow, m_Window.allTutorialStyles.backButton, "back button"));
                yield return(null);

                m_Window.RepaintImmediately();

                // we should now be back at the first page again
                Assert.AreEqual(firstPage, m_Window.currentTutorial.currentPage);
            }
        }
        public IEnumerator TestGetViewsAndRects_ForSerializedPropertyInInspector_WhenParentPropertyIsCollapsed(
            bool parentPropertyExpanded, bool expectedFoundAncestorProperty)
        {
            var testObject = new GameObject("TestGetViewsAndRects_ForContractedPropertyInInspector",
                                            typeof(TestComponents.ComponentWithNestedValues));

            Selection.activeObject = testObject;
            try
            {
                var serializedObject = new SerializedObject(testObject.GetComponent <TestComponents.ComponentWithNestedValues>());
                var parentProperty   = serializedObject.FindProperty("componentWithNestedValuesFieldA");
                var childProperty    = serializedObject.FindProperty(
                    "componentWithNestedValuesFieldA.componentWithNestedValuesFieldB");

                Assert.That(parentProperty, Is.Not.Null);
                Assert.That(childProperty, Is.Not.Null);

                parentProperty.isExpanded = parentPropertyExpanded;
                serializedObject.ApplyModifiedProperties();

                var inspectorWindow = EditorWindow.GetWindow <InspectorWindow>();

                Rect labelRectOfExpectedFoundProperty;
                using (var automatedWindow = new AutomatedWindow <InspectorWindow>(inspectorWindow))
                {
                    inspectorWindow.Repaint();
                    yield return(null);

                    if (expectedFoundAncestorProperty)
                    {
                        var parentElements = automatedWindow.FindElementsByGUIContent(
                            new GUIContent("Component With Nested Values Field A"));
                        Assert.That(parentElements.Count(), Is.EqualTo(1));
                        labelRectOfExpectedFoundProperty = parentElements.Single().rect;
                    }
                    else
                    {
                        var childElements = automatedWindow.FindElementsByGUIContent(
                            new GUIContent("Component With Nested Values Field B"));
                        Assert.That(childElements.Count(), Is.EqualTo(1));
                        labelRectOfExpectedFoundProperty = childElements.Single().rect;
                    }
                }

                var unmaskedViews = new[] {
                    UnmaskedView.CreateInstanceForEditorWindow <InspectorWindow>(
                        new[] {
                        new GUIControlSelector()
                        {
                            selectorMode = GUIControlSelector.Mode.Property,
                            targetType   = typeof(TestComponents.ComponentWithNestedValues),
                            propertyPath = "componentWithNestedValuesFieldA.componentWithNestedValuesFieldB"
                        }
                    }
                        )
                };

                bool foundAncestorProperty;
                var  viewsAndRects = UnmaskedView.GetViewsAndRects(unmaskedViews, out foundAncestorProperty)
                                     .m_MaskData;

                Assert.That(foundAncestorProperty, Is.EqualTo(expectedFoundAncestorProperty));
                Assert.That(viewsAndRects.Count, Is.EqualTo(1), "Did not find one view for the Inspector");

                var rects = viewsAndRects.Values.First().rects;
                Assert.That(rects.Count, Is.EqualTo(1),
                            "Did not find exactly one control for the SerializedPropert " +
                            "componentWithNestedValuesFieldA.componentWithNestedValuesFieldB for ComponentWithNestedValues");

                var rect = rects.Single();
                Assert.That(rect.yMin, Is.GreaterThanOrEqualTo(labelRectOfExpectedFoundProperty.yMin),
                            "Found property rect does not contain of label rect of expected found property");
                Assert.That(rect.yMax, Is.LessThanOrEqualTo(labelRectOfExpectedFoundProperty.yMax),
                            "Found property rect does not contain of label rect of expected found property");
            }
            finally
            {
                UnityEngine.Object.DestroyImmediate(testObject);
            }
        }