mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-05 08:44:36 +00:00
Added whole documents to the Translation, Grammar & Spelling, and Rewrite & Improve assistants (#1179)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f7666861f1
commit
918572c158
150 files changed
+12850
-302
No files matched your search
@@ -6,23 +6,28 @@ using AIStudio.Components;
|
||||
namespace AIStudio.Tests.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Checks that every text field with a validation checks its text again while the user types.
|
||||
/// Checks that every text field with a validation checks its text again while the user types, and not before the
|
||||
/// user touched it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Without Immediate or a DebounceInterval, a MudTextField passes its text on only when the user leaves it, so an
|
||||
/// issue stays visible while the user types the text which resolves it. A field with a DebounceInterval binds its
|
||||
/// Value, not its Text: bound by its text, it would delay the texts its parent sets as well, e.g., by a reset, and
|
||||
/// check them without having been touched, see TextFieldDefaults. A read-only field takes no typing and needs neither.
|
||||
/// check them without having been touched, see TextFieldDefaults. A read-only field takes no typing and needs neither,
|
||||
/// but it binds its Value as well: only its parent sets its text, e.g., the path a file dialog returned, and bound by
|
||||
/// its text, it would check the empty text before the user chose anything.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed partial class ValidatedTextFieldTests
|
||||
{
|
||||
private const string CHECKS_ON_LEAVING = "checks its text only when the user leaves it";
|
||||
private const string DEBOUNCED_BY_TEXT = "binds its text, so it delays and checks the texts its parent sets as well";
|
||||
private const string READ_ONLY_BY_TEXT = "is read-only and binds its text, so it checks the texts its parent sets, the empty one before the user chose anything as well";
|
||||
|
||||
[TestCase("""<MudTextField T="string" @bind-Value="@this.input" Validation="@this.Validate" DebounceInterval="@TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS"/>""", ExpectedResult = "")]
|
||||
[TestCase("""<MudTextField T="string" @bind-Text="@this.input" Validation="@this.Validate" Immediate="@true"/>""", ExpectedResult = "")]
|
||||
[TestCase("""<MudTextField T="string" Text="@this.input" ReadOnly="@true" Validation="@this.Validate"/>""", ExpectedResult = "")]
|
||||
[TestCase("""<MudTextField T="string" Value="@this.input" ReadOnly="@true" Validation="@this.Validate"/>""", ExpectedResult = "")]
|
||||
[TestCase("""<MudTextField T="string" Text="@this.input" ReadOnly="@true" Validation="@this.Validate"/>""", ExpectedResult = "1: " + READ_ONLY_BY_TEXT)]
|
||||
[TestCase("""<MudTextField T="string" @bind-Text="@this.input" Label="@T("Name")"/>""", ExpectedResult = "")]
|
||||
[TestCase("""<MudTextField T="string" @bind-Text="@this.input" Validation="@this.Validate"/>""", ExpectedResult = "1: " + CHECKS_ON_LEAVING)]
|
||||
[TestCase("""<MudTextField T="string" @bind-Value="@this.input" Validation="@this.Validate" Immediate="@false"/>""", ExpectedResult = "1: " + CHECKS_ON_LEAVING)]
|
||||
@@ -55,7 +60,7 @@ public sealed partial class ValidatedTextFieldTests
|
||||
}
|
||||
|
||||
Assert.That(fields, Is.GreaterThan(50), "The test found too few text fields with a validation, so it probably misreads the Razor files.");
|
||||
Assert.That(issues, Is.Empty, $"Give these text fields DebounceInterval=\"@{nameof(TextFieldDefaults)}.{nameof(TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS)}\" and bind their Value:\n{string.Join('\n', issues)}");
|
||||
Assert.That(issues, Is.Empty, $"Bind the Value of these text fields, and give those which take typing DebounceInterval=\"@{nameof(TextFieldDefaults)}.{nameof(TextFieldDefaults.VALIDATION_DEBOUNCE_MILLISECONDS)}\":\n{string.Join('\n', issues)}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -66,14 +71,14 @@ public sealed partial class ValidatedTextFieldTests
|
||||
private sealed record TextFieldTag(int Line, string Source);
|
||||
|
||||
/// <summary>
|
||||
/// Finds every MudTextField with a validation which takes typing, i.e., which is not read-only.
|
||||
/// Finds every MudTextField with a validation.
|
||||
/// </summary>
|
||||
private static IEnumerable<TextFieldTag> ValidatedTextFields(string razor)
|
||||
{
|
||||
foreach (Match start in TextFieldStartRegex().Matches(razor))
|
||||
{
|
||||
var tag = razor[start.Index..(TagEnd(razor, start.Index + start.Length) + 1)];
|
||||
if (!ValidationRegex().IsMatch(tag) || ReadOnlyRegex().IsMatch(tag))
|
||||
if (!ValidationRegex().IsMatch(tag))
|
||||
continue;
|
||||
|
||||
yield return new TextFieldTag(razor[..start.Index].Count(character => character == '\n') + 1, tag);
|
||||
@@ -82,6 +87,14 @@ public sealed partial class ValidatedTextFieldTests
|
||||
|
||||
private static IEnumerable<string> IssuesOf(TextFieldTag field)
|
||||
{
|
||||
if (ReadOnlyRegex().IsMatch(field.Source))
|
||||
{
|
||||
if (TextBindingRegex().IsMatch(field.Source))
|
||||
yield return READ_ONLY_BY_TEXT;
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
var isDebounced = DebounceRegex().IsMatch(field.Source);
|
||||
if (!isDebounced && !ImmediateRegex().IsMatch(field.Source))
|
||||
yield return CHECKS_ON_LEAVING;
|
||||
|
||||
Reference in new issue
Block a user