chore: setup js interops for tests (#4066)

* setup js interops

* add more setup

* fix test
This commit is contained in:
James Yeung 2024-08-09 18:35:47 +08:00 committed by GitHub
parent 6124687ca2
commit 63223455d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.Threading.Tasks;
using AntDesign.JsInterop;
using Bunit;
using Microsoft.AspNetCore.Components;
@ -10,10 +11,10 @@ namespace AntDesign.Tests
{
public class AntDesignTestBase : TestContext, IDisposable
{
protected string DateFormat => "dd/MM/yyyy";
protected string TimeFormat = "yyyy-MM-dd HH:mm:ss";
protected const string DateFormat = "dd/MM/yyyy";
protected const string TimeFormat = "yyyy-MM-dd HH:mm:ss";
protected readonly CultureInfo Culture = CultureInfo.InvariantCulture;
public TestContext Context => this;
public NavigationManager NavigationManager => Services.GetRequiredService<NavigationManager>();
@ -24,8 +25,12 @@ namespace AntDesign.Tests
Services.AddAntDesign();
//Needed for Tests using Overlay
Services.AddScoped<AntDesign.JsInterop.DomEventService>(sp => new TestDomEventService(Context.JSInterop.JSRuntime, MockedDomEventListener));
Services.AddScoped<DomEventService>(sp => new TestDomEventService(Context.JSInterop.JSRuntime, MockedDomEventListener));
JSInterop.SetupVoid(JSInteropConstants.OverlayComponentHelper.DeleteOverlayFromContainer, _ => true);
JSInterop.SetupVoid("AntDesign.interop.tableHelper.bindTableScroll", _ => true);
JSInterop.Setup<Task>("AntDesign.interop.domManipulationHelper.blur").SetResult(Task.CompletedTask);
JSInterop.SetupVoid("AntDesign.interop.domManipulationHelper.smoothScrollTo", _ => true);
JSInterop.Mode = JSRuntimeMode.Strict;
LocaleProvider.SetLocale("en-US");