Skip to content

Commit

Permalink
Make the loop count to 2000
Browse files Browse the repository at this point in the history
  • Loading branch information
vivinkrishna-ni committed Oct 4, 2024
1 parent 1988b66 commit 5e97c1d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class RichTextEditorPageObject {
.run();
await waitForUpdatesAsync();

if (this.isMentionListboxOpened()) {
if (await this.isMentionListboxOpened()) {
this.richTextEditorElement.tiptapEditor.commands.focus();
await waitForUpdatesAsync();
}
Expand Down Expand Up @@ -280,12 +280,31 @@ export class RichTextEditorPageObject {
return getLastChildElementAttribute(attribute, this.getTiptapEditor());
}

public isMentionListboxOpened(): boolean {
return (
!this.getMentionListbox()
?.shadowRoot?.querySelector(anchoredRegionTag)
?.hasAttribute('hidden') ?? false
);
public async isMentionListboxOpened(): Promise<boolean> {
const mentionListbox = this.getMentionListbox();
if (!mentionListbox) {
// eslint-disable-next-line no-console
console.log('Mention listbox not found');
return false;
}
const shadowRoot = mentionListbox.shadowRoot;
if (!shadowRoot) {
// eslint-disable-next-line no-console
console.log('Mention listbox shadow root not found');
return false;
}

const anchoredRegion = shadowRoot.querySelector(anchoredRegionTag);
if (!anchoredRegion) {
// eslint-disable-next-line no-console
console.log('Anchored region not found');
return false;
}
await waitForUpdatesAsync();

// eslint-disable-next-line no-console
console.log('Anchored region hidden attribute:', !anchoredRegion.hasAttribute('hidden'), anchoredRegion.getAttribute('hidden'));
return !anchoredRegion.hasAttribute('hidden');
}

public getEditorMentionViewAttributeValues(attribute: string): string[] {
Expand Down Expand Up @@ -439,11 +458,13 @@ export class RichTextEditorPageObject {
}

public async clickMentionListboxOption(index: number): Promise<void> {
if (this.isMentionListboxOpened()) {
this.richTextEditorElement.tiptapEditor.commands.focus();
await waitForUpdatesAsync();
}
// if (await this.isMentionListboxOpened()) {
// this.richTextEditorElement.tiptapEditor.commands.focus();
// await waitForUpdatesAsync();
// }
const listOption = this.getAllListItemsInMentionBox()[index];
// eslint-disable-next-line no-console
console.log('Editor focus status:', this.richTextEditorElement.tiptapEditor.isFocused);
listOption?.click();
await waitForUpdatesAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ describe('RichTextEditor user mention via template', () => {
it('should open mention popup, when button clicked', async () => {
await pageObject.clickUserMentionButton();

expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
});
});

Expand Down Expand Up @@ -1106,9 +1106,9 @@ describe('RichTextEditorMentionListbox', () => {
{ key: 'user:1', displayName: 'username1' },
{ key: 'user:2', displayName: 'username2' }
]);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
await pageObject.setEditorTextContent('@');
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
expect(pageObject.getMentionListboxItemsName()).toEqual([
'username1',
'username2'
Expand Down Expand Up @@ -1145,9 +1145,9 @@ describe('RichTextEditorMentionListbox', () => {
{ key: 'user:1', displayName: 'username1' },
{ key: 'user:2', displayName: 'username2' }
]);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
await pageObject.setEditorTextContent('@');
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
expect(pageObject.getMentionListboxItemsName()).toEqual([
'username1',
'username2'
Expand Down Expand Up @@ -1179,9 +1179,9 @@ describe('RichTextEditorMentionListbox', () => {
await appendUserMentionConfiguration(element, [
{ key: 'user:1', displayName: 'username1' }
]);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
await pageObject.setEditorTextContent('@');
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
await pageObject.clickMentionListboxOption(0);

expect(pageObject.getMarkdownRenderedTagNames()).toEqual([
Expand All @@ -1191,16 +1191,16 @@ describe('RichTextEditorMentionListbox', () => {
expect(
pageObject.getEditorMentionViewAttributeValues('mention-label')
).toEqual(['username1']);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
});

it('should commit mention into the editor on Enter', async () => {
await appendUserMentionConfiguration(element, [
{ key: 'user:1', displayName: 'username1' }
]);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
await pageObject.setEditorTextContent('@');
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
await pageObject.pressEnterKeyInEditor();

expect(pageObject.getMarkdownRenderedTagNames()).toEqual([
Expand All @@ -1210,16 +1210,16 @@ describe('RichTextEditorMentionListbox', () => {
expect(
pageObject.getEditorMentionViewAttributeValues('mention-label')
).toEqual(['username1']);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
});

it('should commit mention into the editor on Tab', async () => {
await appendUserMentionConfiguration(element, [
{ key: 'user:1', displayName: 'username1' }
]);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
await pageObject.setEditorTextContent('@');
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
await pageObject.pressTabKeyInEditor();

expect(pageObject.getMarkdownRenderedTagNames()).toEqual([
Expand All @@ -1229,19 +1229,19 @@ describe('RichTextEditorMentionListbox', () => {
expect(
pageObject.getEditorMentionViewAttributeValues('mention-label')
).toEqual(['username1']);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
});

it('should close the popup when clicking Escape', async () => {
await appendUserMentionConfiguration(element, [
{ key: 'user:1', displayName: 'username1' },
{ key: 'user:2', displayName: 'username2' }
]);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
await pageObject.setEditorTextContent('@');
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
await pageObject.pressEscapeKeyInEditor();
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
});

it('should filter and commit first mention into the editor on Enter', async () => {
Expand Down Expand Up @@ -1323,7 +1323,7 @@ describe('RichTextEditorMentionListbox', () => {
expect(
pageObject.getEditorMentionViewAttributeValues('mention-label')
).toEqual(['username2']);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
});

it('should commit second option on arrow key down and tab', async () => {
Expand All @@ -1342,7 +1342,7 @@ describe('RichTextEditorMentionListbox', () => {
expect(
pageObject.getEditorMentionViewAttributeValues('mention-label')
).toEqual(['username2']);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
});

it('focus out from the editor should close the mention popup', async () => {
Expand All @@ -1352,11 +1352,11 @@ describe('RichTextEditorMentionListbox', () => {
]);
await pageObject.setEditorTextContent('@');

expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();

await pageObject.focusOutEditor();

expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
});

// WebKit skipped, see https://github.com/ni/nimble/issues/1938
Expand All @@ -1367,11 +1367,11 @@ describe('RichTextEditorMentionListbox', () => {
]);
await pageObject.setEditorTextContent('@');

expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();

await pageObject.setDisabled(true);

expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
});
});

Expand All @@ -1384,14 +1384,14 @@ describe('RichTextEditorMentionListbox', () => {
{ key: 'user:2', displayName: 'username2' }
]);
await pageObject.setEditorTextContent('@');
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
expect(pageObject.getMentionListboxItemsName()).toEqual([
'username1',
'username2'
]);
element.removeChild(userMentionElement);
await waitForUpdatesAsync();
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
expect(pageObject.getMentionListboxItemsName()).toEqual([]);
}
);
Expand All @@ -1413,7 +1413,7 @@ describe('RichTextEditorMentionListbox', () => {
expect(pageObject.getMentionListboxItemsName()).toEqual([
'username2'
]);
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
}
);

Expand All @@ -1438,7 +1438,7 @@ describe('RichTextEditorMentionListbox', () => {
'username3',
'username4'
]);
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
}
);

Expand All @@ -1457,7 +1457,7 @@ describe('RichTextEditorMentionListbox', () => {
userMentionElement.pattern = 'invalid';
await waitForUpdatesAsync();
expect(pageObject.getMentionListboxItemsName()).toEqual([]);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
}
);

Expand All @@ -1479,7 +1479,7 @@ describe('RichTextEditorMentionListbox', () => {
'updated-name',
'username2'
]);
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
}
);

Expand All @@ -1490,7 +1490,7 @@ describe('RichTextEditorMentionListbox', () => {
{ key: 'invalid', displayName: 'username1' }
]);
await pageObject.setEditorTextContent('@');
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
expect(pageObject.getMentionListboxItemsName()).toEqual([]);
mappingElements[0]!.key = 'user:1';
// After the first wait, `activeMappingConfigs` is updated,
Expand All @@ -1501,7 +1501,7 @@ describe('RichTextEditorMentionListbox', () => {
expect(pageObject.getMentionListboxItemsName()).toEqual([
'username1'
]);
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
}
);

Expand All @@ -1520,7 +1520,7 @@ describe('RichTextEditorMentionListbox', () => {
mappingElements[0]!.key = 'invalid';
await waitForUpdatesAsync();
expect(pageObject.getMentionListboxItemsName()).toEqual([]);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
}
);

Expand All @@ -1545,11 +1545,11 @@ describe('RichTextEditorMentionListbox', () => {
'New user',
'username2'
]);
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
}
);

for (let i = 0; i < 10000; i++) {
for (let i = 0; i < 2000; i++) {
// Intermittent, see https://github.com/ni/nimble/issues/2219
// eslint-disable-next-line no-restricted-globals
fit(
Expand All @@ -1566,7 +1566,9 @@ describe('RichTextEditorMentionListbox', () => {
'username1',
'username2'
]);
expect(pageObject.isMentionListboxOpened()).toBeTrue();
// eslint-disable-next-line no-console
console.log('1', await pageObject.isMentionListboxOpened());
expect(await pageObject.isMentionListboxOpened()).toBeTrue();

// await pageObject.clickMentionListboxOption(0);
await pageObject.sliceEditorContent(0, 2);
Expand All @@ -1582,7 +1584,9 @@ describe('RichTextEditorMentionListbox', () => {
'testname1',
'testname2'
]);
expect(pageObject.isMentionListboxOpened()).toBeTrue();
// eslint-disable-next-line no-console
console.log('2', await pageObject.isMentionListboxOpened());
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
}
);
}
Expand All @@ -1594,12 +1598,12 @@ describe('RichTextEditorMentionListbox', () => {
{ key: 'user:1', displayName: 'user name1' }
]);
await pageObject.setEditorTextContent('@user');
expect(pageObject.isMentionListboxOpened()).toBeTrue();
expect(await pageObject.isMentionListboxOpened()).toBeTrue();
await pageObject.setCursorPosition(1);
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
mappingElements[0]!.displayName = 'user name2';
await waitForUpdatesAsync();
expect(pageObject.isMentionListboxOpened()).toBeFalse();
expect(await pageObject.isMentionListboxOpened()).toBeFalse();
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ Plain text 3`);
}
);

for (let i = 0; i < 10000; i++) {
for (let i = 0; i < 2000; i++) {
// Intermittent, see https://github.com/ni/nimble/issues/2219
// eslint-disable-next-line no-restricted-globals
fit('Mention node' + `${i}`, async () => {
Expand Down

0 comments on commit 5e97c1d

Please sign in to comment.