2020-08-01 03:43:15 +02:00
|
|
|
|
"use strict";
|
|
|
|
|
|
2020-08-03 23:57:48 +02:00
|
|
|
|
const {strict: assert} = require("assert");
|
2020-03-18 19:52:03 +01:00
|
|
|
|
|
2020-07-24 06:02:07 +02:00
|
|
|
|
const common = require("../puppeteer_lib/common");
|
|
|
|
|
|
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";
|
|
|
|
|
|
2020-05-16 19:14:31 +02:00
|
|
|
|
async function realm_creation_tests(page) {
|
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(),
|
2020-07-15 01:29:15 +02:00
|
|
|
|
page.$eval("#send_confirm", (form) => form.submit()),
|
2020-05-27 02:28:17 +02:00
|
|
|
|
]);
|
2020-05-15 17:38:25 +02:00
|
|
|
|
|
|
|
|
|
// Make sure onfirmation email is sent.
|
2020-07-15 01:29:15 +02:00
|
|
|
|
assert(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
|
2020-10-07 10:15:47 +02:00
|
|
|
|
const page_content = await page.evaluate(() => document.querySelector("body").textContent);
|
2020-05-15 17:38:25 +02:00
|
|
|
|
const confirmation_key = await JSON.parse(page_content).confirmation_key;
|
2020-07-15 01:29:15 +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");
|
2020-10-07 10:15:47 +02:00
|
|
|
|
const text_in_pitch = await page.evaluate(() => document.querySelector(".pitch p").textContent);
|
2020-07-22 08:49:51 +02:00
|
|
|
|
assert(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.
|
2020-07-15 01:29:15 +02:00
|
|
|
|
await page.$eval("#realm_in_root_domain", (el) => el.click());
|
|
|
|
|
await common.fill_form(page, "#registration", params);
|
|
|
|
|
await page.$eval("#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
|
2020-03-18 19:52:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 17:45:03 +02:00
|
|
|
|
common.run_test(realm_creation_tests);
|