From 71a87ef056b42c2b7ea8165adbc7239de37f25e6 Mon Sep 17 00:00:00 2001 From: DominikaLos Date: Wed, 4 Dec 2024 13:55:41 +0100 Subject: [PATCH] bugfix: added tests for legend menu builder class --- .../GH/Legend/LegendMenuBuilderTests.cs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 GsaGHTests/Helpers/GH/Legend/LegendMenuBuilderTests.cs diff --git a/GsaGHTests/Helpers/GH/Legend/LegendMenuBuilderTests.cs b/GsaGHTests/Helpers/GH/Legend/LegendMenuBuilderTests.cs new file mode 100644 index 000000000..b0ae027fa --- /dev/null +++ b/GsaGHTests/Helpers/GH/Legend/LegendMenuBuilderTests.cs @@ -0,0 +1,49 @@ +using System; +using System.Windows.Forms; + +using GsaGH.Components; +using GsaGH.Helpers; + +using Moq; + +using Xunit; + +namespace GsaGH.Tests.Helpers { + [Collection("GrasshopperFixture collection")] + public class LegendMenuBuilderTests { + private Mock _componentMock; + private double _initialScale; + private ToolStripMenuItem _menuItem; + + public LegendMenuBuilderTests() { + _componentMock = new Mock(); // any component you want + var updateUiMock = new Mock(); + var setLegendScaleMock = new Mock(); + _initialScale = 1.5; + var builder = new LegendMenuBuilder(); + + _menuItem = builder.CreateLegendToolStripMenuItem(_componentMock.Object, updateUiMock.Object, + setLegendScaleMock.Object, _initialScale); + } + + [Fact] + public void CreateLegendToolStripMenuItem_CreatesMenuItemCorrectly() { + Assert.NotNull(_menuItem); + Assert.Equal("Scale Legend", _menuItem.Text); + Assert.True(_menuItem.Enabled); + Assert.NotNull(_menuItem.DropDownItems); + Assert.Equal(_initialScale.ToString(), _menuItem.DropDownItems[0]?.Text); + } + + [Fact] + public void CreateLegendToolStripMenuItem_UpdatesScale_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); + } + } +}