puppeteer_tests: Fix type errors.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-07-05 20:28:39 -07:00 committed by Tim Abbott
parent 6648fc4bf1
commit 4ebcc9ba95
3 changed files with 18 additions and 13 deletions

View File

@ -103,7 +103,7 @@ class CommonUtils {
// This function hacks around that issue; once it's fixed in
// puppeteer upstream, we can delete this function and return
// its callers to using `page.url()`
return await page.evaluate("location.href");
return await page.evaluate(() => window.location.href);
}
// This function will clear the existing value of the element and
@ -280,13 +280,13 @@ class CommonUtils {
}
async assert_compose_box_content(page: Page, expected_value: string): Promise<void> {
await page.waitForSelector("#compose-textarea");
const compose_box_element = await page.$("#compose-textarea");
const compose_box_content = await page.evaluate(
(element: HTMLTextAreaElement) => element.value,
compose_box_element,
);
const compose_box_element = await page.waitForSelector("#compose-textarea");
const compose_box_content = await page.evaluate((element) => {
if (!(element instanceof HTMLTextAreaElement)) {
throw new TypeError("expected HTMLTextAreaElement");
}
return element.value;
}, compose_box_element);
assert.equal(
compose_box_content,
expected_value,
@ -501,12 +501,12 @@ class CommonUtils {
`//*[@class="typeahead dropdown-menu" and contains(@style, "display: block")]//li[contains(normalize-space(), "${item}")]//a`,
{visible: true},
);
const entry_x = (await entry?.boundingBox())?.x;
const entry_y = (await entry?.boundingBox())?.y;
if (entry_x && entry_y) {
await page.mouse.move(entry_x, entry_y);
}
assert.ok(entry);
await entry.hover();
await page.evaluate((entry) => {
if (!(entry instanceof HTMLElement)) {
throw new TypeError("expected HTMLElement");
}
entry.click();
}, entry);
}

View File

@ -179,6 +179,7 @@ async function test_markdown_preview_without_any_content(page: Page): Promise<vo
await page.click("#compose .markdown_preview");
await page.waitForSelector("#compose .undo_markdown_preview", {visible: true});
const markdown_preview_element = await page.$("#compose .preview_content");
assert.ok(markdown_preview_element);
assert.equal(
await page.evaluate((element: Element) => element.textContent, markdown_preview_element),
"Nothing to preview",
@ -189,6 +190,7 @@ async function test_markdown_preview_without_any_content(page: Page): Promise<vo
async function test_markdown_rendering(page: Page): Promise<void> {
await page.waitForSelector("#compose .markdown_preview", {visible: true});
let markdown_preview_element = await page.$("#compose .preview_content");
assert.ok(markdown_preview_element);
assert.equal(
await page.evaluate((element: Element) => element.textContent, markdown_preview_element),
"",
@ -202,6 +204,7 @@ async function test_markdown_rendering(page: Page): Promise<void> {
"<p><strong>Markdown preview</strong> &gt;&gt; Test for Markdown preview</p>";
await page.waitForFunction(() => $("#compose .preview_content").html() !== "");
markdown_preview_element = await page.$("#compose .preview_content");
assert.ok(markdown_preview_element);
assert.equal(
await page.evaluate((element: Element) => element.innerHTML, markdown_preview_element),
expected_markdown_html,

View File

@ -217,6 +217,8 @@ async function test_invalid_edit_bot_form(page: Page): Promise<void> {
await page.waitForFunction(
(cancel_button_selector: string) =>
!document.querySelector(cancel_button_selector)?.hasAttribute("disabled"),
{},
cancel_button_selector,
);
await page.click(cancel_button_selector);
await page.waitForXPath(