Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update version diffs #109

Merged
merged 7 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 56 additions & 53 deletions SiemensIXBlazor.Tests/CardListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,70 @@

namespace SiemensIXBlazor.Tests
{
public class CardListTests: TestContextBase
{
[Fact]
public void CardListRendersWithoutCrashing()
{
// Arrange
var cut = RenderComponent<CardList>(parameters => {
parameters.Add(p => p.Id, "testId");
parameters.Add(p => p.Collapse, true);
parameters.Add(p => p.I18NMoreCards, "testMoreCards");
parameters.Add(p => p.I18NShowAll, "testShowAll");
parameters.Add(p => p.Label, "testLabel");
parameters.Add(p => p.ListStyle, Enums.CardList.CardListStyle.Stack);
parameters.Add(p => p.ShowAllCount, 1);
parameters.Add(p => p.SuppressOverflowHandling, true);
});
public class CardListTests : TestContextBase
{
[Fact]
public void CardListRendersWithoutCrashing()
{
// Arrange
var cut = RenderComponent<CardList>(parameters =>
{
parameters.Add(p => p.Id, "testId");
parameters.Add(p => p.Collapse, true);
parameters.Add(p => p.I18NMoreCards, "testMoreCards");
parameters.Add(p => p.I18NShowAll, "testShowAll");
parameters.Add(p => p.Label, "testLabel");
parameters.Add(p => p.ListStyle, Enums.CardList.CardListStyle.Stack);
parameters.Add(p => p.ShowAllCount, 1);
parameters.Add(p => p.SuppressOverflowHandling, true);
parameters.Add(p => p.HideShowAll, true);

// Assert
cut.MarkupMatches("<ix-card-list id=\"testId\" label=\"testLabel\" show-all-count=\"1\" list-style=\"stack\" collapse=\"\" i-1-8n-more-cards=\"testMoreCards\" i-1-8n-show-all=\"testShowAll\" suppress-overflow-handling=\"\"></ix-card-list>");
}
});

[Fact]
public void CollapsedChangedEventTriggeredCorrectly()
{
// Arrange
var eventTriggered = false;
var cut = RenderComponent<CardList>(parameters => parameters.Add(p => p.CollapseChangedEvent, EventCallback.Factory.Create<bool>(this, () => eventTriggered = true)));
// Assert
cut.MarkupMatches("<ix-card-list id=\"testId\" label=\"testLabel\" show-all-count=\"1\" list-style=\"stack\" collapse=\"\" i-1-8n-more-cards=\"testMoreCards\" i-1-8n-show-all=\"testShowAll\" suppress-overflow-handling=\"\" hide-show-all></ix-card-list>");
}

// Act
cut.Instance.CollapseChangedEvent.InvokeAsync(true);
[Fact]
public void CollapsedChangedEventTriggeredCorrectly()
{
// Arrange
var eventTriggered = false;
var cut = RenderComponent<CardList>(parameters => parameters.Add(p => p.CollapseChangedEvent, EventCallback.Factory.Create<bool>(this, () => eventTriggered = true)));

// Assert
Assert.True(eventTriggered);
}
// Act
cut.Instance.CollapseChangedEvent.InvokeAsync(true);

[Fact]
public void ShowAllClickedEventTriggeredCorrectly()
{
// Arrange
var eventTriggered = false;
var cut = RenderComponent<CardList>(parameters => parameters.Add(p => p.ShowAllClickEvent, EventCallback.Factory.Create(this, () => eventTriggered = true)));
// Assert
Assert.True(eventTriggered);
}

// Act
cut.Instance.ShowAllClickEvent.InvokeAsync();
[Fact]
public void ShowAllClickedEventTriggeredCorrectly()
{
// Arrange
var eventTriggered = false;
var cut = RenderComponent<CardList>(parameters => parameters.Add(p => p.ShowAllClickEvent, EventCallback.Factory.Create(this, () => eventTriggered = true)));

// Assert
Assert.True(eventTriggered);
}
// Act
cut.Instance.ShowAllClickEvent.InvokeAsync();

[Fact]
public void ShowMoreCardClickedEventTriggeredCorrectly()
{
// Arrange
var eventTriggered = false;
var cut = RenderComponent<CardList>(parameters => parameters.Add(p => p.ShowMoreCardClickEvent, EventCallback.Factory.Create(this, () => eventTriggered = true)));
// Assert
Assert.True(eventTriggered);
}

// Act
cut.Instance.ShowMoreCardClickEvent.InvokeAsync();
[Fact]
public void ShowMoreCardClickedEventTriggeredCorrectly()
{
// Arrange
var eventTriggered = false;
var cut = RenderComponent<CardList>(parameters => parameters.Add(p => p.ShowMoreCardClickEvent, EventCallback.Factory.Create(this, () => eventTriggered = true)));

// Assert
Assert.True(eventTriggered);
}
}
// Act
cut.Instance.ShowMoreCardClickEvent.InvokeAsync();

// Assert
Assert.True(eventTriggered);
}
}
}
4 changes: 3 additions & 1 deletion SiemensIXBlazor.Tests/CategoryFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public void CategoryFilterRendersWithoutCrashing()
parameters.Add(p => p.Placeholder, "TestPlaceholder");
parameters.Add(p => p.RepeatCategories, true);
parameters.Add(p => p.Suggestions, ["testSugestion"]);
parameters.Add(p => p.Disabled, true);
parameters.Add(p => p.Readonly, true);
});

// Assert
cut.MarkupMatches("<ix-category-filter id=\"testId\" placeholder=\"TestPlaceholder\" hide-icon=\"\" i-1-8n-plain-text=\"testI18PlainText\" icon=\"testIcon\" label-categories=\"testLabelCategories\" repeat-categories=\"\"></ix-category-filter>");
cut.MarkupMatches("<ix-category-filter id=\"testId\" placeholder=\"TestPlaceholder\" hide-icon=\"\" i-1-8n-plain-text=\"testI18PlainText\" icon=\"testIcon\" label-categories=\"testLabelCategories\" repeat-categories=\"\" readonly disabled></ix-category-filter>");
}

[Fact]
Expand Down
147 changes: 75 additions & 72 deletions SiemensIXBlazor.Tests/DateDropdownTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,96 +7,99 @@
// LICENSE file in the root directory of this source tree.
// -----------------------------------------------------------------------

using System.Text.Json;
using Bunit;
using Microsoft.AspNetCore.Components;
using SiemensIXBlazor.Components;
using SiemensIXBlazor.Components.BasicNavigation;
using SiemensIXBlazor.Enums.BasicNavigation;
using SiemensIXBlazor.Objects.DateDropdown;
using System.Text.Json;

namespace SiemensIXBlazor.Tests;

public class DateDropdownTest : TestContextBase
{
[Fact]
public void ComponentRendersWithoutCrashing()
{
// Arrange
var cut = RenderComponent<DateDropdown>();
[Fact]
public void ComponentRendersWithoutCrashing()
{
// Arrange
var cut = RenderComponent<DateDropdown>();

// Assert
cut.MarkupMatches(@"
// Assert
cut.MarkupMatches(@"
<ix-date-dropdown id="""" custom-range-allowed="""" date-range-id=""custom"" format=""yyyy/LL/dd"" i18n-custom-item=""Custom..."" i18n-done=""Done"" i18n-no-range=""No range set"" range=""""></ix-date-dropdown>
");
}
}

[Fact]
public void AllPropertiesAreSetCorrectly()
{
// Arrange
var dateDropdownOptions = new DateDropdownOption[] { new() { Id = "test", Label = "Test" } };
var dateRangeChangeEvent = new EventCallbackFactory().Create<DateDropdownResponse>(this, response =>
{
/* your action here */
});
[Fact]
public void AllPropertiesAreSetCorrectly()
{
// Arrange
var dateDropdownOptions = new DateDropdownOption[] { new() { Id = "test", Label = "Test" } };
var dateRangeChangeEvent = new EventCallbackFactory().Create<DateDropdownResponse>(this, response =>
{
/* your action here */
});

var cut = RenderComponent<DateDropdown>(parameters => parameters
.Add(p => p.Id, "testId")
.Add(p => p.CustomRangeAllowed, true)
.Add(p => p.DateRangeId, "custom")
.Add(p => p.DateRangeOptions, dateDropdownOptions)
.Add(p => p.Format, "yyyy/LL/dd")
.Add(p => p.From, "2022/01/01")
.Add(p => p.I18NCustomItem, "Custom...")
.Add(p => p.I18NDone, "Done")
.Add(p => p.I18NNoRange, "No range set")
.Add(p => p.MaxDate, "2022/12/31")
.Add(p => p.MinDate, "2022/01/01")
.Add(p => p.Range, true)
.Add(p => p.To, "2022/12/31")
.Add(p => p.DateRangeChangeEvent, dateRangeChangeEvent));
var cut = RenderComponent<DateDropdown>(parameters => parameters
.Add(p => p.Id, "testId")
.Add(p => p.CustomRangeAllowed, true)
.Add(p => p.DateRangeId, "custom")
.Add(p => p.DateRangeOptions, dateDropdownOptions)
.Add(p => p.Format, "yyyy/LL/dd")
.Add(p => p.From, "2022/01/01")
.Add(p => p.I18NCustomItem, "Custom...")
.Add(p => p.I18NDone, "Done")
.Add(p => p.I18NNoRange, "No range set")
.Add(p => p.MaxDate, "2022/12/31")
.Add(p => p.MinDate, "2022/01/01")
.Add(p => p.Range, true)
.Add(p => p.To, "2022/12/31")
.Add(p => p.DateRangeChangeEvent, dateRangeChangeEvent)
.Add(p => p.Disabled, true));

// Assert
cut.MarkupMatches(@"
<ix-date-dropdown id=""testId"" custom-range-allowed="""" date-range-id=""custom"" format=""yyyy/LL/dd"" from=""2022/01/01"" i18n-custom-item=""Custom..."" i18n-done=""Done"" i18n-no-range=""No range set"" max-date=""2022/12/31"" min-date=""2022/01/01"" range="""" to=""2022/12/31""></ix-date-dropdown>
// Assert
cut.MarkupMatches(@"
<ix-date-dropdown id=""testId"" custom-range-allowed="""" date-range-id=""custom"" format=""yyyy/LL/dd"" from=""2022/01/01"" i18n-custom-item=""Custom..."" i18n-done=""Done"" i18n-no-range=""No range set"" max-date=""2022/12/31"" min-date=""2022/01/01"" range="""" to=""2022/12/31"" disabled></ix-date-dropdown>
");
}
}

[Fact]
public void DateRangeChangeEventIsTriggeredCorrectly()
{
// Arrange
var dateDropdownOptions = new DateDropdownOption[]
{
new() { Id = "test", Label = "Test", From = "2022/01/01", To = "2022/12/31" },
new() { Id = "test2", Label = "Test2", From = "2023/01/01", To = "2023/12/31" }
};
var dateRangeChangeEventTriggered = false;
var dateRangeChangeEvent =
new EventCallbackFactory().Create<DateDropdownResponse>(this,
response => { dateRangeChangeEventTriggered = true; });
[Fact]
public void DateRangeChangeEventIsTriggeredCorrectly()
{
// Arrange
var dateDropdownOptions = new DateDropdownOption[]
{
new() { Id = "test", Label = "Test", From = "2022/01/01", To = "2022/12/31" },
new() { Id = "test2", Label = "Test2", From = "2023/01/01", To = "2023/12/31" }
};
var dateRangeChangeEventTriggered = false;
var dateRangeChangeEvent =
new EventCallbackFactory().Create<DateDropdownResponse>(this,
response => { dateRangeChangeEventTriggered = true; });

var cut = RenderComponent<DateDropdown>(parameters => parameters
.Add(p => p.Id, "testId")
.Add(p => p.CustomRangeAllowed, true)
.Add(p => p.DateRangeId, "test1")
.Add(p => p.DateRangeOptions, dateDropdownOptions)
.Add(p => p.Format, "yyyy/LL/dd")
.Add(p => p.From, "2022/01/01")
.Add(p => p.I18NCustomItem, "Custom...")
.Add(p => p.I18NDone, "Done")
.Add(p => p.I18NNoRange, "No range set")
.Add(p => p.MaxDate, "2022/12/31")
.Add(p => p.MinDate, "2022/01/01")
.Add(p => p.Range, true)
.Add(p => p.To, "2022/12/31")
.Add(p => p.DateRangeChangeEvent, dateRangeChangeEvent));
var cut = RenderComponent<DateDropdown>(parameters => parameters
.Add(p => p.Id, "testId")
.Add(p => p.CustomRangeAllowed, true)
.Add(p => p.DateRangeId, "test1")
.Add(p => p.DateRangeOptions, dateDropdownOptions)
.Add(p => p.Format, "yyyy/LL/dd")
.Add(p => p.From, "2022/01/01")
.Add(p => p.I18NCustomItem, "Custom...")
.Add(p => p.I18NDone, "Done")
.Add(p => p.I18NNoRange, "No range set")
.Add(p => p.MaxDate, "2022/12/31")
.Add(p => p.MinDate, "2022/01/01")
.Add(p => p.Range, true)
.Add(p => p.To, "2022/12/31")
.Add(p => p.DateRangeChangeEvent, dateRangeChangeEvent));

// Act
var json = JsonSerializer.Serialize(new DateDropdownResponse { Id = "test2" });
var parsedJson = JsonDocument.Parse(json).RootElement;
cut.Instance.DateRangeChange(parsedJson);
// Act
var json = JsonSerializer.Serialize(new DateDropdownResponse { Id = "test2" });
var parsedJson = JsonDocument.Parse(json).RootElement;
cut.Instance.DateRangeChange(parsedJson);

// Assert
Assert.True(dateRangeChangeEventTriggered);
}
// Assert
Assert.True(dateRangeChangeEventTriggered);
}
}
49 changes: 25 additions & 24 deletions SiemensIXBlazor.Tests/Menu/MenuItemTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,30 @@
namespace SiemensIXBlazor.Tests.Menu
{
public class MenuItemTests : TestContextBase
{
[Fact]
public void MenuItemRendersCorrectly()
{
// Arrange
var cut = RenderComponent<MenuItem>(
("Active", true),
("Disabled", false),
("Home", true),
("Icon", "testIcon"),
("Notifications", 5),
("TabIcon", "document"),
("ChildContent", (RenderFragment)(builder =>
{
builder.OpenElement(0, "div");
builder.AddContent(1, "Test child content");
builder.CloseElement();
}))
);
{
[Fact]
public void MenuItemRendersCorrectly()
{
// Arrange
var cut = RenderComponent<MenuItem>(
("Active", true),
("Disabled", false),
("Home", true),
("Icon", "testIcon"),
("Notifications", 5),
("TabIcon", "document"),
("Label", "label"),
("ChildContent", (RenderFragment)(builder =>
{
builder.OpenElement(0, "div");
builder.AddContent(1, "Test child content");
builder.CloseElement();
}))
);

// Assert
// Adjust the expected markup to match your component's output
cut.MarkupMatches("<ix-menu-item active=\"\" home=\"\" icon=\"testIcon\" notifications=\"5\" tab-icon=\"document\"><div>Test child content</div></ix-menu-item>");
}
}
// Assert
// Adjust the expected markup to match your component's output
cut.MarkupMatches("<ix-menu-item active=\"\" home=\"\" icon=\"testIcon\" notifications=\"5\" tab-icon=\"document\" label=\"label\"><div>Test child content</div></ix-menu-item>");
}
}
}
Loading
Loading