Skip to content
Open
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
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<!-- Testing -->
<PackageVersion Include="bunit" Version="2.8.6" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.9" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.9" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
Expand Down
1 change: 1 addition & 0 deletions IgniteUI.Blazor.Lite.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</Folder>
<Folder Name="/tests/">
<Project Path="tests/IgniteUI.Blazor.Lite.IntegrationTests/IgniteUI.Blazor.Lite.IntegrationTests.csproj" />
<Project Path="tests/IgniteUI.Blazor.Lite.TestBed.Client/IgniteUI.Blazor.Lite.TestBed.Client.csproj" />
<Project Path="tests/IgniteUI.Blazor.Lite.TestBed/IgniteUI.Blazor.Lite.TestBed.csproj" />
<Project Path="tests/IgniteUI.Blazor.Tests/IgniteUI.Blazor.Tests.csproj" />
</Folder>
Expand Down
181 changes: 181 additions & 0 deletions tests/IgniteUI.Blazor.Lite.IntegrationTests/ComboDataTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
using System.Text.Json;
using IgniteUI.Blazor.Lite.IntegrationTests.Infrastructure;

namespace IgniteUI.Blazor.Lite.IntegrationTests
{
/// <summary>
/// Combo data-binding scenarios against the WebAssembly-rendered TestBed page
/// (<c>/combo-data</c>). Unlike the Server-rendered component sweep, data here crosses
/// the in-process (unmarshalled) channel — the same path a production WASM app uses.
/// Assertions read the live web component's <c>data</c>: what the user's combo shows.
/// </summary>
[Parallelizable(ParallelScope.Self)]
public class ComboDataTest : BlazorPageTest<Program>
{
[Test]
public async Task TypedFields_TransferToClient()
{
await OpenScenarioAsync("typed-products", expectedCount: 3);

var first = (await ClientDataAsync())[0];
Assert.Multiple(() =>
{
Assert.That(first.GetProperty("Id").GetInt32(), Is.EqualTo(1));
Assert.That(first.GetProperty("Name").GetString(), Is.EqualTo("Chai"));
Assert.That(first.GetProperty("Price").GetDouble(), Is.EqualTo(18.5));
Assert.That(first.GetProperty("Discontinued").GetBoolean(), Is.False);
Assert.That(first.GetProperty("UnitsSold").GetInt64(), Is.EqualTo(42_000_000_000));
// The client holds a JS Date; compare instants so the machine's timezone drops out.
Assert.That(ClientInstant(first.GetProperty("Restocked")), Is.EqualTo(new DateTime(2026, 1, 15).ToUniversalTime()));
});
}

[Test]
public async Task NullableFields_PreserveNullsAndValues()
{
await OpenScenarioAsync("nullable-readings", expectedCount: 3);

var data = await ClientDataAsync();
var full = data[0];
var empty = data[1];
var mixed = data[2];
Assert.Multiple(() =>
{
Assert.That(full.GetProperty("Quantity").GetInt32(), Is.EqualTo(5));
Assert.That(full.GetProperty("Value").GetDouble(), Is.EqualTo(2.5));
Assert.That(full.GetProperty("Flagged").GetBoolean(), Is.True);
Assert.That(ClientInstant(full.GetProperty("MeasuredOn")), Is.EqualTo(new DateTime(2026, 3, 3).ToUniversalTime()));

Assert.That(empty.GetProperty("Quantity").ValueKind, Is.EqualTo(JsonValueKind.Null));
Assert.That(empty.GetProperty("Value").ValueKind, Is.EqualTo(JsonValueKind.Null));
Assert.That(empty.GetProperty("Flagged").ValueKind, Is.EqualTo(JsonValueKind.Null));
Assert.That(empty.GetProperty("MeasuredOn").ValueKind, Is.EqualTo(JsonValueKind.Null));

Assert.That(mixed.GetProperty("Quantity").GetInt32(), Is.EqualTo(7));
Assert.That(mixed.GetProperty("Value").ValueKind, Is.EqualTo(JsonValueKind.Null));
Assert.That(mixed.GetProperty("Flagged").GetBoolean(), Is.False);
});
}

[Test]
public async Task NestedObjects_TransferNestedValues()
{
await OpenScenarioAsync("nested-orders", expectedCount: 2);

var data = await ClientDataAsync();
Assert.Multiple(() =>
{
Assert.That(data[0].GetProperty("Reference").GetString(), Is.EqualTo("ORD-1"));
Assert.That(data[0].GetProperty("Customer").GetProperty("Name").GetString(), Is.EqualTo("Maria"));
Assert.That(data[1].GetProperty("Customer").GetProperty("City").GetString(), Is.EqualTo("Madrid"));
});
}

[Test]
public async Task ObjectValues_SelectionTravelsBackAsDataItems()
{
await OpenScenarioAsync("objects-as-values", expectedCount: 3);

await Page.EvaluateAsync("() => document.querySelector('igc-combo').show()");
// Playwright's own click fails its actionability check on the combo's
// shadow-DOM items, so click through the DOM.
await Page.WaitForFunctionAsync("() => document.querySelector('igc-combo').shadowRoot.querySelector('igc-combo-item') !== null");
await Page.EvaluateAsync("() => document.querySelector('igc-combo').shadowRoot.querySelector('igc-combo-item').click()");
await Page.WaitForFunctionAsync(
"() => window.clientPageRef.invokeMethodAsync('GetLastValue').then(v => v.count === 1)");

var last = await Page.EvaluateAsync<JsonElement>(
"() => window.clientPageRef.invokeMethodAsync('GetLastValue')");
Assert.Multiple(() =>
{
Assert.That(last.GetProperty("names")[0].GetString(), Is.EqualTo("Chai"));
Assert.That(last.GetProperty("sameInstances").GetBoolean(), Is.True,
"received values should resolve back to the bound data instances");
});
}

[Test]
[Ignore("Item types with public primitive-typed fields crash schema creation: JsonDataSourceSchema.Commit " +
"stores the typed field getters in a Func<object, object>[] and throws ArrayTypeMismatchException " +
"(TypedPropertyGetters uses Delegate[]). Enable once the field getter array type is fixed.")]
public async Task NestedPublicFields_TransferToClient()
{
await OpenScenarioAsync("nested-field-shipments", expectedCount: 2);

var data = await ClientDataAsync();
Assert.Multiple(() =>
{
Assert.That(data[0].GetProperty("Box").GetProperty("Width").GetDouble(), Is.EqualTo(2.5));
Assert.That(data[1].GetProperty("Box").GetProperty("Height").GetDouble(), Is.EqualTo(3.0));
});
}

[Test]
public async Task PrimitiveStrings_TransferAsItems()
{
await OpenScenarioAsync("primitive-strings", expectedCount: 3);

var data = await ClientDataAsync();
Assert.That(data[0].GetString(), Is.EqualTo("alpha"));
Assert.That(data[2].GetString(), Is.EqualTo("gamma"));
}

[Test]
public async Task ObservableCollectionMutations_FlowToClient()
{
await OpenScenarioAsync("observable-products", expectedCount: 3);

await MutateAsync("add");
await WaitForItemCountAsync(4);
var data = await ClientDataAsync();
Assert.That(data[3].GetProperty("Name").GetString(), Is.EqualTo("Added"), "added item should appear last");

await MutateAsync("removeFirst");
await WaitForItemCountAsync(3);
data = await ClientDataAsync();
Assert.That(data[0].GetProperty("Name").GetString(), Is.EqualTo("Chang"), "remaining items should shift up on remove");

await MutateAsync("replaceFirst");
await Page.WaitForFunctionAsync("() => document.querySelector('igc-combo').data[0].Name === 'Replaced'");

await MutateAsync("clear");
await WaitForItemCountAsync(0);
}

[Test]
public async Task DataSwap_ReplacesClientData()
{
await OpenScenarioAsync("typed-products", expectedCount: 3);

await Page.EvaluateAsync(
"() => window.clientPageRef.invokeMethodAsync('SetComboScenario', 'primitive-strings')");
await Page.WaitForFunctionAsync("() => document.querySelector('igc-combo').data?.[0] === 'alpha'");
}

private async Task OpenScenarioAsync(string scenario, int expectedCount)
{
await Page.GotoAsync("http://localhost:5249/combo-data?scenario=" + scenario);
await Page.WaitForFunctionAsync("() => !!window.clientPageRef");
// Prerender is off on the page, so the combo holding data means the WASM
// runtime is live and the transfer completed.
await WaitForItemCountAsync(expectedCount);
}
Comment thread
Copilot marked this conversation as resolved.

private Task WaitForItemCountAsync(int count)
=> Page.WaitForFunctionAsync($"() => document.querySelector('igc-combo')?.data?.length === {count}");

private async Task<JsonElement> ClientDataAsync()
{
var data = await Page.EvaluateAsync<JsonElement>("() => document.querySelector('igc-combo').data");
Assert.That(data.ValueKind, Is.EqualTo(JsonValueKind.Array), "the combo should expose its data as an array");
return data;
}

private Task MutateAsync(string action)
=> Page.EvaluateAsync($"() => window.clientPageRef.invokeMethodAsync('MutateComboData', '{action}')");

/// <summary>Parses a client-side JS Date (reported as an ISO string) to its UTC instant.</summary>
private static DateTime ClientInstant(JsonElement value)
=> DateTime.Parse(value.GetString()!, null, System.Globalization.DateTimeStyles.AdjustToUniversal);
}
}
97 changes: 97 additions & 0 deletions tests/IgniteUI.Blazor.Lite.TestBed.Client/ComboDataScenarios.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using System.Collections.ObjectModel;

namespace IgniteUI.Blazor.Lite.TestBed.Client;

/// <summary>
/// Combo data-binding scenarios shared between the WASM e2e page (<c>ComboDataPage</c>,
/// compiled here) and the in-process unit suite (<c>UnmarshalledDataChannelTests</c>,
/// which links this file), so both exercise the same data shapes.
/// </summary>
public static class ComboDataScenarios
{
public sealed record Scenario(object Data, string? ValueKey, string? DisplayKey);

public static Scenario Get(string name) => name switch
{
"typed-products" => new(Products(), "Id", "Name"),
"objects-as-values" => new(Products(), null, "Name"),
"observable-products" => new(new ObservableCollection<Product>(Products()), "Id", "Name"),
"nullable-readings" => new(new List<Reading>
{
new() { Id = 1, Label = "full", Quantity = 5, Value = 2.5, Flagged = true, MeasuredOn = new DateTime(2026, 3, 3) },
new() { Id = 2, Label = "empty", Quantity = null, Value = null, Flagged = null, MeasuredOn = null },
new() { Id = 3, Label = "mixed", Quantity = 7, Value = null, Flagged = false, MeasuredOn = null },
}, "Id", "Label"),
"nested-orders" => new(new List<Order>
{
new() { Id = 1, Reference = "ORD-1", Customer = new Customer { Name = "Maria", City = "Berlin" } },
new() { Id = 2, Reference = "ORD-2", Customer = new Customer { Name = "Ana", City = "Madrid" } },
}, "Id", "Reference"),
"nested-field-shipments" => new(new List<Shipment>
{
new() { Id = 1, Code = "SHP-1", Box = new BoxSize { Width = 2.5, Height = 1.5 } },
new() { Id = 2, Code = "SHP-2", Box = new BoxSize { Width = 4.0, Height = 3.0 } },
}, "Id", "Code"),
"primitive-strings" => new(new List<string> { "alpha", "beta", "gamma" }, null, null),
_ => throw new ArgumentException($"Unknown combo data scenario \"{name}\".", nameof(name)),
};

public static List<Product> Products() =>
[
new() { Id = 1, Name = "Chai", Price = 18.5, Discontinued = false, UnitsSold = 42_000_000_000, Restocked = new DateTime(2026, 1, 15) },
new() { Id = 2, Name = "Chang", Price = 19.0, Discontinued = true, UnitsSold = 7, Restocked = new DateTime(2025, 6, 30) },
new() { Id = 3, Name = "Aniseed Syrup", Price = 10.0, Discontinued = false, UnitsSold = 1300, Restocked = new DateTime(2024, 12, 1) },
];

public static Product AddedProduct() =>
new() { Id = 4, Name = "Added", Price = 4.4, UnitsSold = 4, Restocked = new DateTime(2026, 4, 4) };

public static Product ReplacementProduct() =>
new() { Id = 99, Name = "Replaced", Price = 9.9, UnitsSold = 9, Restocked = new DateTime(2026, 9, 9) };

public class Product
{
public int Id { get; set; }
public string Name { get; set; } = "";
public double Price { get; set; }
public bool Discontinued { get; set; }
public long UnitsSold { get; set; }
public DateTime Restocked { get; set; }
}

public class Reading
{
public int Id { get; set; }
public string Label { get; set; } = "";
public int? Quantity { get; set; }
public double? Value { get; set; }
public bool? Flagged { get; set; }
public DateTime? MeasuredOn { get; set; }
}

public class Order
{
public int Id { get; set; }
public string Reference { get; set; } = "";
public Customer Customer { get; set; } = new();
}

public class Customer
{
public string Name { get; set; } = "";
public string City { get; set; } = "";
}

public class Shipment
{
public int Id { get; set; }
public string Code { get; set; } = "";
public BoxSize Box { get; set; } = new();
}

public class BoxSize
{
public double Width;
public double Height;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\IgniteUI.Blazor.Lite.csproj" />
</ItemGroup>

</Project>
Loading
Loading