Skip to content

Commit 50eb4db

Browse files
Add OnChangeAfter integration test (#4753)
1 parent bcbbe29 commit 50eb4db

3 files changed

Lines changed: 77 additions & 2 deletions

File tree

tests/Integration/Components/FluentPlaywrightBaseTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ protected FluentPlaywrightBaseTest(ITestOutputHelper output, StartServerFixture
3737
/// </summary>
3838
protected virtual StartServerFixture Server { get; set; }
3939

40-
public async Task<IPage> WaitOpenPageAsync(string url, bool? openDevTools = null)
40+
public async Task<IPage> WaitOpenPageAsync(string url, bool? openDevTools = null, bool? openHeadlessBrowser = null)
4141
{
4242
_playwright = await Playwright.Playwright.CreateAsync();
4343
_browser = await _playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions()
4444
{
45-
Devtools = openDevTools
45+
Devtools = openDevTools,
46+
Headless = openHeadlessBrowser
4647
});
4748

4849
var page = await _browser.NewPageAsync();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@page "/list/autocomplete/onchange-after"
2+
3+
<div>
4+
Current count: <span data-testid="current-value">@countAfter</span>
5+
</div>
6+
7+
<FluentAutocomplete TValue="string"
8+
TOption="string"
9+
Label="Test"
10+
Items="Options"
11+
@bind-SelectedItems="SelectedItems"
12+
@bind-SelectedItems:after="AfterChanged" />
13+
14+
@code
15+
{
16+
string test = string.Empty;
17+
int countAfter = 0;
18+
IEnumerable<string> SelectedItems { get; set; } = [];
19+
20+
void AfterChanged()
21+
{
22+
countAfter++;
23+
}
24+
25+
List<string> Options = new List<string>
26+
{
27+
"Option 1",
28+
"Option 2",
29+
"Option 3",
30+
"Option 4",
31+
"Option 5"
32+
};
33+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// ------------------------------------------------------------------------
2+
// This file is licensed to you under the MIT License.
3+
// ------------------------------------------------------------------------
4+
5+
using Microsoft.FluentUI.AspNetCore.Components.IntegrationTests.WebServer;
6+
using Microsoft.Playwright;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
namespace Microsoft.FluentUI.AspNetCore.Components.IntegrationTests.Components.List;
11+
12+
[Collection(StartServerCollection.Name)]
13+
public class FluentAutocompleteTests : FluentPlaywrightBaseTest
14+
{
15+
public FluentAutocompleteTests(ITestOutputHelper output, StartServerFixture server)
16+
: base(output, server)
17+
{
18+
}
19+
20+
[Fact(Skip = "Playwright is optional for the moment. This test will fail.")]
21+
public async Task FluentAutocomplete_OnChangeAfter()
22+
{
23+
// Arrange
24+
var page = await WaitOpenPageAsync($"/list/autocomplete/onchange-after", openDevTools: false);
25+
26+
// Act
27+
await page.ClickAsync("fluent-text-input");
28+
await page.ClickAsync("fluent-option");
29+
await Task.Delay(100); // Wait for the onChange event to propagate
30+
31+
// Assert
32+
await page.ScreenshotAsync(new()
33+
{
34+
Path = $"{Server.ScreenshotsFolder}FluentAutocomplete_OnChangeAfter.png"
35+
});
36+
37+
await Assertions.Expect(page.GetByTestId("current-value"))
38+
.ToContainTextAsync("1");
39+
}
40+
}
41+

0 commit comments

Comments
 (0)