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

Re-enable mention intermittent failed cases #2403

Merged
merged 11 commits into from
Oct 14, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Re-enable mention intermittently failed test cases",
"packageName": "@ni/nimble-components",
"email": "123377167+aagash-ni@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,29 @@ export class RichTextEditorPageObject {
toggleButton.control.dispatchEvent(event);
}

public pasteToEditor(text: string): void {
public async pasteToEditor(text: string): Promise<void> {
const editor = this.getTiptapEditor();
const pasteEvent = new ClipboardEvent('paste', {
clipboardData: new DataTransfer()
});
pasteEvent.clipboardData?.setData('text/plain', text);
editor.dispatchEvent(pasteEvent);

await this.focusEditorIfMentionListboxOpened();
}

// Simulate the actual pasting of content by passing the extracted HTML string as an argument and setting the format to 'text/html',
// as in the [DataFormat](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer) object.
// For example, when copying a link, the clipboard stores information that includes the anchor tag, href attribute value etc, and paste it as an HTML string
public pasteHTMLToEditor(htmlString: string): void {
public async pasteHTMLToEditor(htmlString: string): Promise<void> {
const editor = this.getTiptapEditor();
const pasteEvent = new ClipboardEvent('paste', {
clipboardData: new DataTransfer()
});
pasteEvent.clipboardData?.setData('text/html', htmlString);
editor.dispatchEvent(pasteEvent);

await this.focusEditorIfMentionListboxOpened();
}

public async setEditorTextContent(value: string): Promise<void> {
Expand All @@ -248,10 +252,7 @@ export class RichTextEditorPageObject {
.run();
await waitForUpdatesAsync();

if (this.isMentionListboxOpened()) {
this.richTextEditorElement.tiptapEditor.commands.focus();
await waitForUpdatesAsync();
}
await this.focusEditorIfMentionListboxOpened();
}

public async setCursorPosition(position: number): Promise<void> {
Expand All @@ -265,6 +266,8 @@ export class RichTextEditorPageObject {
const lastElement = this.getEditorLastChildElement();
lastElement.parentElement!.textContent = value;
await waitForUpdatesAsync();

await this.focusEditorIfMentionListboxOpened();
}

public async sliceEditorContent(from: number, to: number): Promise<void> {
Expand All @@ -274,18 +277,20 @@ export class RichTextEditorPageObject {
.deleteRange({ from, to })
.run();
await waitForUpdatesAsync();

await this.focusEditorIfMentionListboxOpened();
}

public getEditorLastChildAttribute(attribute: string): string {
return getLastChildElementAttribute(attribute, this.getTiptapEditor());
}

public isMentionListboxOpened(): boolean {
return (
!this.getMentionListbox()
?.shadowRoot?.querySelector(anchoredRegionTag)
?.hasAttribute('hidden') ?? false
);
public async isMentionListboxOpened(): Promise<boolean> {
await waitForUpdatesAsync();

return !this.getMentionListbox()?.shadowRoot?.querySelector(
anchoredRegionTag
)?.hidden;
}

public getEditorMentionViewAttributeValues(attribute: string): string[] {
Expand Down Expand Up @@ -439,6 +444,8 @@ export class RichTextEditorPageObject {
}

public async clickMentionListboxOption(index: number): Promise<void> {
await this.focusEditorIfMentionListboxOpened();

const listOption = this.getAllListItemsInMentionBox()[index];
listOption?.click();
await waitForUpdatesAsync();
Expand Down Expand Up @@ -530,4 +537,11 @@ export class RichTextEditorPageObject {
);
return parserMentionConfig;
}

private async focusEditorIfMentionListboxOpened(): Promise<void> {
if (await this.isMentionListboxOpened()) {
this.richTextEditorElement.tiptapEditor.commands.focus();
await waitForUpdatesAsync();
}
}
}
Loading