Beispiel #1
0
        public void Search_PropertiesBackendSkipFilterTokens(string input)
        {
            var searchElement = new SearchElement();

            searchElement.RegisterSearchBackend(CreateSearchBackend <EquatableAndComparableTestData>(SearchBackendType.Properties));

            var sourceData = new[]
            {
                new EquatableAndComparableTestData {
                    Name = "hello"
                },
                new EquatableAndComparableTestData {
                    Name = "hola"
                },
            };

            EquatableAndComparableTestData[] filtered = null;

            searchElement.RegisterSearchQueryHandler <EquatableAndComparableTestData>(q => filtered = q.Apply(sourceData).ToArray());
            searchElement.AddSearchDataProperty(new PropertyPath(nameof(EquatableAndComparableTestData.Name)));
            searchElement.AddSearchFilterPopupItem("c", "component type");

            searchElement.Search(input);
            Assert.That(filtered, Is.EquivalentTo(sourceData));
        }
Beispiel #2
0
        public void SearchElementPerformance_WithNoSearchData()
        {
            var searchElement = new SearchElement {
                SearchDelay = 0, GlobalStringComparison = StringComparison.Ordinal
            };

            var originalData = Generate(100000);
            var filteredData = new List <TestData>();

            searchElement.RegisterSearchQueryHandler <TestData>(search =>
            {
                foreach (var element in search.Apply(originalData))
                {
                    filteredData.Add(element);
                }
            });

            Measure.Method(() =>
            {
                searchElement.Search("Mat");
            })
            .WarmupCount(1)
            .MeasurementCount(1)
            .Run();

            Assert.That(filteredData.Count, Is.EqualTo(0));
        }
Beispiel #3
0
        public void Search_TokensShouldBeEmptyOnEmptySearchString(SearchBackendType backendType)
        {
            var searchElement = new SearchElement();

            searchElement.RegisterSearchBackend(CreateSearchBackend <TestData>(backendType));

            searchElement.RegisterSearchQueryHandler <TestData>(q =>
            {
                Assert.DoesNotThrow(() =>
                {
                    var i = q.Tokens.Count;
                });
            });
            searchElement.AddSearchDataProperty(new PropertyPath(nameof(TestData.Name)));

            searchElement.Search(string.Empty);
            searchElement.Search(null);
            searchElement.Search("   ");
        }
Beispiel #4
0
        public void Search_WithValidBindings_ResultsAreWrittenToDestinationData()
        {
            var container = new TestDataContainer
            {
                ValidSourceData      = Generate(100),
                ValidDestinationData = new List <TestData>()
            };

            m_PropertyElement.SetTarget(container);
            m_SearchElement.RegisterSearchQueryHandler(m_PropertyElement, TestDataContainer.ValidSourceDataPath, TestDataContainer.ValidDestinationDataPath);
            m_SearchElement.AddSearchDataProperty(new PropertyPath("Name"));

            Assert.That(container.ValidDestinationData.Count, Is.EqualTo(0));

            m_SearchElement.Search("");
            Assert.That(container.ValidDestinationData.Count, Is.EqualTo(container.ValidSourceData.Length));

            m_SearchElement.Search("Mesh");
            Assert.That(container.ValidDestinationData.Count, Is.EqualTo(25));
        }
        public override VisualElement Build()
        {
            var context = GetContext <Explorer.Context>();

            context.NewPropertyBagsDetected += () =>
            {
                m_ListView.Refresh();
                m_SearchElement.Search();
                m_ListView.selectedIndex = string.IsNullOrEmpty(m_SearchElement.value)
                    ? PropertyBagDebugInfoStore.IndexOf(context.SelectedType)
                    : Target.FindIndex(pbd => pbd.Type == context.SelectedType);
            };
            var root = Resources.Templates.Explorer.PropertyBagList.CloneWithoutTemplateContainer();

            m_SearchElement = root.Q <SearchElement>(className: k_Search);
            m_SearchElement.RegisterCallback <ChangeEvent <string>, Explorer.Context>(
                (evt, ctx) => ctx.StringSearch = evt.newValue, context);
            m_SearchElement.RegisterSearchQueryHandler <PropertyBagDebugInfo>(search =>
            {
                Target.Clear();
                Target.AddRange(search.Apply(PropertyBagDebugInfoStore.AllDebugInfos));
                m_ListView.Refresh();
                m_ListView.selectedIndex = string.IsNullOrEmpty(m_SearchElement.value)
                    ? PropertyBagDebugInfoStore.IndexOf(context.SelectedType)
                    : Target.FindIndex(pbd => pbd.Type == context.SelectedType);
            });

            m_ListView = root.Q <ListView>(className: k_ListView);
            m_ListView.selectionType = SelectionType.Single;
            m_ListView.itemsSource   = Target;
            m_ListView.makeItem      = () =>
            {
                var element = new TypeNameLabel();
                element.style.paddingLeft = 15;
                return(element);
            };
            m_ListView.bindItem = (element, i) =>
            {
                if (element is TypeNameLabel typeName)
                {
                    typeName.value = Target[i].Type;
                }
            };

            m_SearchElement.value = context.StringSearch;

            context.Update();
            m_ListView.selectedIndex = string.IsNullOrEmpty(m_SearchElement.value)
                ? PropertyBagDebugInfoStore.IndexOf(context.SelectedType)
                : Target.FindIndex(pbd => pbd.Type == context.SelectedType);

            context.OnPropertyBagSelected += detail =>
            {
                context.Update();
                m_ListView.selectedIndex = string.IsNullOrEmpty(m_SearchElement.value)
                    ? PropertyBagDebugInfoStore.IndexOf(context.SelectedType)
                    : Target.FindIndex(pbd => pbd.Type == context.SelectedType);
                m_ListView.ScrollToItem(m_ListView.selectedIndex);
            };

            m_ListView.onSelectionChange += objects =>
            {
                foreach (var obj in objects)
                {
                    if (obj is PropertyBagDebugInfo detail)
                    {
                        context.SelectPropertyBag(detail);
                        return;
                    }
                }
            };

            return(root);
        }