Skip to content

Commit

Permalink
Merge pull request #315 from Lombiq/issue/OSOE-638
Browse files Browse the repository at this point in the history
OSOE-638: Adding monaco editor extensions
  • Loading branch information
Piedone authored Oct 16, 2023
2 parents 58b76d1 + 83bc7a3 commit e9b8d15
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Lombiq.Tests.UI/Extensions/FormUITestContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,37 @@ public static void SetMarkdownEasyMdeWysiwygEditor(this UITestContext context, s
context.ExecuteScript(script);
}

/// <summary>
/// Fills the <paramref name="editorId"/>-matching Monaco editor with the given <paramref name="text"/> by using JavaScript.
/// </summary>
public static void FillInMonacoEditor(
this UITestContext context,
string editorId,
string text)
{
var script = $@"
monaco.editor.getEditors().find((element) =>
element.getContainerDomNode().id == {JsonConvert.SerializeObject(editorId)})
.getModel().setValue({JsonConvert.SerializeObject(text)});";

context.ExecuteScript(script);
}

/// <summary>
/// Returns the current text of the <paramref name="editorId"/>-matching Monaco editor by using JavaScript.
/// </summary>
public static string GetMonacoEditorText(
this UITestContext context,
string editorId)
{
var script = $@"
return monaco.editor.getEditors().find((element) =>
element.getContainerDomNode().id == {JsonConvert.SerializeObject(editorId)})
.getModel().getValue();";

return context.ExecuteScript(script) as string;
}

public static void ClickAndClear(this UITestContext context, By by) =>
context.ExecuteLogged(
nameof(ClickAndClear),
Expand Down

0 comments on commit e9b8d15

Please sign in to comment.