Stammdaten -> Texte bereinigen shows the bookings of one account in the selected year and edits only their Text: inline, search and replace (plain or regex with $1 groups) over the listed rows, tidying spaces, or setting one text for selected rows. A group panel shows the first-word groups the Analyse page will use, updated live. Saving goes through RawDataRepository.SaveTransactionTextsAsync: refused if the file changed since loading or a text is empty, previous version backed up, atomic save. Opened from the menu, a button per account on Konten, and a link on the Analyse page at account level. Also: the content area fills the window between header and footer, so dropdowns on short pages are no longer cut off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
1.9 KiB
C#
67 lines
1.9 KiB
C#
using Schaad.Accounting.Services;
|
|
using Shouldly;
|
|
|
|
namespace Schaad.Accounting.Tests;
|
|
|
|
public class TextReplacementTestShould
|
|
{
|
|
private static TextReplacement Create(string find, string replacement, bool useRegex = false, bool matchCase = false)
|
|
{
|
|
var result = TextReplacement.Create(find, replacement, useRegex, matchCase, out var error);
|
|
error.ShouldBeNull();
|
|
return result!;
|
|
}
|
|
|
|
[Fact]
|
|
public void ReplaceIgnoringCaseWhenSearchingPlainText()
|
|
{
|
|
Create("urlaub", "Ferien").Apply("Urlaub Flims").ShouldBe("Ferien Flims");
|
|
}
|
|
|
|
[Fact]
|
|
public void RespectCaseWhenMatchCaseIsSet()
|
|
{
|
|
Create("urlaub", "Ferien", matchCase: true).Apply("Urlaub Flims").ShouldBe("Urlaub Flims");
|
|
}
|
|
|
|
[Fact]
|
|
public void TreatSpecialCharactersLiterallyWhenSearchingPlainText()
|
|
{
|
|
Create("(2022)", "$1").Apply("Provence (2022)").ShouldBe("Provence $1");
|
|
}
|
|
|
|
[Fact]
|
|
public void UseGroupsWhenSearchingWithRegex()
|
|
{
|
|
Create("^(.+) Luzern$", "Luzern $1", useRegex: true).Apply("Migros Luzern").ShouldBe("Luzern Migros");
|
|
}
|
|
|
|
[Fact]
|
|
public void LeaveTextUnchangedWhenNothingMatches()
|
|
{
|
|
Create("^(.+) Luzern$", "Luzern $1", useRegex: true).Apply("Florenz").ShouldBe("Florenz");
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnErrorWhenRegexIsInvalid()
|
|
{
|
|
TextReplacement.Create("Provence (", "x", useRegex: true, matchCase: false, out var error).ShouldBeNull();
|
|
|
|
error.ShouldNotBeNull();
|
|
error.ShouldStartWith("Ungültiger regulärer Ausdruck");
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnErrorWhenSearchTextIsEmpty()
|
|
{
|
|
TextReplacement.Create("", "x", useRegex: false, matchCase: false, out var error).ShouldBeNull();
|
|
|
|
error.ShouldBe("Bitte einen Suchtext eingeben.");
|
|
}
|
|
|
|
[Fact]
|
|
public void TrimAndCollapseSpacesWhenTidying()
|
|
{
|
|
TextReplacement.Tidy(" Schrankfachgebühr TKB ").ShouldBe("Schrankfachgebühr TKB");
|
|
}
|
|
}
|