2020-09-09 18:18:27 +01:00
|
|
|
import "expect-puppeteer";
|
2020-11-02 19:33:14 +00:00
|
|
|
import { Frame } from "puppeteer";
|
2020-09-30 21:42:33 +01:00
|
|
|
import { generateUniqueName, login } from "../utils/shared";
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
jest.setTimeout(300000);
|
2020-09-30 21:42:33 +01:00
|
|
|
const LOADING_STATE_DELAY = 2500;
|
2020-11-02 19:33:14 +00:00
|
|
|
const RETRY_DELAY = 5000;
|
|
|
|
const CREATE_DELAY = 10000;
|
2020-09-30 21:42:33 +01:00
|
|
|
const RENDER_DELAY = 1000;
|
2020-09-09 18:18:27 +01:00
|
|
|
|
2020-09-23 21:18:05 +01:00
|
|
|
describe("Collection Add and Delete SQL spec", () => {
|
|
|
|
it("creates a collection", async () => {
|
2020-09-09 18:18:27 +01:00
|
|
|
try {
|
2020-11-02 19:33:14 +00:00
|
|
|
const dbId = generateUniqueName("db");
|
|
|
|
const collectionId = generateUniqueName("col");
|
|
|
|
const sharedKey = `/skey${generateUniqueName()}`;
|
2020-09-30 21:42:33 +01:00
|
|
|
const frame = await login(process.env.PORTAL_RUNNER_CONNECTION_STRING);
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
// create new collection
|
|
|
|
await frame.waitFor('button[data-test="New Container"]', { visible: true });
|
|
|
|
await frame.waitForSelector('div[class="splashScreen"] > div[class="title"]', { visible: true });
|
|
|
|
await frame.click('button[data-test="New Container"]');
|
2020-09-23 21:18:05 +01:00
|
|
|
|
2020-09-09 18:18:27 +01:00
|
|
|
// 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"]');
|
2020-09-23 21:18:05 +01:00
|
|
|
await frame.click('input[data-test="addCollectionPane-databaseSharedThroughput"]');
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
// type database id
|
|
|
|
await frame.waitFor('input[data-test="addCollection-newDatabaseId"]');
|
2020-10-07 20:41:38 +01:00
|
|
|
const dbInput = await frame.$('input[data-test="addCollection-newDatabaseId"]');
|
|
|
|
await dbInput.press("Backspace");
|
|
|
|
await dbInput.type(dbId);
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
// type collection id
|
|
|
|
await frame.waitFor('input[data-test="addCollection-collectionId"]');
|
2020-10-07 20:41:38 +01:00
|
|
|
const input = await frame.$('input[data-test="addCollection-collectionId"]');
|
|
|
|
await input.press("Backspace");
|
|
|
|
await input.type(collectionId);
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
// type partition key value
|
|
|
|
await frame.waitFor('input[data-test="addCollection-partitionKeyValue"]');
|
2020-10-07 20:41:38 +01:00
|
|
|
const keyInput = await frame.$('input[data-test="addCollection-partitionKeyValue"]');
|
|
|
|
await keyInput.press("Backspace");
|
|
|
|
await keyInput.type(sharedKey);
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
// click submit
|
2020-09-23 21:18:05 +01:00
|
|
|
await frame.waitFor("#submitBtnAddCollection");
|
|
|
|
await frame.click("#submitBtnAddCollection");
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
// validate created
|
|
|
|
// open database menu
|
|
|
|
await frame.waitForSelector('div[class="splashScreen"] > div[class="title"]', { visible: true });
|
2020-12-18 22:08:40 +00:00
|
|
|
await frame.waitFor(CREATE_DELAY);
|
2020-11-02 19:33:14 +00:00
|
|
|
await frame.waitForSelector('div[class="splashScreen"] > div[class="title"]', { visible: true });
|
|
|
|
const databases = await frame.$$(`div[class="databaseHeader main1 nodeItem "] > div[class="treeNodeHeader "]`);
|
2021-01-20 15:15:01 +00:00
|
|
|
const selectedDbId = await frame.evaluate((element) => {
|
2020-11-02 19:33:14 +00:00
|
|
|
return element.attributes["data-test"].textContent;
|
|
|
|
}, databases[0]);
|
|
|
|
|
|
|
|
await frame.waitFor(`div[data-test="${selectedDbId}"]`), { visible: true };
|
|
|
|
await frame.waitFor(CREATE_DELAY);
|
|
|
|
await frame.waitFor("div[class='rowData'] > span[class='message']");
|
|
|
|
|
2021-01-20 15:15:01 +00:00
|
|
|
const didCreateContainer = await frame.$$eval("div[class='rowData'] > span[class='message']", (elements) => {
|
|
|
|
return elements.some((el) => el.textContent.includes("Successfully created"));
|
2020-11-02 19:33:14 +00:00
|
|
|
});
|
2020-09-09 18:18:27 +01:00
|
|
|
|
2020-11-02 19:33:14 +00:00
|
|
|
expect(didCreateContainer).toBe(true);
|
|
|
|
|
|
|
|
await frame.waitFor(`div[data-test="${selectedDbId}"]`), { visible: true };
|
2020-10-07 20:41:38 +01:00
|
|
|
await frame.waitFor(LOADING_STATE_DELAY);
|
2020-09-23 21:18:05 +01:00
|
|
|
|
2020-11-02 19:33:14 +00:00
|
|
|
await clickDBMenu(selectedDbId, frame);
|
2020-09-09 18:18:27 +01:00
|
|
|
|
2020-11-02 19:33:14 +00:00
|
|
|
const collections = await frame.$$(
|
|
|
|
`div[class="collectionHeader main2 nodeItem "] > div[class="treeNodeHeader "]`
|
|
|
|
);
|
2020-09-23 21:18:05 +01:00
|
|
|
|
2020-11-02 19:33:14 +00:00
|
|
|
if (collections.length) {
|
|
|
|
await frame.waitFor(`div[class="collectionHeader main2 nodeItem "] > div[class="treeNodeHeader "]`, {
|
2021-01-20 15:15:01 +00:00
|
|
|
visible: true,
|
2020-11-02 19:33:14 +00:00
|
|
|
});
|
2020-09-09 18:18:27 +01:00
|
|
|
|
2021-01-20 15:15:01 +00:00
|
|
|
const textId = await frame.evaluate((element) => {
|
2020-11-02 19:33:14 +00:00
|
|
|
return element.attributes["data-test"].textContent;
|
|
|
|
}, collections[0]);
|
|
|
|
await frame.waitFor(`div[data-test="${textId}"]`, { visible: true });
|
|
|
|
// delete container
|
2020-09-09 18:18:27 +01:00
|
|
|
|
2020-11-02 19:33:14 +00:00
|
|
|
// click context menu for container
|
|
|
|
await frame.waitFor(`div[data-test="${textId}"] > div > button`, { visible: true });
|
|
|
|
await frame.click(`div[data-test="${textId}"] > div > button`);
|
|
|
|
|
|
|
|
// click delete container
|
|
|
|
await frame.waitFor(RENDER_DELAY);
|
|
|
|
await frame.waitFor('span[class="treeComponentMenuItemLabel deleteCollectionMenuItemLabel"]');
|
|
|
|
await frame.click('span[class="treeComponentMenuItemLabel deleteCollectionMenuItemLabel"]');
|
|
|
|
|
|
|
|
// confirm delete container
|
2021-02-10 21:44:00 +00:00
|
|
|
await frame.waitFor('input[id="confirmCollectionId"]', { visible: true });
|
|
|
|
await frame.type('input[id="confirmCollectionId"]', textId);
|
2020-11-02 19:33:14 +00:00
|
|
|
|
|
|
|
// click delete
|
2021-02-10 21:44:00 +00:00
|
|
|
await frame.waitFor('button[id="sidePanelOkButton"]', { visible: true });
|
|
|
|
await frame.click('button[id="sidePanelOkButton"]');
|
2020-11-02 19:33:14 +00:00
|
|
|
await frame.waitFor(LOADING_STATE_DELAY);
|
|
|
|
await frame.waitForSelector('div[class="splashScreen"] > div[class="title"]', { visible: true });
|
2020-09-09 18:18:27 +01:00
|
|
|
|
2020-11-02 19:33:14 +00:00
|
|
|
await expect(page).not.toMatchElement(`div[data-test="${textId}"]`);
|
|
|
|
}
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
// click context menu for database
|
2020-11-02 19:33:14 +00:00
|
|
|
await frame.waitFor(`div[data-test="${selectedDbId}"] > div > button`);
|
|
|
|
await frame.waitFor(RENDER_DELAY);
|
|
|
|
const button = await frame.$(`div[data-test="${selectedDbId}"] > div > button`);
|
2020-09-09 18:18:27 +01:00
|
|
|
await button.focus();
|
|
|
|
await button.asElement().click();
|
|
|
|
|
|
|
|
// click delete database
|
2020-10-07 20:41:38 +01:00
|
|
|
await frame.waitFor(RENDER_DELAY);
|
2020-09-19 00:00:21 +01:00
|
|
|
await frame.waitFor('span[class="treeComponentMenuItemLabel deleteDatabaseMenuItemLabel"]');
|
|
|
|
await frame.click('span[class="treeComponentMenuItemLabel deleteDatabaseMenuItemLabel"]');
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
// confirm delete database
|
2020-09-30 21:42:33 +01:00
|
|
|
await frame.waitForSelector('input[data-test="confirmDatabaseId"]', { visible: true });
|
|
|
|
await frame.waitFor(RENDER_DELAY);
|
2020-11-02 19:33:14 +00:00
|
|
|
await frame.type('input[data-test="confirmDatabaseId"]', selectedDbId);
|
2020-09-09 18:18:27 +01:00
|
|
|
|
|
|
|
// click delete
|
|
|
|
await frame.click('input[data-test="deleteDatabase"]');
|
|
|
|
await frame.waitForSelector('div[class="splashScreen"] > div[class="title"]', { visible: true });
|
2020-11-02 19:33:14 +00:00
|
|
|
await frame.waitFor(LOADING_STATE_DELAY);
|
|
|
|
await frame.waitForSelector('div[class="splashScreen"] > div[class="title"]', { visible: true });
|
|
|
|
await expect(page).not.toMatchElement(`div[data-test="${selectedDbId}"]`);
|
2020-09-09 18:18:27 +01:00
|
|
|
} catch (error) {
|
2020-09-22 21:21:57 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2020-09-23 21:18:05 +01:00
|
|
|
const testName = (expect as any).getState().currentTestName;
|
2020-11-02 19:33:14 +00:00
|
|
|
await page.screenshot({ path: `failed-${testName}.jpg` });
|
2020-09-09 18:18:27 +01:00
|
|
|
throw error;
|
2020-09-23 21:18:05 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2020-11-02 19:33:14 +00:00
|
|
|
|
|
|
|
async function clickDBMenu(dbId: string, frame: Frame, retries = 0) {
|
|
|
|
const button = await frame.$(`div[data-test="${dbId}"]`);
|
|
|
|
await button.focus();
|
|
|
|
const handler = await button.asElement();
|
|
|
|
await handler.click();
|
|
|
|
await ensureMenuIsOpen(dbId, frame, retries);
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function ensureMenuIsOpen(dbId: string, frame: Frame, retries: number) {
|
|
|
|
await frame.waitFor(RETRY_DELAY);
|
|
|
|
const button = await frame.$(`div[data-test="${dbId}"]`);
|
2021-01-20 15:15:01 +00:00
|
|
|
const classList = await frame.evaluate((button) => {
|
2020-11-02 19:33:14 +00:00
|
|
|
return button.parentElement.classList;
|
|
|
|
}, button);
|
|
|
|
if (!Object.values(classList).includes("selected") && retries < 5) {
|
|
|
|
retries = retries + 1;
|
|
|
|
await clickDBMenu(dbId, frame, retries);
|
|
|
|
}
|
|
|
|
}
|