add tests
This commit is contained in:
Родитель
176378ae5f
Коммит
147c3058ac
|
@ -0,0 +1,55 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Playwright;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.TryDotNet.IntegrationTests;
|
||||
|
||||
public class EditorTests : PlaywrightTestBase
|
||||
{
|
||||
public EditorTests(PlaywrightFixture playwright, TryDotNetFixture tryDotNet) : base(playwright, tryDotNet)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task can_load_monaco_editor()
|
||||
{
|
||||
var page = await Playwright.Browser!.NewPageAsync();
|
||||
await page.GotoAsync(TryDotNet.Url + "editor");
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
var isVisible = await page.Locator("div[role = \"code\"]").IsVisibleAsync();
|
||||
|
||||
await page.TestScreenShotAsync();
|
||||
|
||||
isVisible.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task can_load_the_wasm_runner()
|
||||
{
|
||||
var wasmRunnerLoaded = false;
|
||||
var page = await Playwright.Browser!.NewPageAsync();
|
||||
|
||||
await page.RouteAsync("**/*", async route =>
|
||||
{
|
||||
if (route.Request.Url.Contains("blazor.webassembly.js"))
|
||||
{
|
||||
wasmRunnerLoaded = true;
|
||||
}
|
||||
|
||||
await route.ContinueAsync();
|
||||
});
|
||||
|
||||
await page.GotoAsync(TryDotNet.Url + "editor");
|
||||
await page.WaitForLoadStateAsync(LoadState.NetworkIdle);
|
||||
await page.Locator("div[role = \"code\"]").IsVisibleAsync();
|
||||
|
||||
await page.TestScreenShotAsync();
|
||||
|
||||
wasmRunnerLoaded.Should().BeTrue();
|
||||
}
|
||||
}
|
|
@ -16,11 +16,18 @@ internal static class PageExtensions
|
|||
return page.ScreenshotAsync(new PageScreenshotOptions {Path = $"screenshot_{testName}.png"});
|
||||
}
|
||||
|
||||
public static async Task SendRequest<T>(this IPage page, T data)
|
||||
public static async Task DispatchMessage<T>(this IPage page, T data)
|
||||
{
|
||||
await page.EvaluateAsync(@"(request) => window.dispatchEvent(new MessageEvent(""message"", { data: request }))",data);
|
||||
}
|
||||
|
||||
public static async Task TypeTextInMonacoEditor(this IPage page, string text, float? delay)
|
||||
{
|
||||
var editor = page.Locator(@"div[role = ""code""]");
|
||||
await editor.FocusAsync();
|
||||
await editor.TypeAsync(text, new LocatorTypeOptions{ Delay = delay});
|
||||
}
|
||||
|
||||
public static async Task<List<WasmRunnerMessage>> ExecuteAssembly(this IPage page, string base64EncodedAssembly)
|
||||
{
|
||||
var messages = new List<WasmRunnerMessage>();
|
||||
|
@ -36,7 +43,7 @@ internal static class PageExtensions
|
|||
}
|
||||
});
|
||||
|
||||
await page.SendRequest(new
|
||||
await page.DispatchMessage(new
|
||||
{
|
||||
type = "wasmRunner-command",
|
||||
base64EncodedAssembly = base64EncodedAssembly
|
||||
|
|
|
@ -11,7 +11,6 @@ using Xunit;
|
|||
|
||||
namespace Microsoft.TryDotNet.IntegrationTests;
|
||||
|
||||
|
||||
public class WasmRunnerTests : PlaywrightTestBase
|
||||
{
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
using System.Text.Json;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.Html;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
|
||||
namespace Microsoft.TryDotNet
|
||||
{
|
||||
|
@ -53,12 +51,12 @@ namespace Microsoft.TryDotNet
|
|||
<meta charset=""utf-8"">
|
||||
<title>TryDotNet Editor</title>
|
||||
<meta name=""viewport"" content=""width=device-width,initial-scale=1"">
|
||||
<script src=""api/editor/app.bundle.js"" id=""trydotnet-editor-script"" data-trydotnet-configuration=""{HttpUtility.HtmlAttributeEncode(configString)}""></script>
|
||||
<script src=""api/editor/editor.worker.bundle.js""></script>
|
||||
<script src=""api/editor/json.worker.bundle.js""></script>
|
||||
<script src=""api/editor/css.worker.bundle.js""></script>
|
||||
<script src=""api/editor/html.worker.bundle.js""></script>
|
||||
<script src=""api/editor/ts.worker.bundle.js""></script>
|
||||
<script defer=""defer"" src=""api/editor/app.bundle.js"" id=""trydotnet-editor-script"" data-trydotnet-configuration=""{HttpUtility.HtmlAttributeEncode(configString)}""></script>
|
||||
<script defer=""defer"" src=""api/editor/editor.worker.bundle.js""></script>
|
||||
<script defer=""defer"" src=""api/editor/json.worker.bundle.js""></script>
|
||||
<script defer=""defer"" src=""api/editor/css.worker.bundle.js""></script>
|
||||
<script defer=""defer"" src=""api/editor/html.worker.bundle.js""></script>
|
||||
<script defer=""defer"" src=""api/editor/ts.worker.bundle.js""></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.Text.Json;
|
|||
using Microsoft.DotNet.Interactive.CSharpProject;
|
||||
using Microsoft.DotNet.Interactive.Events;
|
||||
using Microsoft.DotNet.Interactive.Server;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.TryDotNet;
|
||||
|
||||
|
@ -56,10 +57,8 @@ public class Program
|
|||
{
|
||||
var html = await ContentGenerator.GenerateEditorPageAsync(request);
|
||||
response.ContentType = MediaTypeNames.Text.Html;
|
||||
|
||||
response.ContentLength = Encoding.UTF8.GetByteCount(html);
|
||||
await response.WriteAsync(html, Encoding.UTF8);
|
||||
return html;
|
||||
return Results.Content(html);
|
||||
});
|
||||
|
||||
app.MapPost("/commands", async (HttpRequest request) =>
|
||||
|
|
|
@ -8,7 +8,6 @@ import './index.css';
|
|||
import * as messageBus from './messageBus';
|
||||
import * as rxjs from 'rxjs';
|
||||
import * as monacoAdapterImpl from './monacoAdapterImpl';
|
||||
import * as dotnetInteractive from '@microsoft/dotnet-interactive';
|
||||
|
||||
if (window) {
|
||||
|
||||
|
|
|
@ -79,10 +79,6 @@ export class MonacoEditorAdapter extends editorAdapter.EditorAdapter {
|
|||
});
|
||||
}
|
||||
|
||||
setActiveBuffer(bufferId: string) {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
getCode(): string {
|
||||
return this._editor.getValue();
|
||||
}
|
||||
|
@ -105,6 +101,8 @@ export class MonacoEditorAdapter extends editorAdapter.EditorAdapter {
|
|||
|
||||
monaco.languages.registerCompletionItemProvider(language, {
|
||||
provideCompletionItems: (model: monaco.editor.ITextModel, position: monaco.Position, context: monaco.languages.CompletionContext, token: monaco.CancellationToken) => {
|
||||
|
||||
const kernel = this.kernel;
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче