Skip to content

Commit

Permalink
refactor: updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikaLos committed Dec 13, 2024
1 parent 01cc160 commit ca85142
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
23 changes: 16 additions & 7 deletions GsaGH/Helpers/GH/TextWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ public static string WrapText(string text, int maxWidth, Font font) {
return string.Empty;
}

string[] splittedText = text.Split('\n');
string caseName = splittedText[0];
string withoutCaseName = splittedText[1];
string[] words = withoutCaseName.Split(' ');
var lines = new List<string>() {
caseName,
};
string[] words = GetTextToWrap(text, out List<string> lines);
string currentLine = "";
foreach (string word in words) {
string testLine = string.IsNullOrEmpty(currentLine) ? word : $"{currentLine} {word}";
Expand All @@ -43,6 +37,21 @@ public static string WrapText(string text, int maxWidth, Font font) {
return string.Join("\n", lines).Trim();
}

private static string[] GetTextToWrap(string text, out List<string> lines) {
lines = new List<string>();
string[] splittedText = text.Split('\n');
string textToWrap;

if (splittedText.Length > 1) {
lines.Add(splittedText[0]);
textToWrap = splittedText[1];
} else {
textToWrap = text;
}

return textToWrap.Split(' ');
}

/// <summary>
/// Gets the width of the given text from the cache or measures and caches it.
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions GsaGHTests/Helpers/GH/Legend/ContourLegendMenagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ namespace GsaGHTests.Helpers {
public class ContourLegendMenagerTests {
private static Mock<ContourLegend> _mockLegend;
private static Mock<ContourLegendConfiguration> _mockConfiguration;
private static Mock<LegendMenuBuilder> _mockMenuBuilder;
private static ContourLegendManager _manager;
private static Mock<IGH_PreviewArgs> _mockArgs;

public ContourLegendMenagerTests() {
_mockLegend = new Mock<ContourLegend>();
_mockConfiguration = new Mock<ContourLegendConfiguration>();
_mockMenuBuilder = new Mock<LegendMenuBuilder>();
_manager = new ContourLegendManager(_mockConfiguration.Object, _mockLegend.Object, _mockMenuBuilder.Object);
var menuBuilder = new LegendMenuBuilder();
_manager = new ContourLegendManager(_mockConfiguration.Object, _mockLegend.Object, menuBuilder);

_mockArgs = new Mock<IGH_PreviewArgs>();
}
Expand Down
9 changes: 2 additions & 7 deletions GsaGHTests/Helpers/GH/Legend/ContourLegendTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@
namespace GsaGHTests.Helpers {
[Collection("GrasshopperFixture collection")]
public class ContourLegendTests {
private readonly Mock<ContourLegendConfiguration> _mockConfiguration;
private ContourLegend legend;
private readonly Bitmap _mockBitmap;

public ContourLegendTests() {
_mockBitmap = new Bitmap(10, 10);
_mockConfiguration = new Mock<ContourLegendConfiguration>();
// _mockConfiguration.Setup(c => c.Bitmap).Returns(_mockBitmap);
_mockConfiguration.Setup(c => c.Scale).Returns(1.0);
legend = new ContourLegend(_mockConfiguration.Object);
var configuration = new ContourLegendConfiguration(1, 2, 1.0d);
legend = new ContourLegend(configuration);
}

[Fact]
Expand Down
11 changes: 0 additions & 11 deletions GsaGHTests/Helpers/GH/Legend/LegendMenuBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,5 @@ public void CreateLegendToolStripMenuItem_CreatesMenuItemCorrectly() {
Assert.NotNull(_menuItem.DropDownItems);
Assert.Equal(_initialScale.ToString(), _menuItem.DropDownItems[0]?.Text);
}

[Fact]
public void CreateLegendToolStripMenuItem_UpdatesTextBox_OnTextChange() {
ToolStripItem scaleTextBox = _menuItem.DropDownItems[0];
double newScale = 2.5d;
// Act - Simulate text change
scaleTextBox.Text = $"{newScale}"; // Updates private _scaleLegendTxt indirectly
_menuItem.DropDownItems[1].PerformClick(); // Simulate mouse up to trigger UpdateLegendScale

Assert.Equal(newScale.ToString(), _menuItem.DropDownItems[0]?.Text);
}
}
}

0 comments on commit ca85142

Please sign in to comment.