Skip to content

Commit 0b24c80

Browse files
committed
Tests for change
1 parent 4ccf522 commit 0b24c80

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

src/Components/test/E2ETest/Tests/VirtualizationTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,33 @@ public void AlwaysFillsVisibleCapacity_Async()
110110
int GetPlaceholderCount() => Browser.FindElements(By.Id("async-placeholder")).Count;
111111
}
112112

113+
[Fact]
114+
public void PlaceholdersHaveCorrectValue_Async()
115+
{
116+
Browser.MountTestComponent<VirtualizationQuickGrid>();
117+
118+
var finishLoadingButton = Browser.Exists(By.Id("finish-loading-button"));
119+
120+
finishLoadingButton.Click(); //not waiting
121+
122+
Browser.True(() => Browser.Exists(By.Id("loadDone")).Text != "111");
123+
124+
Browser.True(() => GetItemCount() > 0);
125+
Browser.Equal(0, () => GetPlaceholderCount());
126+
127+
Browser.ExecuteJavaScript("const container = document.getElementById('async-container'); container.scrollTop = container.scrollHeight * 0.5;");
128+
129+
Browser.Equal(0, () => GetItemCount());
130+
Browser.True(() => GetPlaceholderCount() > 0);
131+
132+
//test that the other placeholder has ...
133+
Browser.Equal("LOADING DATA", () => Browser.Exists(By.CssSelector(".async-placeholder")).Text);
134+
135+
136+
int GetItemCount() => Browser.FindElements(By.CssSelector("#async-container tbody tr:not(:has(.grid-cell-placeholder))")).Count;
137+
int GetPlaceholderCount() => Browser.FindElements(By.CssSelector(".grid-cell-placeholder")).Count;
138+
}
139+
113140
[Fact]
114141
public void RerendersWhenItemSizeShrinks_Sync()
115142
{

src/Components/test/testassets/BasicTestApp/Index.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<option value="BasicTestApp.VirtualizationMaxItemCount">Virtualization MaxItemCount</option>
118118
<option value="BasicTestApp.VirtualizationMaxItemCount_AppContext">Virtualization MaxItemCount (via AppContext)</option>
119119
<option value="BasicTestApp.VirtualizationTable">Virtualization HTML table</option>
120+
<option value="BasicTestApp.VirtualizationQuickGrid">Virtualization QuickGrid component</option>
120121
<option value="BasicTestApp.HotReload.RenderOnHotReload">Render on hot reload</option>
121122
<option value="BasicTestApp.SectionsTest.ParentComponentWithTwoChildren">Sections test</option>
122123
<option value="BasicTestApp.SectionsTest.SectionsWithCascadingParameters">Sections with Cascading parameters test</option>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
@using Microsoft.AspNetCore.Components.QuickGrid
2+
3+
4+
@if (RendererInfo.IsInteractive)
5+
{
6+
<button id="finish-loading-button" @onclick="@(async () => await FinishLoadingAsync(200))">Finish loading</button>
7+
}
8+
<br/>
9+
10+
@if (boolLoad != "no condition")
11+
{
12+
<p id="loadDone">@boolLoad</p>
13+
}
14+
15+
<div id="async-container" style="height: 500px; overflow-y: auto;">
16+
<QuickGrid @ref="asyncGrid" TGridItem="DataItem" ItemsProvider="GetItemsAsync" Virtualize="true" ItemSize="25">
17+
<PropertyColumn Property="@(p => p.Id)" class="async-id">
18+
</PropertyColumn>
19+
<PropertyColumn Property="@(p => p.SecondNum)" class="async-second">
20+
<PlaceholderTemplate>
21+
<strong class="async-placeholder">LOADING DATA</strong>
22+
</PlaceholderTemplate>
23+
</PropertyColumn>
24+
</QuickGrid>
25+
</div>
26+
27+
@code {
28+
record DataItem(int Id, int SecondNum);
29+
30+
QuickGrid<DataItem> asyncGrid;
31+
32+
int asyncTotalItemCount = 200;
33+
int asyncCancellationCount = 0;
34+
string boolLoad = "no condition";
35+
TaskCompletionSource asyncTcs = new TaskCompletionSource();
36+
37+
private async ValueTask<GridItemsProviderResult<DataItem>> GetItemsAsync(GridItemsProviderRequest<DataItem> request)
38+
{
39+
var loadingTask = asyncTcs.Task;
40+
var registration = request.CancellationToken.Register(() => CancelLoadingAsync(request.CancellationToken));
41+
42+
await loadingTask;
43+
44+
registration.Dispose();
45+
46+
var items = Enumerable.Range(request.StartIndex, request.Count ?? 200)
47+
.Select(i => new DataItem(i, i * 2))
48+
.ToArray();
49+
50+
return GridItemsProviderResult.From(items, asyncTotalItemCount);
51+
}
52+
53+
async Task FinishLoadingAsync(int totalItemCount)
54+
{
55+
asyncTotalItemCount = totalItemCount;
56+
asyncTcs.SetResult();
57+
asyncTcs = new TaskCompletionSource();
58+
59+
if (asyncGrid is not null)
60+
{
61+
await asyncGrid.RefreshDataAsync();
62+
boolLoad = "condition";
63+
}
64+
else
65+
{
66+
boolLoad = "asyncGrid null";
67+
}
68+
StateHasChanged();
69+
}
70+
71+
void CancelLoadingAsync(System.Threading.CancellationToken cancellationToken)
72+
{
73+
asyncTcs.TrySetCanceled(cancellationToken);
74+
asyncTcs = new TaskCompletionSource();
75+
76+
asyncCancellationCount++;
77+
78+
StateHasChanged();
79+
}
80+
}

src/Components/test/testassets/Components.TestServer/RazorComponents/ComplexValidationComponent.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@using Microsoft.AspNetCore.Components.Forms
44

55
@if(RendererInfo.IsInteractive) {
6-
<p id="is-interactive"></p>
6+
<p id="is-interactive">111</p>
77
}
88

99
@if (_invalid)

0 commit comments

Comments
 (0)