Пример #1
0
        public void TestRedrawOnChangeProps()
        {
            // <PropsChangeTestComponent Id="1">
            // </PropsChangeTestComponent>

            const string id = "1";

            var rootBlueprint = ComponentBlueprint.From <PropsChangeTestComponent, PropsChangeTestComponentProps>(new PropsChangeTestComponentProps
            {
                Id = id,
            });

            var document   = new TestHtmlDocument();
            var renderer   = new DomRenderer(document);
            var renderNode = renderer.Mount(rootBlueprint);

            var expected = "<div id=\"1\"></div>";

            Assert.AreEqual(renderNode.RootNodes[0].ToString(), expected);

            var childrenString = "";

            for (var i = 0; i < 10; i += 1)
            {
                PropsChangeTestComponent.IncreaseLength(id);

                childrenString += $"<div id=\"1-{i + 1}\"></div>";
                expected        = $"<div id=\"1\">{childrenString}</div>";
                Assert.AreEqual(renderNode.RootNodes[0].ToString(), expected);
            }
        }
Пример #2
0
        public void TestMethod1()
        {
            // <div style="1">
            //   <div style="2"></div>
            // </div>

            var rootBlueprint = ComponentBlueprint.From <DivComponent, DivComponentProps>(new DivComponentProps
            {
                Style    = "1",
                Children = new Blueprint[]
                {
                    ComponentBlueprint.From <DivComponent, DivComponentProps>(new DivComponentProps
                    {
                        Style = "2"
                    }),
                },
            });

            var document    = new TestHtmlDocument();
            var renderer    = new DomRenderer(document);
            var htmlElement = renderer.Mount(rootBlueprint).RootNodes[0];

            var expected = "<div style=\"1\"><div style=\"2\"></div></div>";

            Assert.AreEqual(htmlElement.ToString(), expected);
        }
Пример #3
0
        public override ComponentBlueprint Render()
        {
            var style = State.IsClicked
                ? $"{Props.Style} clicked"
                : Props.Style;

            return(ComponentBlueprint.From <DivComponent, DivComponentProps>(new DivComponentProps
            {
                Style = style,
                Children = Props.Children,
            }));
        }
Пример #4
0
            public override ComponentBlueprint Render()
            {
                var children = new List <ComponentBlueprint>();

                for (var i = 0; i < this.State.Length; i += 1)
                {
                    children.Add(ComponentBlueprint.From <DivComponent, DivComponentProps>(new DivComponentProps
                    {
                        Id = $"{Props.Id}-{i + 1}",
                    }));
                }

                return(ComponentBlueprint.From <DivComponent, DivComponentProps>(new DivComponentProps
                {
                    Id = Props.Id,
                    Children = children.ToArray(),
                }));
            }
Пример #5
0
        public void TestTextNodeChild()
        {
            // <div>"abc"</div>

            var rootBlueprint = ComponentBlueprint.From <DivComponent, DivComponentProps>(new DivComponentProps
            {
                Children = new Blueprint[]
                {
                    new ValueBlueprint("abc"),
                },
            });

            var document    = new TestHtmlDocument();
            var renderer    = new DomRenderer(document);
            var htmlElement = renderer.Mount(rootBlueprint).RootNodes[0];

            var expected = @"<div>abc</div>";

            Assert.AreEqual(htmlElement.ToString(), expected);
        }
Пример #6
0
        public void TestRedrawOnChangeState()
        {
            // <MyComponent style="1" id="first">
            //   <MyComponent style="2" id="second"></MyComponent>
            // </MyComponent>

            // <div style="1">
            //   <div style="2"></div>
            // </div>

            var rootBlueprint = ComponentBlueprint.From <MyComponent, MyComponentProps>(new MyComponentProps
            {
                Style    = "1",
                Id       = "first",
                Children = new Blueprint[]
                {
                    ComponentBlueprint.From <MyComponent, MyComponentProps>(new MyComponentProps
                    {
                        Style = "2",
                        Id    = "second",
                    }),
                },
            });


            var document   = new TestHtmlDocument();
            var renderer   = new DomRenderer(document);
            var renderNode = renderer.Mount(rootBlueprint);

            var expected = "<div style=\"1\"><div style=\"2\"></div></div>";

            Assert.AreEqual(renderNode.RootNodes[0].ToString(), expected);

            MyComponent.Click("first");

            expected = "<div style=\"1 clicked\"><div style=\"2\"></div></div>";
            Assert.AreEqual(renderNode.RootNodes[0].ToString(), expected);
        }