Example #1
0
        public void AutocompleteStarts()
        {
            LaraUI.InternalContext.Value = Context;
            var x        = new AutocompleteElement();
            var provider = new MyProvider();
            var options  = new AutocompleteOptions
            {
                Provider  = provider,
                AutoFocus = true,
                MinLength = 2,
                Strict    = true
            };

            x.Start(options);
            var doc    = new Document(new MyPage(), 100);
            var bridge = new Mock <IJsBridge>();

            Context.JSBridge = bridge.Object;

            const string code    = "LaraUI.autocompleteApply(context.Payload);";
            var          payload = new AutocompletePayload
            {
                AutoFocus = options.AutoFocus,
                ElementId = x.InnerInput.Id,
                MinLength = options.MinLength,
                Strict    = options.Strict
            };
            var json = LaraUI.JSON.Stringify(payload);

            bridge.Setup(x1 => x1.Submit(code, json));
            doc.Body.AppendChild(x);
            bridge.Verify(x2 => x2.Submit(code, json), Times.Once);
        }
Example #2
0
        public void OnDisconnectStops()
        {
            LaraUI.InternalContext.Value = Context;
            var x        = new AutocompleteElement();
            var provider = new MyProvider();
            var options  = new AutocompleteOptions
            {
                Provider  = provider,
                AutoFocus = true,
                MinLength = 2,
                Strict    = true
            };

            var doc    = new Document(new MyPage(), 100);
            var bridge = new Mock <IJsBridge>();

            Context.JSBridge = bridge.Object;
            doc.Body.AppendChild(x);

            x.Start(options);
            Assert.Equal(1, AutocompleteService.RegisteredCount);
            Assert.Same(options, x.GetOptions());

            x.Remove();
            Assert.Equal(0, AutocompleteService.RegisteredCount);
        }
Example #3
0
        public CountrySelector()
        {
            var auto = new AutocompleteElement
            {
                Class = "form-control"
            };
            var span = new HtmlSpanElement();

            ShadowRoot.Children = new Node[]
            {
                new HtmlDivElement
                {
                    Class    = "form-row mt-3",
                    Children = new Node[]
                    {
                        new HtmlDivElement
                        {
                            Class    = "form-group col-md-3",
                            Children = new Node[]
                            {
                                new HtmlLabelElement
                                {
                                    InnerText = "Select country"
                                },
                                auto
                            }
                        }
                    }
                },
                new HtmlDivElement
                {
                    Class    = "form-row mb-2",
                    Children = new Node[]
                    {
                        new HtmlButtonElement
                        {
                            InnerText = "Show country code",
                            Class     = "btn btn-primary"
                        }
                        .Event("click", () => span.InnerText = auto.Value),
                        new HtmlDivElement
                        {
                            Class    = "ml-2 pt-2",
                            Children = new Node[] { span }
                        }
                    }
                },
            };
            auto.Start(new AutocompleteOptions
            {
                AutoFocus = true,
                MinLength = 2,
                Strict    = true,
                Provider  = this
            });
        }
Example #4
0
        public void InnerInputValue()
        {
            var x = new AutocompleteElement
            {
                Value = "abc"
            };

            Assert.Equal("abc", x.Value);
            Assert.Equal("abc", x.InnerInput.Value);
        }
Example #5
0
        public void RegistryReplacesEntries()
        {
            LaraUI.InternalContext.Value = Context;
            var x     = new AutocompleteRegistry();
            var auto1 = new AutocompleteElement();
            var auto2 = new AutocompleteElement();

            x.Set("a", auto1);
            x.Set("a", auto2);
            Assert.True(x.TryGet("a", out var autoX));
            Assert.Same(auto2, autoX);
        }
Example #6
0
        public async void AutocompleteServiceRun()
        {
            LaraUI.InternalContext.Value = Context;
            var x        = new AutocompleteElement();
            var provider = new MyProvider();
            var options  = new AutocompleteOptions
            {
                Provider  = provider,
                AutoFocus = true,
                MinLength = 2,
                Strict    = true,
            };
            var doc    = new Document(new MyPage(), 100);
            var bridge = new Mock <IJsBridge>();

            Context.JSBridge = bridge.Object;
            doc.Body.AppendChild(x);
            x.Start(options);

            var service = new AutocompleteService();
            var request = new AutocompleteRequest
            {
                Key  = x.AutocompleteId,
                Term = "B"
            };

            Context.RequestBody = LaraUI.JSON.Stringify(request);
            var text = await service.Execute();

            var response = LaraUI.JSON.Parse <AutocompleteResponse>(text);

            Assert.Equal(3, response.Suggestions !.Count);
            var item = response.Suggestions[0];

            Assert.Equal("Red", item.Label);
            Assert.Equal("R", item.Code);
        }