Skip to content
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

Refactor internal frame tracking & time handling #29

Merged
merged 19 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
update tests to use TestTimeProvider
  • Loading branch information
DavidVollmers committed Sep 29, 2023
commit 4e681ee2e1a1b4495edf833063f3f692a13bc320
1 change: 1 addition & 0 deletions packages/Ignis.Components/Ignis.Components.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<InternalsVisibleTo Include="Ignis.Components.HeadlessUI"/>
<InternalsVisibleTo Include="Ignis.Components.Reactivity"/>
<InternalsVisibleTo Include="Ignis.Components.Web"/>
<InternalsVisibleTo Include="Ignis.Tests.Common"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
Expand Down
18 changes: 18 additions & 0 deletions tests/Ignis.Tests.Common/IgnisTestExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Ignis.Components;
using Microsoft.Extensions.DependencyInjection;

namespace Ignis.Tests.Common;

public static class IgnisTestExtensions
{
public static IServiceCollection AddIgnisTestServices(this IServiceCollection serviceCollection)
{
if (serviceCollection == null) throw new ArgumentNullException(nameof(serviceCollection));

serviceCollection.AddIgnis();
serviceCollection.AddSingleton<IHostContext, TestHostContext>();
serviceCollection.AddSingleton<TimeProvider, TestTimeProvider>();

return serviceCollection;
}
}
2 changes: 1 addition & 1 deletion tests/Ignis.Tests.Common/TestHostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ignis.Tests.Common;

public class TestHostContext : IHostContext
internal class TestHostContext : IHostContext
{
public bool IsPrerendering => false;

Expand Down
11 changes: 11 additions & 0 deletions tests/Ignis.Tests.Common/TestTimeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Ignis.Components;

namespace Ignis.Tests.Common;

internal class TestTimeProvider : TimeProvider
{
public override Timer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
{
return base.CreateTimer(callback, state, TimeSpan.Zero, TimeSpan.Zero);
}
}
29 changes: 11 additions & 18 deletions tests/Ignis.Tests.Components.HeadlessUI/DialogTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[Fact]
public void Outlet()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand All @@ -29,8 +28,7 @@
[Fact]
public void IgnoreOutlet()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand All @@ -53,8 +51,7 @@
[Fact]
public void OutletWithTransition()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand Down Expand Up @@ -85,8 +82,7 @@
[Fact]
public void IgnoreOutletWithTransition()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand Down Expand Up @@ -117,8 +113,7 @@
[Fact]
public async Task OutletWithTransitionAndChildren()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand Down Expand Up @@ -164,8 +159,7 @@
[Fact]
public async Task OutletWithTransitionAndChildren_EnterLeaveWithDuration()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand Down Expand Up @@ -229,8 +223,7 @@
[Fact]
public async Task CustomModal_OpenCloseByButton()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand All @@ -248,11 +241,11 @@

var closeButton = cut.WaitForElement($"#{closeButtonId}");
Assert.True(outlet.Contains(closeButton));

closeButton.Click();

await Task.Delay(400);

cut.WaitForState(() => cut.FindAll($"#{closeButtonId}").Count == 0);
outlet = cut.Find($"#{outletId}");
Assert.Empty(outlet.Children);
}
Expand Down
11 changes: 4 additions & 7 deletions tests/Ignis.Tests.Components.HeadlessUI/ListboxTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[Fact]
public void Button_OnClick()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand All @@ -28,8 +27,7 @@
[Fact]
public void Button_OnClick_PreventDefault()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand All @@ -47,8 +45,7 @@
[Fact]
public async Task ListboxInDialog()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand All @@ -64,7 +61,7 @@
var listboxButton = cut.WaitForElement($"#{listboxButtonId}");
listboxButton.Click();

var intOption = cut.Find($"#{intOptionId}");
var intOption = cut.WaitForElement($"#{intOptionId}");
intOption.Click();

cut.WaitForAssertion(() =>
Expand Down
6 changes: 2 additions & 4 deletions tests/Ignis.Tests.Components.HeadlessUI/MenuTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[Fact]
public void Button_OnClick()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand All @@ -28,8 +27,7 @@
[Fact]
public void Button_OnClick_PreventDefault()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand Down
6 changes: 2 additions & 4 deletions tests/Ignis.Tests.Components.HeadlessUI/PopoverTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[Fact]
public void Button_OnClick()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand All @@ -28,8 +27,7 @@
[Fact]
public void Button_OnClick_PreventDefault()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

JSInterop.Mode = JSRuntimeMode.Loose;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[Fact]
public void Test()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

var cut = RenderComponent<AlternatingCounter>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[Fact]
public void SilentCounter()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

var cut = RenderComponent<SilentCounter>();
Assert.Equal(1, cut.RenderCount);
Expand All @@ -25,8 +24,7 @@
[Fact]
public void ReactiveCounter()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

var cut = RenderComponent<ReactiveCounter>();
Assert.Equal(1, cut.RenderCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[Fact]
public void Cycle()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

const string echo1 = "Hello World!";
const string echo2 = "Lorem Ipsum dolor sit amet.";
Expand All @@ -27,8 +26,7 @@
[Fact]
public void AlreadyDisposed()
{
Services.AddIgnis();
Services.AddSingleton<IHostContext, TestHostContext>();
Services.AddIgnisTestServices();

const string echo1 = "Hello World!";
const string echo2 = "Lorem Ipsum dolor sit amet.";
Expand Down