Skip to content

Commit

Permalink
Add ComboBoxMember methods and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Jul 6, 2024
1 parent d3d3fd5 commit 0fa50c2
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Updated
- Change `GetRibbonItem` to `GetRibbonItem_Alternative` to fix null when panel is removed.
- Update `SetImage` to work with `ComboBoxMember`
- Add `CreateComboBoxMember` to create `ComboBoxMember`.
### Tests
- Add `RibbonThemeUtilsTests` to test the theme change event.
- Add `ComboBoxMember` tests for `Image`, `Group` and `Current`.

## [0.6.2] / 2024-01-09 - 2024-02-05
### Features
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.6.3-beta</Version>
<Version>0.6.3-beta.1</Version>
</PropertyGroup>
</Project>
68 changes: 68 additions & 0 deletions ricaun.Revit.UI.Tests/Items/Items/RevitComboBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,74 @@ public void SetLargeImage_ShouldBe_Image()
Assert.IsNotNull(comboBox.Image);
}

[Test]
public void ComboBoxMember_SetImage_ShouldBe_Image()
{
var data = ribbonPanel.NewComboBoxMemberData();
Assert.IsNull(data.Image);
data.SetImage(BaseImage.Revit);
Assert.IsNotNull(data.Image);
}

[Test]
public void ComboBoxMember_SetLargeImage_ShouldBe_Image()
{
var data = ribbonPanel.NewComboBoxMemberData();
Assert.IsNull(data.Image);
data.SetLargeImage(BaseImage.Revit);
Assert.IsNotNull(data.Image);
}

[TestCase("Text")]
[TestCase("Name")]
public void ComboBoxMember_Create_Name_ShouldBe_ItemText(string name)
{
var comboBoxMember = comboBox.CreateComboBoxMember(name);
Assert.AreEqual(name, comboBoxMember.ItemText);
}

[TestCase("Text")]
[TestCase("Name")]
public void ComboBoxMember_Create_SetTest_ShouldBe_ItemText(string text)
{
var comboBoxMember = comboBox.CreateComboBoxMember();
comboBoxMember.SetText(text);
Assert.AreEqual(text, comboBoxMember.ItemText);
}

[TestCase("Group")]
[TestCase("Name")]
public void ComboBoxMember_Create_GroupName_ShouldBe_GroupName(string groupName)
{
var comboBoxMember = comboBox.CreateComboBoxMember(groupName: groupName);
Assert.AreEqual(groupName, comboBoxMember.GroupName);
}

[Test]
public void ComboBoxMember_Create_SetLargeImage_ShouldBe_Image()
{
var comboBoxMember = comboBox.CreateComboBoxMember();
Assert.IsNull(comboBoxMember.Image);
comboBoxMember.SetLargeImage(BaseImage.Revit);
Assert.IsNotNull(comboBoxMember.Image);
}

[Test]
public void ComboBoxMember_Create_SetImage_ShouldBe_Image()
{
var comboBoxMember = comboBox.CreateComboBoxMember();
Assert.IsNull(comboBoxMember.Image);
comboBoxMember.SetImage(BaseImage.Revit);
Assert.IsNotNull(comboBoxMember.Image);
}

[Test]
public void ComboBoxMember_Create_ShouldBe_Current()
{
var comboBoxMember = comboBox.CreateComboBoxMember();
Assert.AreEqual(comboBoxMember, comboBox.Current);
}

[TestCase(1)]
[TestCase(2)]
[TestCase(3)]
Expand Down
6 changes: 5 additions & 1 deletion ricaun.Revit.UI.Tests/ricaun.Revit.UI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="ricaun.RevitTest.TestAdapter" Version="*-*" />
<PackageReference Include="ricaun.RevitTest.TestAdapter" Version="*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" Condition="!$(TargetFramework.StartsWith('net4'))" />
</ItemGroup>

Expand All @@ -53,6 +53,10 @@
<PackageReference Include="System.Drawing.Common" Version="*" IncludeAssets="build; compile" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ricaun.Revision.Build.Tasks" Version="*-*" Condition="$(Configuration.Contains('Debug'))"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*-*" IncludeAssets="build; compile" PrivateAssets="All" />
</ItemGroup>
Expand Down
26 changes: 26 additions & 0 deletions ricaun.Revit.UI/RibbonComboBoxExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,32 @@ public static ComboBox RemoveDropDownClosed(this ComboBox comboBox, EventHandler
return comboBox;
}

#region ComboBoxMember
/// <summary>
/// CreateComboBoxMember
/// </summary>
/// <param name="comboBox"></param>
/// <param name="targetName"></param>
/// <param name="groupName"></param>
/// <returns></returns>
public static ComboBoxMember CreateComboBoxMember(this ComboBox comboBox, string targetName = null, string groupName = null)
{
if (string.IsNullOrWhiteSpace(targetName))
targetName = nameof(ComboBoxMemberData);

var comboBoxMemberData = new ComboBoxMemberData(targetName, targetName);

if (!string.IsNullOrWhiteSpace(groupName))
comboBoxMemberData.SetGroupName(groupName);

var targetText = targetName;

comboBoxMemberData.Name = RibbonSafeExtension.GenerateSafeButtonName(comboBox, comboBoxMemberData.Name, targetText);

return comboBox.AddItem(comboBoxMemberData);
}
#endregion

#region ComboBoxData
/// <summary>
/// NewComboBoxData
Expand Down

0 comments on commit 0fa50c2

Please sign in to comment.