2021-02-20 05:52:06 +01:00
|
|
|
|
import {strict as assert} from "assert";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
|
import type {Page} from "puppeteer";
|
2020-03-18 19:52:03 +01:00
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
|
import common from "../puppeteer_lib/common";
|
2020-07-24 06:02:07 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const email = "alice@test.example.com";
|
|
|
|
|
const subdomain = "testsubdomain";
|
|
|
|
|
const organization_name = "Awesome Organization";
|
2020-03-18 19:52:03 +01:00
|
|
|
|
const host = "zulipdev.com:9981";
|
|
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
|
async function realm_creation_tests(page: Page): Promise<void> {
|
2020-07-15 01:29:15 +02:00
|
|
|
|
await page.goto("http://" + host + "/new/");
|
2020-05-15 17:38:25 +02:00
|
|
|
|
|
|
|
|
|
// submit the email for realm creation.
|
2020-07-15 01:29:15 +02:00
|
|
|
|
await page.waitForSelector("#email");
|
|
|
|
|
await page.type("#email", email);
|
2020-05-27 02:28:17 +02:00
|
|
|
|
await Promise.all([
|
|
|
|
|
page.waitForNavigation(),
|
2021-02-20 05:52:06 +01:00
|
|
|
|
page.$eval("#send_confirm", (form) => (form as HTMLFormElement).submit()),
|
2020-05-27 02:28:17 +02:00
|
|
|
|
]);
|
2020-05-15 17:38:25 +02:00
|
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
|
// Make sure confirmation email is sent.
|
2021-06-10 08:32:54 +02:00
|
|
|
|
assert.ok(page.url().includes("/accounts/new/send_confirm/" + email));
|
2020-05-15 17:38:25 +02:00
|
|
|
|
|
|
|
|
|
// Special endpoint enabled only during tests for extracting confirmation key
|
2020-07-15 01:29:15 +02:00
|
|
|
|
await page.goto("http://" + host + "/confirmation_key/");
|
2020-05-15 17:38:25 +02:00
|
|
|
|
|
|
|
|
|
// Open the confirmation URL
|
2021-02-20 05:52:06 +01:00
|
|
|
|
const page_content = await page.evaluate(() => document.querySelector("body")!.textContent);
|
2021-09-23 00:25:31 +02:00
|
|
|
|
const confirmation_key: string = JSON.parse(page_content!).confirmation_key;
|
2021-09-22 23:34:58 +02:00
|
|
|
|
const confirmation_url = `http://${host}/accounts/do_confirm/${confirmation_key}`;
|
2020-05-15 17:38:25 +02:00
|
|
|
|
await page.goto(confirmation_url);
|
|
|
|
|
|
2020-05-28 01:47:18 +02:00
|
|
|
|
// We wait until the DOMContentLoaded event because we want the code
|
|
|
|
|
// that focuses the first input field to run before we run our tests to avoid
|
|
|
|
|
// flakes. Without waiting for DOMContentLoaded event, in rare cases, the
|
|
|
|
|
// first input is focused when we are typing something for other fields causing
|
|
|
|
|
// validation errors. The code for focusing the input is wrapped in jQuery
|
|
|
|
|
// $() calls which runs when DOMContentLoaded is fired.
|
2020-07-16 22:40:18 +02:00
|
|
|
|
await page.waitForNavigation({waitUntil: "domcontentloaded"});
|
2020-05-28 01:47:18 +02:00
|
|
|
|
|
2020-05-15 17:38:25 +02:00
|
|
|
|
// Make sure the realm creation page is loaded correctly by
|
|
|
|
|
// checking the text in <p> tag under pitch class is as expected.
|
2020-07-15 01:29:15 +02:00
|
|
|
|
await page.waitForSelector(".pitch");
|
2021-02-20 05:52:06 +01:00
|
|
|
|
const text_in_pitch = await page.evaluate(
|
|
|
|
|
() => document.querySelector(".pitch p")!.textContent,
|
|
|
|
|
);
|
2021-06-08 05:08:21 +02:00
|
|
|
|
assert.equal(text_in_pitch, "You’re almost there! We just need you to do one last thing.");
|
2020-05-15 17:38:25 +02:00
|
|
|
|
|
|
|
|
|
// fill the form.
|
2020-05-29 20:46:35 +02:00
|
|
|
|
const params = {
|
|
|
|
|
realm_name: organization_name,
|
|
|
|
|
realm_subdomain: subdomain,
|
2020-07-15 01:29:15 +02:00
|
|
|
|
full_name: "Alice",
|
|
|
|
|
password: "passwordwhichisnotreallycomplex",
|
2020-05-29 20:46:35 +02:00
|
|
|
|
terms: true,
|
|
|
|
|
};
|
|
|
|
|
// For some reason, page.click() does not work this for particular checkbox
|
2020-05-27 02:23:34 +02:00
|
|
|
|
// so use page.$eval here to call the .click method in the browser.
|
2021-02-20 05:52:06 +01:00
|
|
|
|
await page.$eval("#realm_in_root_domain", (el) => (el as HTMLInputElement).click());
|
2020-07-15 01:29:15 +02:00
|
|
|
|
await common.fill_form(page, "#registration", params);
|
2021-02-20 05:52:06 +01:00
|
|
|
|
await page.$eval("#registration", (form) => (form as HTMLFormElement).submit());
|
2020-05-15 17:38:25 +02:00
|
|
|
|
|
|
|
|
|
// Check if realm is created and user is logged in by checking if
|
|
|
|
|
// element of id `lightbox_overlay` exists.
|
2020-07-16 23:29:01 +02:00
|
|
|
|
await page.waitForSelector("#lightbox_overlay"); // if element doesn't exist,timeout error raises
|
2021-03-29 13:43:08 +02:00
|
|
|
|
|
|
|
|
|
// Updating common.realm_url because we are redirecting to it when logging out.
|
|
|
|
|
common.realm_url = page.url();
|
2020-03-18 19:52:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 17:45:03 +02:00
|
|
|
|
common.run_test(realm_creation_tests);
|