Change ParentChildComponent test to use Razor. Add E2E tests showing events on child components work.
This commit is contained in:
parent
2107a1927f
commit
23c2816bcd
|
|
@ -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 <fieldset>
|
||||
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<CounterComponentWrapper>()
|
||||
.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<TComponent>() where TComponent: IComponent
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<h1>Counter wrapper</h1>
|
||||
|
||||
This is the parent component. Here comes the counter:
|
||||
|
||||
<c:CounterComponent />
|
||||
|
||||
Finished.
|
||||
|
|
@ -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<ChildComponent>(3);
|
||||
builder.CloseElement();
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
private class ChildComponent : IComponent
|
||||
{
|
||||
public void BuildRenderTree(RenderTreeBuilder builder)
|
||||
{
|
||||
builder.AddText(0, "Child component");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<fieldset>
|
||||
<legend>Parent component</legend>
|
||||
<c:RedTextComponent />
|
||||
</fieldset>
|
||||
Loading…
Reference in New Issue