2024-10-09 00:25:41 +02:00
|
|
|
import assert from "node:assert/strict";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2021-02-20 05:52:06 +01:00
|
|
|
import type {Page} from "puppeteer";
|
2024-05-04 03:39:10 +02:00
|
|
|
import {z} from "zod";
|
2020-03-18 19:52:03 +01:00
|
|
|
|
2023-02-22 23:04:11 +01:00
|
|
|
import * as common from "./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 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);
|
2023-03-01 10:47:38 +01:00
|
|
|
await page.type("#id_team_name", organization_name);
|
2024-10-19 12:48:31 +02:00
|
|
|
await page.select("#realm_type", "business");
|
2023-12-22 01:00:27 +01:00
|
|
|
await page.$eval("input#realm_in_root_domain", (el) => {
|
|
|
|
el.click();
|
|
|
|
});
|
2023-03-01 10:47:38 +01:00
|
|
|
|
2020-05-27 02:28:17 +02:00
|
|
|
await Promise.all([
|
|
|
|
page.waitForNavigation(),
|
2023-12-22 01:00:27 +01:00
|
|
|
page.$eval("form#create_realm", (form) => {
|
|
|
|
form.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.
|
2023-01-20 08:22:48 +01:00
|
|
|
assert.ok(page.url().includes("/accounts/new/send_confirm/?email=alice%40test.example.com"));
|
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);
|
2024-05-04 03:39:10 +02:00
|
|
|
assert(page_content !== null);
|
|
|
|
const {confirmation_key} = z
|
|
|
|
.object({confirmation_key: z.string()})
|
|
|
|
.parse(JSON.parse(page_content));
|
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,
|
|
|
|
);
|
2023-03-09 12:30:03 +01:00
|
|
|
assert.equal(text_in_pitch, "Enter your account details to complete registration.");
|
2020-05-15 17:38:25 +02:00
|
|
|
|
|
|
|
// fill the form.
|
2020-05-29 20:46:35 +02:00
|
|
|
const params = {
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice",
|
|
|
|
password: "passwordwhichisnotreallycomplex",
|
2020-05-29 20:46:35 +02:00
|
|
|
terms: true,
|
2024-03-26 06:14:16 +01:00
|
|
|
how_realm_creator_found_zulip: "other",
|
|
|
|
how_realm_creator_found_zulip_other_text: "test",
|
2020-05-29 20:46:35 +02:00
|
|
|
};
|
|
|
|
// 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.
|
2020-07-15 01:29:15 +02:00
|
|
|
await common.fill_form(page, "#registration", params);
|
2023-12-22 01:00:27 +01:00
|
|
|
await page.$eval("form#registration", (form) => {
|
|
|
|
form.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.
|
2021-03-27 03:52:16 +01:00
|
|
|
common.set_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);
|