diff --git a/README.md b/README.md index 0cbac2b3..f04838fb 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Release | Chart.js | Tested Chart.js ---|---|--- ->= 0.5.0 | **4.x** | 4.5.1 +>= 0.5.0 | **4.x** | 4.6.1 ## Highlights diff --git a/src/pax.BlazorChartJs.samplelib/BarChartComp.razor.cs b/src/pax.BlazorChartJs.samplelib/BarChartComp.razor.cs index 7b49d6b9..152e575c 100644 --- a/src/pax.BlazorChartJs.samplelib/BarChartComp.razor.cs +++ b/src/pax.BlazorChartJs.samplelib/BarChartComp.razor.cs @@ -250,7 +250,7 @@ private void AddDataset() private void RemoveLastDataset() { - if (chartJsConfig.Data.Datasets.Any()) + if (chartJsConfig.Data.Datasets.Count != 0) { chartJsConfig.RemoveDataset(chartJsConfig.Data.Datasets.Last()); } diff --git a/src/pax.BlazorChartJs.samplelib/LineChartComp.razor.cs b/src/pax.BlazorChartJs.samplelib/LineChartComp.razor.cs index 8e15b5d2..16eb93d5 100644 --- a/src/pax.BlazorChartJs.samplelib/LineChartComp.razor.cs +++ b/src/pax.BlazorChartJs.samplelib/LineChartComp.razor.cs @@ -231,7 +231,7 @@ private void AddDataset() private void RemoveLastDataset() { - if (chartJsConfig.Data.Datasets.Any()) + if (chartJsConfig.Data.Datasets.Count != 0) { chartJsConfig.RemoveDataset(chartJsConfig.Data.Datasets.Last()); } @@ -249,7 +249,7 @@ private void RemoveAllDatasets() private void Fill() { - if (chartJsConfig.Data.Datasets.Any()) + if (chartJsConfig.Data.Datasets.Count != 0) { var lineDataset = chartJsConfig.Data.Datasets.First() as LineDataset; if (lineDataset != null) diff --git a/src/pax.BlazorChartJs/ChartJsConfig/ChartJsConfig.RemoveData.cs b/src/pax.BlazorChartJs/ChartJsConfig/ChartJsConfig.RemoveData.cs index 1547644c..1ca4c30c 100644 --- a/src/pax.BlazorChartJs/ChartJsConfig/ChartJsConfig.RemoveData.cs +++ b/src/pax.BlazorChartJs/ChartJsConfig/ChartJsConfig.RemoveData.cs @@ -21,7 +21,7 @@ public void RemoveData() private void RemoveLabel() { - if (!Data.Labels.Any()) + if (Data.Labels.Count == 0) { return; } @@ -31,7 +31,7 @@ private void RemoveLabel() private static void RemoveDatasetData(ChartJsDataset dataset) { - if (!dataset.Data.Any()) + if (dataset.Data.Count == 0) { return; } diff --git a/tests/README.md b/tests/README.md index 9a89e2f4..891aa1ab 100644 --- a/tests/README.md +++ b/tests/README.md @@ -39,3 +39,18 @@ dotnet test .\tests\pax.BlazorChartJs.pwtests\pax.BlazorChartJs.pwtests.csproj ``` Clear that environment variable to return to the self-hosted path. + +```powershell +Remove-Item Env:PWTESTS_SampleBaseUrl -ErrorAction SilentlyContinue +``` + +## Readiness and intermittent failures + +Page-title and chart-readiness checks allow up to 30 seconds for cold WASM startup; +they finish as soon as the expected state appears. A title timeout can indicate +that the app has not finished starting, rather than a Chart.js failure. + +The event callback tests wait for the initial animation-complete event to reach +Blazor before interacting with the chart. Chart registration alone is too early: +animation events can overwrite a click event in the sample's shared latest-event +display. Keep this readiness check when adding interaction tests. diff --git a/tests/pax.BlazorChartJs.pwtests/ChartEventsTests.cs b/tests/pax.BlazorChartJs.pwtests/ChartEventsTests.cs index 4434f906..ceeac3c6 100644 --- a/tests/pax.BlazorChartJs.pwtests/ChartEventsTests.cs +++ b/tests/pax.BlazorChartJs.pwtests/ChartEventsTests.cs @@ -376,6 +376,13 @@ public async Task HoverEventTest() // wait for ChartJs to load await Task.Delay(Startup.ChartJsLoadDelay); + await Expect(Page.GetByTestId("latest-chart-event")).ToHaveTextAsync( + new Regex(@"ChartJsAnimationCompleteEvent.*Initial = True"), + new Microsoft.Playwright.LocatorAssertionsToHaveTextOptions + { + Timeout = (float)Startup.WasmLoadDelay.TotalMilliseconds + }); + await canvas.HoverAsync(new Microsoft.Playwright.LocatorHoverOptions() { Position = new Microsoft.Playwright.Position() { X = 100, Y = 100 } @@ -480,6 +487,15 @@ await canvas.ClickAsync(new Microsoft.Playwright.LocatorClickOptions() var addEvents = Page.GetByText("AddEvents", new Microsoft.Playwright.PageGetByTextOptions() { Exact = true }); await addEvents.ClickAsync(); + // Replacing options starts a new animation. Wait for that update to + // finish before asserting a click in the shared latest-event display. + await Expect(clickResult).ToHaveTextAsync( + new Regex(@"ChartJsAnimationCompleteEvent.*Initial = False"), + new Microsoft.Playwright.LocatorAssertionsToHaveTextOptions + { + Timeout = (float)Startup.WasmLoadDelay.TotalMilliseconds + }); + await canvas.ClickAsync(new Microsoft.Playwright.LocatorClickOptions() { Position = new Microsoft.Playwright.Position() { X = 100, Y = 100 } @@ -582,6 +598,16 @@ await Page.WaitForFunctionAsync( canvasId, new Microsoft.Playwright.PageWaitForFunctionOptions { Timeout = (float)Startup.WasmLoadDelay.TotalMilliseconds }); + // Chart registration precedes its initial animation and Blazor event delivery. + // Wait for the rendered completion event so it cannot overwrite the interaction + // being asserted in the sample's shared latest-event display. + await Expect(Page.GetByTestId("latest-chart-event")).ToHaveTextAsync( + new Regex(@"ChartJsAnimationCompleteEvent.*Initial = True"), + new Microsoft.Playwright.LocatorAssertionsToHaveTextOptions + { + Timeout = (float)Startup.WasmLoadDelay.TotalMilliseconds + }); + return canvasId!; } diff --git a/tests/pax.BlazorChartJs.pwtests/DisposeTests.cs b/tests/pax.BlazorChartJs.pwtests/DisposeTests.cs index be623d00..19051d0f 100644 --- a/tests/pax.BlazorChartJs.pwtests/DisposeTests.cs +++ b/tests/pax.BlazorChartJs.pwtests/DisposeTests.cs @@ -66,24 +66,28 @@ public async Task DatasetInteropAfterDisposeIsIgnored() var canvasId = await Page.Locator("canvas").GetAttributeAsync("id"); Assert.That(Guid.TryParse(canvasId, out _), Is.True); + await Page.WaitForFunctionAsync( + "chartId => window.Chart !== undefined && Chart.getChart(chartId) !== undefined", + canvasId, + new Microsoft.Playwright.PageWaitForFunctionOptions { Timeout = (float)Startup.WasmLoadDelay.TotalMilliseconds }); + + // Use the running app's interop version, including for external targets. + // A version bump must not silently skip this regression. var chartInteropVersion = await Page.EvaluateAsync("() => window.chartJsInteropVersion ?? ''"); - if (chartInteropVersion != "0.9.0-preview2") - { - Assert.Ignore($"The configured sample site is serving pax.BlazorChartJs {chartInteropVersion}; this regression requires 0.9.0-preview2."); - } + Assert.That(chartInteropVersion, Is.Not.Empty, "The initialized app must expose its interop version."); await Page.GotoAsync(Startup.GetSampleBaseUrl()); await Page.EvaluateAsync( - @"async (chartId) => { - const chartInterop = await import('./_content/pax.BlazorChartJs/chartJsInterop.js?v=0.9.1'); + @"async ({ chartId, version }) => { + const chartInterop = await import('./_content/pax.BlazorChartJs/chartJsInterop.js?v=' + encodeURIComponent(version)); const dataset = { id: 'disposed-test', label: 'Disposed Test', data: [1, 2, 3] }; - chartInterop.addDatasets(chartId, [dataset]); - chartInterop.updateDatasets(chartId, [dataset]); - chartInterop.removeDatasets(chartId, [dataset.id]); - chartInterop.setDatasets(chartId, [dataset]); + await chartInterop.addDatasets(chartId, [dataset]); + await chartInterop.updateDatasets(chartId, [dataset]); + await chartInterop.removeDatasets(chartId, [dataset.id]); + await chartInterop.setDatasets(chartId, [dataset]); }", - canvasId); + new { chartId = canvasId, version = chartInteropVersion }); var error = Page.GetByText("An unhandled error has occurred.", new Microsoft.Playwright.PageGetByTextOptions() { Exact = false }); await Expect(error).ToHaveCSSAsync("display", "none"); diff --git a/tests/pax.BlazorChartJs.pwtests/Startup.cs b/tests/pax.BlazorChartJs.pwtests/Startup.cs index f91c25fd..da0455bc 100644 --- a/tests/pax.BlazorChartJs.pwtests/Startup.cs +++ b/tests/pax.BlazorChartJs.pwtests/Startup.cs @@ -7,7 +7,9 @@ namespace PlaywrightTests; public static class Startup { - internal static readonly TimeSpan WasmLoadDelay = TimeSpan.FromSeconds(10); + // Cold WASM startup can take longer under parallel browser load. Assertions + // poll for readiness and return immediately once it is reached. + internal static readonly TimeSpan WasmLoadDelay = TimeSpan.FromSeconds(30); internal static readonly TimeSpan ChartJsLoadDelay = TimeSpan.FromMilliseconds(1500); internal static readonly TimeSpan ChartJsComputeDelay = TimeSpan.FromMilliseconds(10); diff --git a/tests/pax.BlazorChartJs.pwtests/pax.BlazorChartJs.pwtests.csproj b/tests/pax.BlazorChartJs.pwtests/pax.BlazorChartJs.pwtests.csproj index 3a09bd51..9b99eee6 100644 --- a/tests/pax.BlazorChartJs.pwtests/pax.BlazorChartJs.pwtests.csproj +++ b/tests/pax.BlazorChartJs.pwtests/pax.BlazorChartJs.pwtests.csproj @@ -10,15 +10,15 @@ - - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/pax.BlazorChartJs.tests/pax.BlazorChartJs.tests.csproj b/tests/pax.BlazorChartJs.tests/pax.BlazorChartJs.tests.csproj index 25c7ab85..cd2eaff8 100644 --- a/tests/pax.BlazorChartJs.tests/pax.BlazorChartJs.tests.csproj +++ b/tests/pax.BlazorChartJs.tests/pax.BlazorChartJs.tests.csproj @@ -9,11 +9,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - +