diff --git a/test/Microsoft.Blazor.E2ETest/Tests/ComponentRenderingTest.cs b/test/Microsoft.Blazor.E2ETest/Tests/ComponentRenderingTest.cs index 45dae498ac..878320c70a 100644 --- a/test/Microsoft.Blazor.E2ETest/Tests/ComponentRenderingTest.cs +++ b/test/Microsoft.Blazor.E2ETest/Tests/ComponentRenderingTest.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; using BasicTestApp; using Microsoft.Blazor.Components; using Microsoft.Blazor.E2ETest.Infrastructure; @@ -86,8 +87,30 @@ namespace Microsoft.Blazor.E2ETest.Tests // TODO: Once we remove the wrapper elements from around child components, // assert that the child component text node is directly inside the
- Assert.Equal("Child component", - appElement.FindElement(By.CssSelector("fieldset > blazor-component")).Text); + var childComponentWrapper = appElement.FindElement(By.CssSelector("fieldset > blazor-component")); + Assert.Single(childComponentWrapper.FindElements(By.CssSelector("*"))); + + var styledElement = childComponentWrapper.FindElement(By.TagName("h1")); + Assert.Equal("Hello, world!", styledElement.Text); + Assert.Equal("color: red;", styledElement.GetAttribute("style")); + Assert.Equal("somevalue", styledElement.GetAttribute("customattribute")); + } + + [Fact] + public void CanTriggerEventsOnChildComponents() + { + var childComponentWrapper = MountTestComponent() + .FindElements(By.CssSelector("blazor-component")).Single(); + + Assert.Equal( + "Current count: 0", + childComponentWrapper.FindElement(By.TagName("p")).Text); + + childComponentWrapper.FindElement(By.TagName("button")).Click(); + + Assert.Equal( + "Current count: 1", + childComponentWrapper.FindElement(By.TagName("p")).Text); } private IWebElement MountTestComponent() where TComponent: IComponent diff --git a/test/testapps/BasicTestApp/CounterComponentWrapper.cshtml b/test/testapps/BasicTestApp/CounterComponentWrapper.cshtml new file mode 100644 index 0000000000..6501270836 --- /dev/null +++ b/test/testapps/BasicTestApp/CounterComponentWrapper.cshtml @@ -0,0 +1,7 @@ +

Counter wrapper

+ +This is the parent component. Here comes the counter: + + + +Finished. diff --git a/test/testapps/BasicTestApp/ParentChildComponent.cs b/test/testapps/BasicTestApp/ParentChildComponent.cs deleted file mode 100644 index 10b8be8aed..0000000000 --- a/test/testapps/BasicTestApp/ParentChildComponent.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Blazor.Components; -using Microsoft.Blazor.RenderTree; - -namespace BasicTestApp -{ - public class ParentChildComponent : IComponent - { - public void BuildRenderTree(RenderTreeBuilder builder) - { - builder.OpenElement(0, "fieldset"); - builder.OpenElement(1, "legend"); - builder.AddText(2, "Parent component"); - builder.CloseElement(); - builder.AddComponentElement(3); - builder.CloseElement(); - builder.CloseElement(); - } - - private class ChildComponent : IComponent - { - public void BuildRenderTree(RenderTreeBuilder builder) - { - builder.AddText(0, "Child component"); - } - } - } -} diff --git a/test/testapps/BasicTestApp/ParentChildComponent.cshtml b/test/testapps/BasicTestApp/ParentChildComponent.cshtml new file mode 100644 index 0000000000..0577adfe19 --- /dev/null +++ b/test/testapps/BasicTestApp/ParentChildComponent.cshtml @@ -0,0 +1,4 @@ +
+ Parent component + +