2020-09-30 21:42:33 +01:00
|
|
|
import crypto from "crypto";
|
|
|
|
import { Frame } from "puppeteer";
|
|
|
|
|
2021-02-18 13:40:58 +00:00
|
|
|
const LOADING_STATE_DELAY = 3000;
|
|
|
|
const CREATE_DELAY = 10000;
|
|
|
|
|
2020-09-30 21:42:33 +01:00
|
|
|
export async function login(connectionString: string): Promise<Frame> {
|
2020-11-03 19:05:54 +00:00
|
|
|
const prodUrl = process.env.DATA_EXPLORER_ENDPOINT;
|
2020-11-13 16:58:38 +00:00
|
|
|
await page.goto(prodUrl);
|
2020-09-30 21:42:33 +01:00
|
|
|
|
2020-11-13 16:58:38 +00:00
|
|
|
if (process.env.PLATFORM === "Emulator") {
|
|
|
|
return page.mainFrame();
|
|
|
|
}
|
2020-09-30 21:42:33 +01:00
|
|
|
// log in with connection string
|
2021-01-19 22:31:55 +00:00
|
|
|
await page.waitFor("div > p.switchConnectTypeText", { visible: true });
|
|
|
|
await page.click("div > p.switchConnectTypeText");
|
|
|
|
const connStr = connectionString;
|
|
|
|
await page.type("input[class='inputToken']", connStr);
|
|
|
|
await page.click("input[value='Connect']");
|
2020-09-30 21:42:33 +01:00
|
|
|
const handle = await page.waitForSelector("iframe");
|
|
|
|
const frame = await handle.contentFrame();
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2020-11-02 19:33:14 +00:00
|
|
|
export function generateUniqueName(baseName = "", length = 4): string {
|
2020-09-30 21:42:33 +01:00
|
|
|
return `${baseName}${crypto.randomBytes(length).toString("hex")}`;
|
|
|
|
}
|
2021-02-18 13:40:58 +00:00
|
|
|
|
2021-03-05 00:12:31 +00:00
|
|
|
export function generateDatabaseName(baseName = "db", length = 1): string {
|
|
|
|
return `${baseName}${crypto.randomBytes(length).toString("hex")}-${Date.now()}`;
|
|
|
|
}
|
|
|
|
|
2021-03-08 18:29:41 +00:00
|
|
|
export async function createDatabase(frame: Frame): Promise<string> {
|
2021-03-05 00:12:31 +00:00
|
|
|
const dbId = generateDatabaseName();
|
2021-02-18 13:40:58 +00:00
|
|
|
const collectionId = generateUniqueName("col");
|
2021-03-05 00:12:31 +00:00
|
|
|
const shardKey = "partitionKey";
|
2021-02-18 13:40:58 +00:00
|
|
|
// create new collection
|
|
|
|
await frame.waitFor('button[data-test="New Collection"]', { visible: true });
|
|
|
|
await frame.click('button[data-test="New Collection"]');
|
|
|
|
|
|
|
|
// check new database
|
|
|
|
await frame.waitFor('input[data-test="addCollection-createNewDatabase"]');
|
|
|
|
await frame.click('input[data-test="addCollection-createNewDatabase"]');
|
|
|
|
|
|
|
|
// check shared throughput
|
|
|
|
await frame.waitFor('input[data-test="addCollectionPane-databaseSharedThroughput"]');
|
|
|
|
await frame.click('input[data-test="addCollectionPane-databaseSharedThroughput"]');
|
|
|
|
|
|
|
|
// type database id
|
|
|
|
await frame.waitFor('input[data-test="addCollection-newDatabaseId"]');
|
|
|
|
const dbInput = await frame.$('input[data-test="addCollection-newDatabaseId"]');
|
|
|
|
await dbInput.press("Backspace");
|
|
|
|
await dbInput.type(dbId);
|
|
|
|
|
|
|
|
// type collection id
|
|
|
|
await frame.waitFor('input[data-test="addCollection-collectionId"]');
|
|
|
|
const input = await frame.$('input[data-test="addCollection-collectionId"]');
|
|
|
|
await input.press("Backspace");
|
|
|
|
await input.type(collectionId);
|
|
|
|
|
|
|
|
// type partition key value
|
|
|
|
await frame.waitFor('input[data-test="addCollection-partitionKeyValue"]');
|
|
|
|
const keyInput = await frame.$('input[data-test="addCollection-partitionKeyValue"]');
|
|
|
|
await keyInput.press("Backspace");
|
|
|
|
await keyInput.type(shardKey);
|
|
|
|
|
|
|
|
// click submit
|
|
|
|
await frame.waitFor("#submitBtnAddCollection");
|
|
|
|
await frame.click("#submitBtnAddCollection");
|
2021-03-05 04:49:52 +00:00
|
|
|
return dbId;
|
2021-02-18 13:40:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 18:29:41 +00:00
|
|
|
export async function onClickSaveButton(frame: Frame): Promise<void> {
|
2021-02-18 13:40:58 +00:00
|
|
|
await frame.waitFor(`button[data-test="Save"]`), { visible: true };
|
|
|
|
await frame.waitFor(LOADING_STATE_DELAY);
|
|
|
|
await frame.click(`button[data-test="Save"]`);
|
|
|
|
await frame.waitFor(CREATE_DELAY);
|
|
|
|
}
|