-
Notifications
You must be signed in to change notification settings - Fork 8
test: cover the unmarshalled (WASM) data channel #373
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
Open
damyanpetev
wants to merge
3
commits into
master
Choose a base branch
from
dpetev/unmarshalled-coverage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
tests/IgniteUI.Blazor.Lite.IntegrationTests/ComboDataTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| 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
97
tests/IgniteUI.Blazor.Lite.TestBed.Client/ComboDataScenarios.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
tests/IgniteUI.Blazor.Lite.TestBed.Client/IgniteUI.Blazor.Lite.TestBed.Client.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.