Skip to content

Commit 64a01b5

Browse files
committed
Stabilize editor cue hover verification
1 parent 7664635 commit 64a01b5

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

src/PrompterOne.Shared/wwwroot/editor/editor-monaco.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,40 @@ function ensureHarness(options) {
557557
y: editorBounds.top + visiblePosition.top + (visiblePosition.height / 2)
558558
};
559559
},
560+
getRenderedDecorationCoordinates: (testId, className, textContent) => {
561+
const state = getRequiredHarnessState(testId);
562+
const token = String(className ?? emptyValue).trim().replace(/^\./, emptyValue);
563+
if (!/^[a-zA-Z0-9_-]+$/.test(token)) {
564+
return null;
565+
}
566+
567+
state.editor.render(true);
568+
const editorNode = state.editor.getDomNode();
569+
if (!editorNode) {
570+
return null;
571+
}
572+
573+
const expectedText = String(textContent ?? emptyValue).trim();
574+
const elements = Array.from(editorNode.querySelectorAll(`.${token}`));
575+
const element = elements.find(candidate => {
576+
const bounds = candidate.getBoundingClientRect();
577+
if (bounds.width <= 0 || bounds.height <= 0) {
578+
return false;
579+
}
580+
581+
return !expectedText || String(candidate.textContent ?? emptyValue).includes(expectedText);
582+
});
583+
if (!element) {
584+
return null;
585+
}
586+
587+
const bounds = element.getBoundingClientRect();
588+
return {
589+
height: bounds.height,
590+
x: bounds.left + (bounds.width / 2),
591+
y: bounds.top + (bounds.height / 2)
592+
};
593+
},
560594
setSelection: async (testId, start, end, revealSelection = true, selectionDirection = undefined) => {
561595
const state = getRequiredHarnessState(testId);
562596
applySelection(state, start ?? 0, end ?? 0, revealSelection !== false, selectionDirection);

tests/PrompterOne.Web.UITests.Editor/Editor/EditorCueRenderingFlowTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ await page.WaitForFunctionAsync(
213213
await Assert.That(energyHover!.Contents).Contains(content => content.Contains("Energy contour", StringComparison.Ordinal));
214214
await Assert.That(melodyHover!.Contents).Contains(content => content.Contains("Melody contour", StringComparison.Ordinal));
215215

216-
var energyPoint = await EditorMonacoDriver.GetPositionCoordinatesAsync(page, 5, FindColumn(contourLine, "steady"));
216+
var energyPoint = await EditorMonacoDriver.GetRenderedDecorationCoordinatesAsync(page, "po-inline-energy", "steady");
217217
await page.Mouse.MoveAsync((float)energyPoint.X, (float)energyPoint.Y);
218-
await Expect(page.Locator(".monaco-hover").First).ToContainTextAsync("Energy contour", new()
218+
await Expect(page.Locator(".monaco-hover:not(.hidden)").First).ToContainTextAsync("Energy contour", new()
219219
{
220220
Timeout = BrowserTestConstants.Timing.DefaultVisibleTimeoutMs
221221
});

tests/PrompterOne.Web.UITests/Support/EditorMonacoDriver.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ internal static async Task<EditorMonacoPositionCoordinates> GetPositionCoordinat
165165
return coordinates!;
166166
}
167167

168+
internal static async Task<EditorMonacoPositionCoordinates> GetRenderedDecorationCoordinatesAsync(IPage page, string className, string textContent)
169+
{
170+
var coordinates = await InvokeHarnessAsync<EditorMonacoPositionCoordinates?>(page, "getRenderedDecorationCoordinates", new
171+
{
172+
className,
173+
textContent
174+
});
175+
176+
await Assert.That(coordinates).IsNotNull();
177+
return coordinates!;
178+
}
179+
168180
internal static async Task<EditorMonacoTokenizedLine> TokenizeLineAsync(IPage page, int lineNumber)
169181
{
170182
var tokenizedLine = await InvokeHarnessAsync<EditorMonacoTokenizedLine?>(page, "tokenizeLine", new

0 commit comments

Comments
 (0)