InputRadio validation styling fix (#24762)

This commit is contained in:
Mackinnon Buck 2020-08-12 09:03:29 -07:00 committed by GitHub
parent 4092201629
commit 40869f8969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 9 deletions

View File

@ -43,10 +43,11 @@ namespace Microsoft.AspNetCore.Components.Forms
{
Debug.Assert(_context != null);
builder.OpenComponent<CascadingValue<InputRadioContext>>(2);
builder.AddAttribute(3, "IsFixed", true);
builder.AddAttribute(4, "Value", _context);
builder.AddAttribute(5, "ChildContent", ChildContent);
builder.OpenComponent<CascadingValue<InputRadioContext>>(0);
builder.SetKey(_context);
builder.AddAttribute(1, "IsFixed", true);
builder.AddAttribute(2, "Value", _context);
builder.AddAttribute(3, "ChildContent", ChildContent);
builder.CloseComponent();
}

View File

@ -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.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
@ -305,9 +306,9 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
public void InputRadioGroupWithoutNameInteractsWithEditContext()
{
var appElement = MountTypicalValidationComponent();
var airlineInputs = appElement.FindElement(By.ClassName("airline")).FindElements(By.TagName("input"));
var unknownAirlineInput = airlineInputs.First(i => i.GetAttribute("value").Equals("Unknown"));
var bestAirlineInput = airlineInputs.First(i => i.GetAttribute("value").Equals("BestAirline"));
var airlineInputs = FindAirlineInputs(appElement);
var unknownAirlineInput = FindUnknownAirlineInput(airlineInputs);
var bestAirlineInput = FindBestAirlineInput(airlineInputs);
var messagesAccessor = CreateValidationMessagesAccessor(appElement);
// Validate unselected inputs
@ -321,13 +322,28 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
// Validates on edit
Assert.All(airlineInputs, i => Browser.Equal("valid", () => i.GetAttribute("class")));
bestAirlineInput.Click();
airlineInputs = FindAirlineInputs(appElement);
Assert.All(airlineInputs, i => Browser.Equal("modified valid", () => i.GetAttribute("class")));
// Can become invalid
unknownAirlineInput = FindUnknownAirlineInput(airlineInputs);
unknownAirlineInput.Click();
airlineInputs = FindAirlineInputs(appElement);
Assert.All(airlineInputs, i => Browser.Equal("modified invalid", () => i.GetAttribute("class")));
Browser.Equal(new[] { "Pick a valid airline." }, messagesAccessor);
static IReadOnlyCollection<IWebElement> FindAirlineInputs(IWebElement appElement)
=> appElement.FindElement(By.ClassName("airline")).FindElements(By.TagName("input"));
static IWebElement FindUnknownAirlineInput(IReadOnlyCollection<IWebElement> airlineInputs)
=> airlineInputs.First(i => i.GetAttribute("value").Equals("Unknown"));
static IWebElement FindBestAirlineInput(IReadOnlyCollection<IWebElement> airlineInputs)
=> airlineInputs.First(i => i.GetAttribute("value").Equals("BestAirline"));
}
[Fact]
@ -336,8 +352,8 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
var appElement = MountTypicalValidationComponent();
var submitButton = appElement.FindElement(By.CssSelector("button[type=submit]"));
var group = appElement.FindElement(By.ClassName("nested-radio-group"));
var countryInputs = group.FindElements(By.Name("country"));
var colorInputs = group.FindElements(By.Name("color"));
var countryInputs = FindCountryInputs();
var colorInputs = FindColorInputs();
// Validate group counts
Assert.Equal(3, countryInputs.Count);
@ -350,17 +366,30 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
// Invalidates on submit
Assert.All(countryInputs, i => Browser.Equal("valid", () => i.GetAttribute("class")));
Assert.All(colorInputs, i => Browser.Equal("valid", () => i.GetAttribute("class")));
submitButton.Click();
countryInputs = FindCountryInputs();
colorInputs = FindColorInputs();
Assert.All(countryInputs, i => Browser.Equal("invalid", () => i.GetAttribute("class")));
Assert.All(colorInputs, i => Browser.Equal("invalid", () => i.GetAttribute("class")));
// Validates on edit
countryInputs.First().Click();
countryInputs = FindCountryInputs();
colorInputs = FindColorInputs();
Assert.All(countryInputs, i => Browser.Equal("modified valid", () => i.GetAttribute("class")));
Assert.All(colorInputs, i => Browser.Equal("invalid", () => i.GetAttribute("class")));
colorInputs.First().Click();
colorInputs = FindColorInputs();
Assert.All(colorInputs, i => Browser.Equal("modified valid", () => i.GetAttribute("class")));
IReadOnlyCollection<IWebElement> FindCountryInputs() => group.FindElements(By.Name("country"));
IReadOnlyCollection<IWebElement> FindColorInputs() => group.FindElements(By.Name("color"));
}
[Fact]