2021-05-01 03:31:04 +02:00
|
|
|
import {strict as assert} from "assert";
|
|
|
|
|
|
|
|
import type {Page} from "puppeteer";
|
|
|
|
|
2023-02-22 23:04:11 +01:00
|
|
|
import * as common from "./lib/common";
|
2021-05-01 03:31:04 +02:00
|
|
|
|
|
|
|
type Playground = {
|
2021-05-10 18:29:56 +02:00
|
|
|
playground_name: string;
|
2021-05-01 03:31:04 +02:00
|
|
|
pygments_language: string;
|
|
|
|
url_prefix: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
async function _add_playground_and_return_status(page: Page, payload: Playground): Promise<string> {
|
|
|
|
await page.waitForSelector(".admin-playground-form", {visible: true});
|
|
|
|
// Let's first ensure that the success/failure status from an earlier step has disappeared.
|
|
|
|
const admin_playground_status_selector = "div#admin-playground-status";
|
2021-05-13 02:51:24 +02:00
|
|
|
await page.waitForSelector(admin_playground_status_selector, {hidden: true});
|
2021-05-01 03:31:04 +02:00
|
|
|
|
|
|
|
// Now we can fill and click the submit button.
|
|
|
|
await common.fill_form(page, "form.admin-playground-form", payload);
|
|
|
|
// Not sure why, but page.click() doesn't seem to always click the submit button.
|
|
|
|
// So we resort to using eval with the button ID instead.
|
|
|
|
await page.$eval("#submit_playground_button", (el) => (el as HTMLInputElement).click());
|
|
|
|
|
|
|
|
// We return the success/failure status message back to the caller.
|
|
|
|
await page.waitForSelector(admin_playground_status_selector, {visible: true});
|
|
|
|
const admin_playground_status = await common.get_text_from_selector(
|
|
|
|
page,
|
|
|
|
admin_playground_status_selector,
|
|
|
|
);
|
|
|
|
return admin_playground_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function test_successful_playground_creation(page: Page): Promise<void> {
|
|
|
|
const payload = {
|
|
|
|
pygments_language: "Python",
|
2021-05-10 18:29:56 +02:00
|
|
|
playground_name: "Python3 playground",
|
2021-05-01 03:31:04 +02:00
|
|
|
url_prefix: "https://python.example.com",
|
|
|
|
};
|
|
|
|
const status = await _add_playground_and_return_status(page, payload);
|
|
|
|
assert.strictEqual(status, "Custom playground added!");
|
|
|
|
await page.waitForSelector(".playground_row", {visible: true});
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(
|
|
|
|
page,
|
|
|
|
".playground_row span.playground_pygments_language",
|
|
|
|
),
|
|
|
|
"Python",
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, ".playground_row span.playground_name"),
|
|
|
|
"Python3 playground",
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
await common.get_text_from_selector(page, ".playground_row span.playground_url_prefix"),
|
|
|
|
"https://python.example.com",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function test_invalid_playground_parameters(page: Page): Promise<void> {
|
|
|
|
const payload = {
|
|
|
|
pygments_language: "Python",
|
2021-05-10 18:29:56 +02:00
|
|
|
playground_name: "Python3 playground",
|
2021-05-01 03:31:04 +02:00
|
|
|
url_prefix: "not_a_url",
|
|
|
|
};
|
|
|
|
let status = await _add_playground_and_return_status(page, payload);
|
|
|
|
assert.strictEqual(status, "Failed: url_prefix is not a URL");
|
|
|
|
|
|
|
|
payload.url_prefix = "https://python.example.com";
|
|
|
|
payload.pygments_language = "py!@%&";
|
|
|
|
status = await _add_playground_and_return_status(page, payload);
|
|
|
|
assert.strictEqual(status, "Failed: Invalid characters in pygments language");
|
|
|
|
}
|
|
|
|
|
2021-05-12 16:45:26 +02:00
|
|
|
async function test_successful_playground_deletion(page: Page): Promise<void> {
|
|
|
|
await page.click(".playground_row button.delete");
|
2022-09-07 20:28:08 +02:00
|
|
|
|
|
|
|
await common.wait_for_micromodal_to_open(page);
|
|
|
|
await page.click("#confirm_delete_code_playgrounds_modal .dialog_submit_button");
|
|
|
|
await common.wait_for_micromodal_to_close(page);
|
|
|
|
|
2021-05-12 16:45:26 +02:00
|
|
|
await page.waitForSelector(".playground_row", {hidden: true});
|
|
|
|
}
|
|
|
|
|
2021-05-01 03:31:04 +02:00
|
|
|
async function playground_test(page: Page): Promise<void> {
|
|
|
|
await common.log_in(page);
|
|
|
|
await common.manage_organization(page);
|
|
|
|
await page.click("li[data-section='playground-settings']");
|
|
|
|
|
|
|
|
await test_successful_playground_creation(page);
|
|
|
|
await test_invalid_playground_parameters(page);
|
2021-05-12 16:45:26 +02:00
|
|
|
await test_successful_playground_deletion(page);
|
2021-05-01 03:31:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
common.run_test(playground_test);
|