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

v7 Preparation: Add Nullable & Improve Code Quality #367

Merged
merged 4 commits into from
Apr 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>disable</Nullable>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@code {
private bool collapseNavMenu = true;

private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void ToggleNavMenu()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@code {

string value = null;
string? value = null;

public bool ClearButtonClicked { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
public int ItemChangeCount { get; set; }
public int ItemsChangeCount { get; set; }

MudComboBox<string> _combobox;
MudComboBoxItem<string> FirstItem { get; set; }
MudComboBoxItem<string> SecondItem { get; set; }
MudComboBoxItem<string> ThirdItem { get; set; }
MudComboBox<string> _combobox = new();
MudComboBoxItem<string> FirstItem { get; set; } = new();
MudComboBoxItem<string> SecondItem { get; set; } = new();
MudComboBoxItem<string> ThirdItem { get; set; } = new();

//public void SetSelectedItem()
//{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

@code {
[Parameter]
public string SelectedValue { get; set; }
public string? SelectedValue { get; set; }
[Parameter]
public IEnumerable<string> SelectedValues { get; set; }
public IEnumerable<string?>? SelectedValues { get; set; }
[Parameter]
public bool MultiSelection { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@

@code
{
MudListItemExtended<int> selectedItem;
MudListItemExtended<int>? selectedItem;
int selectedValue;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
@code
{
[Parameter] public Color Color { get; set; } = Color.Primary;
MudListExtended<int?> _list;
MudListExtended<int?> _list = new();
public static string __description__ = "Sparkling Water should be selected initially.";
MudListItemExtended<int?> selectedItem;
MudListItemExtended<int?>? selectedItem;
int? selectedValue = 1;

public void SetSelectedValue(int? value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
@code
{
public static string __description__ = "Clicking the drinks selects them. The child lists are updated accordingly.";
MudListItemExtended<int> selectedItem;
MudListItemExtended<int>? selectedItem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<MudGrid>
<MudItem xs="12" sm="4">
<MudCheckBox @bind-Checked="_clickable" Color="Color.Primary" Label="Clickable" />
<MudCheckBox @bind-Value="_clickable" Color="Color.Primary" Label="Clickable" />
@*<MudCheckBox @bind-Checked="_multiSelection" Color="Color.Primary" Label="MultiSelection" />*@
<MudCheckBox @bind-Checked="_selectAll" Color="Color.Primary" Label="Select All" />
<MudCheckBox @bind-Value="_selectAll" Color="Color.Primary" Label="Select All" />
<MudDivider />
<MudTextField @bind-Value="_selectedValue" Clearable="true" />

Expand Down Expand Up @@ -48,11 +48,11 @@
bool _clickable = true;
bool _selectAll = false;

MudListExtended<int?> _list;
MudListExtended<int?> _list = new();
int? _selectedValue = 1;
IEnumerable<int?> _selectedValues = new List<int?>();
MudListItemExtended<int?> _selectedItem;
MudListItemExtended<int?> _thirdItem;
MudListItemExtended<int?> _fifthItem;
MudListItemExtended<int?>? _selectedItem;
MudListItemExtended<int?> _thirdItem = new();
MudListItemExtended<int?> _fifthItem = new();
IEnumerable<MudListItemExtended<int?>> _selectedItems = new List<MudListItemExtended<int?>>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Nullable>enable</Nullable>

<!--<IsPackable>false</IsPackable>-->
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ public async Task ComboBoxTest1()
comp.WaitForAssertion(() => combobox.Instance.Value.Should().Be("1"));
//Check user on blur implementation works
var @switch = comp.FindComponent<MudSwitch<bool>>();
@switch.Instance.Checked = true;
@switch.Instance.Value = true;
await comp.InvokeAsync(() => combobox.Instance.HandleOnBlur(new FocusEventArgs()));
comp.WaitForAssertion(() => @switch.Instance.Checked.Should().Be(false));
comp.WaitForAssertion(() => @switch.Instance.Value.Should().Be(false));
}

[Test]
Expand Down Expand Up @@ -304,7 +304,7 @@ public async Task ComboBox_MultiSelectTest1()
comp.WaitForAssertion(() => combobox.Instance.GetPresenterText().Should().Be("2, 1, 3"));
items[0].Click();
comp.WaitForAssertion(() => combobox.Instance.GetPresenterText().Should().Be("2, 3"));
combobox.Instance.SelectedValues.Count().Should().Be(2);
combobox.Instance.SelectedValues?.Count().Should().Be(2);
combobox.Instance.SelectedValues.Should().Contain("2");
combobox.Instance.SelectedValues.Should().Contain("3");
//Console.WriteLine(comp.Markup);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using Bunit;
using MudExtensions.UnitTests.Components;
using ComponentViewer.Docs.Pages.Components;
using ComponentViewer.Docs.Pages.Components;
using FluentAssertions;
using MudBlazor;
using MudExtensions;

namespace MudExtensions.UnitTests.Components
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ public async Task SelectTest1()
comp.WaitForAssertion(() => select.Instance.Value.Should().Be("1"));
//Check user on blur implementation works
var @switch = comp.FindComponent<MudSwitch<bool>>();
@switch.Instance.Checked = true;
@switch.Instance.Value = true;
await comp.InvokeAsync(() => select.Instance.OnLostFocus(new FocusEventArgs()));
comp.WaitForAssertion(() => @switch.Instance.Checked.Should().Be(false));
comp.WaitForAssertion(() => @switch.Instance.Value.Should().Be(false));
}

/// <summary>
Expand Down Expand Up @@ -391,7 +391,7 @@ public void Select_Should_FireTextChangedWithNewValue()
var comp = Context.RenderComponent<SelectTest1>();
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
string text = null;
string? text = null;
select.SetCallback(s => s.TextChanged, x => text = x);
var menu = comp.Find("div.mud-popover");
var input = comp.Find("div.mud-input-control");
Expand Down Expand Up @@ -433,8 +433,8 @@ public void SingleSelect_Should_FireTextChangedBeforeSelectedValuesChanged()
var comp = Context.RenderComponent<SelectTest1>();
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
string text = null;
IEnumerable<string> selectedValues = null;
string? text = null;
IEnumerable<string>? selectedValues = null;
var eventCounter = 0;
var textChangedCount = 0;
var selectedValuesChangedCount = 0;
Expand Down Expand Up @@ -494,8 +494,8 @@ public void MultiSelect_Should_FireTextChangedBeforeSelectedValuesChanged()
var comp = Context.RenderComponent<SelectTest1>();
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
string text = null;
IEnumerable<string> selectedValues = null;
string? text = null;
IEnumerable<string>? selectedValues = null;
var eventCounter = 0;
var textChangedCount = 0;
var selectedValuesChangedCount = 0;
Expand Down Expand Up @@ -577,7 +577,7 @@ public async Task MultiSelect_ShouldCallValidationFunc()
//Console.WriteLine(comp.Markup);
// select elements needed for the test
var select = comp.FindComponent<MudSelectExtended<string>>();
IEnumerable<string> validatedValue = null;
IEnumerable<string>? validatedValue = null;
select.SetParam(x => x.Validation, new Func<string, bool>(value =>
{
validatedValue = select.Instance.SelectedValues;
Expand Down Expand Up @@ -619,7 +619,7 @@ public void MultiSelect_SelectAll()
var comp = Context.RenderComponent<MultiSelectTest2>();
// select element needed for the test
var select = comp.FindComponent<MudSelectExtended<string>>();
IEnumerable<string> validatedValue = null;
IEnumerable<string>? validatedValue = null;
select.SetParam(x => x.Validation, (object)new Func<string, bool>(value =>
{
validatedValue = select.Instance.SelectedValues; // NOTE: select does only update the value for T string
Expand Down Expand Up @@ -694,7 +694,7 @@ public void SingleSelect_Should_CallValidationFunc()
var comp = Context.RenderComponent<SelectTest1>();
//Console.WriteLine(comp.Markup);
var select = comp.FindComponent<MudSelectExtended<string>>();
string validatedValue = null;
string? validatedValue = null;
select.SetParam(x => x.Validation, (object)new Func<string, bool>(value =>
{
validatedValue = value; // NOTE: select does only update the value for T string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using Bunit;
using MudExtensions.UnitTests.Components;
using ComponentViewer.Docs.Pages.Components;
using FluentAssertions;
using MudBlazor;
using MudExtensions;
using MudExtensions.UnitTests.TestComponents;

namespace MudExtensions.UnitTests.Components
Expand Down
Loading
Loading