Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/pax.BlazorChartJs.samplelib/BarChartComp.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions src/pax.BlazorChartJs.samplelib/LineChartComp.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void RemoveData()

private void RemoveLabel()
{
if (!Data.Labels.Any())
if (Data.Labels.Count == 0)
{
return;
}
Expand All @@ -31,7 +31,7 @@ private void RemoveLabel()

private static void RemoveDatasetData(ChartJsDataset dataset)
{
if (!dataset.Data.Any())
if (dataset.Data.Count == 0)
{
return;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
26 changes: 26 additions & 0 deletions tests/pax.BlazorChartJs.pwtests/ChartEventsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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!;
}

Expand Down
26 changes: 15 additions & 11 deletions tests/pax.BlazorChartJs.pwtests/DisposeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>("() => 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");
Expand Down
4 changes: 3 additions & 1 deletion tests/pax.BlazorChartJs.pwtests/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions tests/pax.BlazorChartJs.pwtests/pax.BlazorChartJs.pwtests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.58.0" />
<PackageReference Include="NUnit" Version="4.5.1" />
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.12.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.64.1" />
<PackageReference Include="NUnit" Version="5.0.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.3.1" />
<PackageReference Include="NUnit.Analyzers" Version="4.15.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="8.0.1">
<PackageReference Include="coverlet.collector" Version="10.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions tests/pax.BlazorChartJs.tests/pax.BlazorChartJs.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PackageReference Include="coverlet.collector" Version="10.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MSTest" Version="4.0.2" />
<PackageReference Include="MSTest" Version="4.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading