FIL-13 Comments on the Show/Hide line are now preserved if block groups are not enabled for the script
This commit is contained in:
parent
8e54cc3b4b
commit
797c911bb5
|
@ -15,7 +15,7 @@ namespace Filtration.ObjectModel.BlockItemBaseTypes
|
|||
|
||||
public BlockAction Action
|
||||
{
|
||||
get { return _action; }
|
||||
get => _action;
|
||||
set
|
||||
{
|
||||
_action = value;
|
||||
|
@ -27,6 +27,8 @@ namespace Filtration.ObjectModel.BlockItemBaseTypes
|
|||
}
|
||||
}
|
||||
|
||||
public string Comment { get; set; }
|
||||
|
||||
public override string OutputText => Action.GetAttributeDescription();
|
||||
|
||||
public override string PrefixText => string.Empty;
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace Filtration.ObjectModel
|
|||
string Description { get; set; }
|
||||
ItemFilterBlockGroup BlockGroup { get; set; }
|
||||
BlockAction Action { get; set; }
|
||||
ActionBlockItem ActionBlockItem { get; }
|
||||
ObservableCollection<IItemFilterBlockItem> BlockItems { get; }
|
||||
Color DisplayBackgroundColor { get; }
|
||||
Color DisplayTextColor { get; }
|
||||
|
@ -32,7 +33,8 @@ namespace Filtration.ObjectModel
|
|||
|
||||
public ItemFilterBlock()
|
||||
{
|
||||
BlockItems = new ObservableCollection<IItemFilterBlockItem> {new ActionBlockItem(BlockAction.Show)};
|
||||
ActionBlockItem = new ActionBlockItem(BlockAction.Show);
|
||||
BlockItems = new ObservableCollection<IItemFilterBlockItem> {ActionBlockItem};
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
|
@ -79,6 +81,8 @@ namespace Filtration.ObjectModel
|
|||
}
|
||||
}
|
||||
|
||||
public ActionBlockItem ActionBlockItem { get; }
|
||||
|
||||
public ObservableCollection<IItemFilterBlockItem> BlockItems { get; }
|
||||
|
||||
public int BlockCount(Type type)
|
||||
|
|
|
@ -26,6 +26,41 @@ namespace Filtration.Parser.Tests.Services
|
|||
_testUtility = new ItemFilterBlockTranslatorTestUtility();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_ActionBlockItemCommentIsNull()
|
||||
{
|
||||
|
||||
// Arrange
|
||||
var inputString = "Show # Test - Test2 - Test3" + Environment.NewLine;
|
||||
|
||||
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
||||
_testUtility.MockBlockGroupHierarchyBuilder
|
||||
.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>()))
|
||||
.Returns(inputBlockGroup);
|
||||
|
||||
// Act
|
||||
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScriptSettings>(i => i.BlockGroupsEnabled));
|
||||
|
||||
//Assert
|
||||
Assert.IsTrue(string.IsNullOrEmpty(result.ActionBlockItem.Comment));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslateStringToItemFilterBlock_BlockGroupsDisabled_ActionBlockItemCommentIsSetCorrectly()
|
||||
{
|
||||
|
||||
// Arrange
|
||||
var testInputExpectedComment = " this is a comment that should be preserved";
|
||||
|
||||
var inputString = $"Show #{testInputExpectedComment}" + Environment.NewLine;
|
||||
|
||||
// Act
|
||||
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of<IItemFilterScriptSettings>(i => i.BlockGroupsEnabled == false));
|
||||
|
||||
//Assert
|
||||
Assert.AreEqual(testInputExpectedComment, result.ActionBlockItem.Comment);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslateStringToItemFilterBlock_NotDisabled_SetsBlockEnabledTrue()
|
||||
{
|
||||
|
@ -1044,6 +1079,22 @@ namespace Filtration.Parser.Tests.Services
|
|||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslateItemFilterBlockToString_HasActionBlockComment_ReturnsCorrectString()
|
||||
{
|
||||
// Arrange
|
||||
var testInputActionBlockComment = "this is a test";
|
||||
var expectedResult = $"Show #{testInputActionBlockComment}";
|
||||
|
||||
_testUtility.TestBlock.BlockItems.OfType<ActionBlockItem>().First().Comment = testInputActionBlockComment;
|
||||
|
||||
// Act
|
||||
var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(expectedResult, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslateItemFilterBlockToString_FilterTypeHide_ReturnsCorrectString()
|
||||
{
|
||||
|
|
|
@ -348,6 +348,7 @@ namespace Filtration.Parser.Tests.Services
|
|||
Assert.AreEqual("This is a disabled block", secondBlock.Description);
|
||||
}
|
||||
|
||||
// TODO: Reinstate this test
|
||||
[Ignore("Ignored until toggling block group parsing can be controlled from the filter script input")]
|
||||
[Test]
|
||||
public void TranslateStringToItemFilterScript_DisabledBlockWithBlockGroup_ReturnsCorrectBlock()
|
||||
|
|
|
@ -55,39 +55,12 @@ namespace Filtration.Parser.Services
|
|||
continue;
|
||||
}
|
||||
|
||||
var adjustedLine = line.Replace("#", " # ");
|
||||
var trimmedLine = adjustedLine.Trim();
|
||||
|
||||
var trimmedLine = line.Trim();
|
||||
var spaceOrEndOfLinePos = trimmedLine.IndexOf(" ", StringComparison.Ordinal) > 0 ? trimmedLine.IndexOf(" ", StringComparison.Ordinal) : trimmedLine.Length;
|
||||
|
||||
var lineOption = trimmedLine.Substring(0, spaceOrEndOfLinePos);
|
||||
switch (lineOption)
|
||||
{
|
||||
|
||||
//case "Show":
|
||||
// showHideFound = true;
|
||||
// block.Action = BlockAction.Show;
|
||||
// block.Enabled = true;
|
||||
// AddBlockGroupToBlock(block, trimmedLine);
|
||||
// break;
|
||||
//case "Hide":
|
||||
// showHideFound = true;
|
||||
// block.Action = BlockAction.Hide;
|
||||
// block.Enabled = true;
|
||||
// AddBlockGroupToBlock(block, trimmedLine);
|
||||
// break;
|
||||
//case "ShowDisabled":
|
||||
// showHideFound = true;
|
||||
// block.Action = BlockAction.Show;
|
||||
// block.Enabled = false;
|
||||
// AddBlockGroupToBlock(block, trimmedLine);
|
||||
// break;
|
||||
//case "HideDisabled":
|
||||
// showHideFound = true;
|
||||
// block.Action = BlockAction.Hide;
|
||||
// block.Enabled = false;
|
||||
// AddBlockGroupToBlock(block, trimmedLine);
|
||||
// break;
|
||||
case "Show":
|
||||
case "Hide":
|
||||
case "ShowDisabled":
|
||||
|
@ -96,10 +69,17 @@ namespace Filtration.Parser.Services
|
|||
showHideFound = true;
|
||||
block.Action = lineOption.StartsWith("Show") ? BlockAction.Show : BlockAction.Hide;
|
||||
block.Enabled = !lineOption.EndsWith("Disabled");
|
||||
|
||||
// If block groups are enabled for this script, the comment after Show/Hide is parsed as a block
|
||||
// group hierarchy, if block groups are disabled it is preserved as a simple text comment.
|
||||
if (itemFilterScriptSettings.BlockGroupsEnabled)
|
||||
{
|
||||
AddBlockGroupToBlock(block, trimmedLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
block.ActionBlockItem.Comment = GetTextAfterFirstComment(trimmedLine);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "ItemLevel":
|
||||
|
@ -406,10 +386,7 @@ namespace Filtration.Parser.Services
|
|||
|
||||
private void AddBlockGroupToBlock(IItemFilterBlock block, string inputString)
|
||||
{
|
||||
var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal);
|
||||
if (blockGroupStart <= 0) return;
|
||||
|
||||
var blockGroupText = inputString.Substring(blockGroupStart + 1);
|
||||
var blockGroupText = GetTextAfterFirstComment(inputString);
|
||||
var blockGroups = blockGroupText.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(s => s.Trim())
|
||||
.ToList();
|
||||
|
@ -421,6 +398,14 @@ namespace Filtration.Parser.Services
|
|||
}
|
||||
}
|
||||
|
||||
private static string GetTextAfterFirstComment(string inputString)
|
||||
{
|
||||
var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal);
|
||||
if (blockGroupStart <= 0) return string.Empty;
|
||||
|
||||
return inputString.Substring(blockGroupStart + 1);
|
||||
}
|
||||
|
||||
private static Color GetColorFromString(string inputString)
|
||||
{
|
||||
var argbValues = Regex.Matches(inputString, @"\s+(\d+)");
|
||||
|
@ -474,6 +459,10 @@ namespace Filtration.Parser.Services
|
|||
{
|
||||
outputString += " # " + block.BlockGroup;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(block.ActionBlockItem?.Comment))
|
||||
{
|
||||
outputString += " #" + block.ActionBlockItem.Comment;
|
||||
}
|
||||
|
||||
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||
foreach (var blockItem in block.BlockItems.Where(b => b.GetType() != typeof(ActionBlockItem)).OrderBy(b => b.SortOrder))
|
||||
|
|
Loading…
Reference in New Issue