Update components E2E test to use splatting (#11518)

This test was already in place, and just needs some updates to work with
Razor syntax instead of .cs
This commit is contained in:
Ryan Nowak 2019-06-25 10:06:16 -07:00 committed by Pranav K
parent eba671ec88
commit 550710f304
3 changed files with 23 additions and 43 deletions

View File

@ -7,18 +7,12 @@
<div id="duplicate-on-element-override">
<DuplicateAttributesOnElementChildComponent
BoolAttributeBefore="true"
StringAttributeBefore="original-text"
UnmatchedValues="@elementValues"
BoolAttributeAfter="false"
StringAttributeAfter="other-text" />
</div>
@functions {
void SomeMethod()
{
}
Dictionary<string, object> elementValues = new Dictionary<string, object>()
{
{ "bool", true },

View File

@ -1,37 +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 System.Collections.Generic;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.RenderTree;
namespace BasicTestApp
{
// Written in C# for flexibility and because we don't currently have the ability to write this in .razor.
public class DuplicateAttributesOnElementChildComponent : ComponentBase
{
[Parameter] public string StringAttributeBefore { get; private set; }
[Parameter] public bool BoolAttributeBefore { get; private set; }
[Parameter] public string StringAttributeAfter { get; private set; }
[Parameter] public bool? BoolAttributeAfter { get; private set; }
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> UnmatchedValues { get; private set; }
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenElement(0, "div");
builder.AddAttribute(1, "string", StringAttributeBefore);
builder.AddAttribute(2, "bool", BoolAttributeBefore);
builder.AddMultipleAttributes(3, UnmatchedValues);
if (StringAttributeAfter != null)
{
builder.AddAttribute(4, "string", StringAttributeAfter);
}
if (BoolAttributeAfter != null)
{
builder.AddAttribute(5, "bool", BoolAttributeAfter);
}
builder.CloseElement();
}
}
}

View File

@ -0,0 +1,23 @@
@if (StringAttributeBefore != null)
{
<div string="@StringAttributeBefore"
bool="@BoolAttributeBefore"
@attributes="@UnmatchedValues">
</div>
}
else
{
<div @attributes="@UnmatchedValues"
string="@StringAttributeAfter"
bool="@BoolAttributeAfter">
</div>
}
@code {
[Parameter] public string StringAttributeBefore { get; private set; }
[Parameter] public bool BoolAttributeBefore { get; private set; }
[Parameter] public string StringAttributeAfter { get; private set; }
[Parameter] public bool? BoolAttributeAfter { get; private set; }
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> UnmatchedValues { get; private set; }
}