mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-18 16:31:31 +00:00
Test Explorer Improvements (#541)
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import "expect-puppeteer";
|
||||
import { getTestExplorerFrame } from "../testExplorer/TestExplorerUtils";
|
||||
import { createDatabase, onClickSaveButton } from "../utils/shared";
|
||||
import { generateUniqueName } from "../utils/shared";
|
||||
import { ApiKind } from "../../src/Contracts/DataModels";
|
||||
import { createDatabase, generateUniqueName, onClickSaveButton } from "../utils/shared";
|
||||
|
||||
const LOADING_STATE_DELAY = 5000;
|
||||
jest.setTimeout(300000);
|
||||
@@ -12,7 +9,9 @@ describe("MongoDB Index policy tests", () => {
|
||||
try {
|
||||
const singleFieldId = generateUniqueName("key");
|
||||
const wildCardId = generateUniqueName("key") + "$**";
|
||||
const frame = await getTestExplorerFrame(ApiKind.MongoDB);
|
||||
await page.goto("https://localhost:1234/testExplorer.html?accountName=portal-mongo-runner");
|
||||
const handle = await page.waitForSelector("iframe");
|
||||
const frame = await handle.contentFrame();
|
||||
const dropDown = "Index Type ";
|
||||
let index = 0;
|
||||
|
||||
@@ -20,24 +19,18 @@ describe("MongoDB Index policy tests", () => {
|
||||
await frame.waitForSelector('div[class="splashScreen"] > div[class="title"]', { visible: true });
|
||||
await frame.waitFor(LOADING_STATE_DELAY);
|
||||
await frame.waitForSelector('div[class="splashScreen"] > div[class="title"]', { visible: true });
|
||||
const dbId = await createDatabase(frame);
|
||||
const { databaseId, collectionId } = await createDatabase(frame);
|
||||
await frame.waitFor(25000);
|
||||
// click on database
|
||||
await frame.waitForSelector(`div[data-test="${dbId}"]`);
|
||||
await frame.waitForSelector(`div[data-test="${databaseId}"]`);
|
||||
await frame.waitFor(LOADING_STATE_DELAY);
|
||||
await frame.click(`div[data-test="${dbId}"]`);
|
||||
await frame.click(`div[data-test="${databaseId}"]`);
|
||||
await frame.waitFor(LOADING_STATE_DELAY);
|
||||
|
||||
// click on scale & setting
|
||||
const containers = await frame.$$(
|
||||
`div[class="nodeChildren"] > div[class="collectionHeader main2 nodeItem "]> div[class="treeNodeHeader "]`
|
||||
);
|
||||
const selectedContainer = (await frame.evaluate((element) => element.innerText, containers[0]))
|
||||
.replace(/[\u{0080}-\u{FFFF}]/gu, "")
|
||||
.trim();
|
||||
await frame.waitFor(`div[data-test="${selectedContainer}"]`), { visible: true };
|
||||
await frame.waitFor(`div[data-test="${collectionId}"]`), { visible: true };
|
||||
await frame.waitFor(LOADING_STATE_DELAY);
|
||||
await frame.click(`div[data-test="${selectedContainer}"]`);
|
||||
await frame.click(`div[data-test="${collectionId}"]`);
|
||||
|
||||
await frame.waitFor(`div[data-test="Scale & Settings"]`), { visible: true };
|
||||
await frame.waitFor(LOADING_STATE_DELAY);
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
import { uploadNotebookIfNotExist } from "./notebookTestUtils";
|
||||
import { ElementHandle, Frame } from "puppeteer";
|
||||
import { getTestExplorerFrame } from "../testExplorer/TestExplorerUtils";
|
||||
|
||||
jest.setTimeout(300000);
|
||||
|
||||
const notebookName = "GettingStarted.ipynb";
|
||||
let frame: Frame;
|
||||
let uploadedNotebookNode: ElementHandle<Element>;
|
||||
|
||||
describe("Notebook UI tests", () => {
|
||||
it("Upload, Open and Delete Notebook", async () => {
|
||||
try {
|
||||
frame = await getTestExplorerFrame();
|
||||
await page.goto("https://localhost:1234/testExplorer.html");
|
||||
const handle = await page.waitForSelector("iframe");
|
||||
const frame = await handle.contentFrame();
|
||||
await frame.waitForSelector(".galleryHeader");
|
||||
uploadedNotebookNode = await uploadNotebookIfNotExist(frame, notebookName);
|
||||
const uploadedNotebookNode = await uploadNotebookIfNotExist(frame, notebookName);
|
||||
await uploadedNotebookNode.click();
|
||||
await frame.waitForSelector(".tabNavText");
|
||||
const tabTitle = await frame.$eval(".tabNavText", (element) => element.textContent);
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
import { Frame } from "puppeteer";
|
||||
import { TestExplorerParams } from "../testExplorer/TestExplorerParams";
|
||||
import { getTestExplorerFrame } from "../testExplorer/TestExplorerUtils";
|
||||
import { SelfServeType } from "../../src/SelfServe/SelfServeUtils";
|
||||
import { ApiKind } from "../../src/Contracts/DataModels";
|
||||
|
||||
jest.setTimeout(300000);
|
||||
|
||||
let frame: Frame;
|
||||
describe("Self Serve", () => {
|
||||
it("Launch Self Serve Example", async () => {
|
||||
try {
|
||||
frame = await getTestExplorerFrame(
|
||||
ApiKind.SQL,
|
||||
new Map<string, string>([[TestExplorerParams.selfServeType, SelfServeType.example]])
|
||||
);
|
||||
await page.goto("https://localhost:1234/testExplorer.html?iframeSrc=selfServe.html");
|
||||
const handle = await page.waitForSelector("iframe");
|
||||
const frame = await handle.contentFrame();
|
||||
|
||||
// wait for refresh RP call to end
|
||||
await frame.waitFor(10000);
|
||||
|
||||
@@ -1,82 +1,50 @@
|
||||
/* eslint-disable no-console */
|
||||
import { ClientSecretCredential } from "@azure/identity";
|
||||
import "../../less/hostedexplorer.less";
|
||||
import { TestExplorerParams } from "./TestExplorerParams";
|
||||
import { CosmosDBManagementClient } from "@azure/arm-cosmosdb";
|
||||
import * as msRest from "@azure/ms-rest-js";
|
||||
import * as ViewModels from "../../src/Contracts/ViewModels";
|
||||
import { Capability, DatabaseAccount } from "../../src/Contracts/DataModels";
|
||||
import { DataExplorerInputsFrame } from "../../src/Contracts/ViewModels";
|
||||
import { updateUserContext } from "../../src/UserContext";
|
||||
import { get, listKeys } from "../../src/Utils/arm/generatedClients/2020-04-01/databaseAccounts";
|
||||
|
||||
class CustomSigner implements msRest.ServiceClientCredentials {
|
||||
private token: string;
|
||||
constructor(token: string) {
|
||||
this.token = token;
|
||||
}
|
||||
const resourceGroup = process.env.RESOURCE_GROUP || "";
|
||||
const subscriptionId = process.env.SUBSCRIPTION_ID || "";
|
||||
const urlSearchParams = new URLSearchParams(window.location.search);
|
||||
const accountName = urlSearchParams.get("accountName") || "portal-sql-runner";
|
||||
const selfServeType = urlSearchParams.get("selfServeType") || "example";
|
||||
const iframeSrc = urlSearchParams.get("iframeSrc") || "explorer.html?platform=Portal&disablePortalInitCache";
|
||||
|
||||
async signRequest(webResource: msRest.WebResourceLike): Promise<msRest.WebResourceLike> {
|
||||
webResource.headers.set("authorization", `bearer ${this.token}`);
|
||||
return webResource;
|
||||
}
|
||||
if (!process.env.AZURE_CLIENT_SECRET) {
|
||||
throw new Error(
|
||||
"process.env.AZURE_CLIENT_SECRET was not set! Set it in your .env file and restart webpack dev server"
|
||||
);
|
||||
}
|
||||
|
||||
const getDatabaseAccount = async (
|
||||
token: string,
|
||||
notebooksAccountSubscriptonId: string,
|
||||
notebooksAccountResourceGroup: string,
|
||||
notebooksAccountName: string
|
||||
): Promise<DatabaseAccount> => {
|
||||
const client = new CosmosDBManagementClient(new CustomSigner(token), notebooksAccountSubscriptonId);
|
||||
const databaseAccountGetResponse = await client.databaseAccounts.get(
|
||||
notebooksAccountResourceGroup,
|
||||
notebooksAccountName
|
||||
);
|
||||
// Azure SDK clients accept the credential as a parameter
|
||||
const credentials = new ClientSecretCredential(
|
||||
process.env.AZURE_TENANT_ID,
|
||||
process.env.AZURE_CLIENT_ID,
|
||||
process.env.AZURE_CLIENT_SECRET,
|
||||
{
|
||||
authorityHost: "https://localhost:1234",
|
||||
}
|
||||
);
|
||||
|
||||
const databaseAccount: DatabaseAccount = {
|
||||
id: databaseAccountGetResponse.id,
|
||||
name: databaseAccountGetResponse.name,
|
||||
location: databaseAccountGetResponse.location,
|
||||
type: databaseAccountGetResponse.type,
|
||||
kind: databaseAccountGetResponse.kind,
|
||||
tags: databaseAccountGetResponse.tags,
|
||||
properties: {
|
||||
documentEndpoint: databaseAccountGetResponse.documentEndpoint,
|
||||
tableEndpoint: undefined,
|
||||
gremlinEndpoint: undefined,
|
||||
cassandraEndpoint: undefined,
|
||||
capabilities: databaseAccountGetResponse.capabilities.map((capability) => {
|
||||
return { name: capability.name } as Capability;
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
return databaseAccount;
|
||||
};
|
||||
console.log("Resource Group:", resourceGroup);
|
||||
console.log("Subcription: ", subscriptionId);
|
||||
console.log("Account Name: ", accountName);
|
||||
|
||||
const initTestExplorer = async (): Promise<void> => {
|
||||
const urlSearchParams = new URLSearchParams(window.location.search);
|
||||
const portalRunnerDatabaseAccount = decodeURIComponent(
|
||||
urlSearchParams.get(TestExplorerParams.portalRunnerDatabaseAccount)
|
||||
);
|
||||
const portalRunnerDatabaseAccountKey = decodeURIComponent(
|
||||
urlSearchParams.get(TestExplorerParams.portalRunnerDatabaseAccountKey)
|
||||
);
|
||||
const portalRunnerSubscripton = decodeURIComponent(urlSearchParams.get(TestExplorerParams.portalRunnerSubscripton));
|
||||
const portalRunnerResourceGroup = decodeURIComponent(
|
||||
urlSearchParams.get(TestExplorerParams.portalRunnerResourceGroup)
|
||||
);
|
||||
const selfServeType = urlSearchParams.get(TestExplorerParams.selfServeType);
|
||||
|
||||
const token = decodeURIComponent(urlSearchParams.get(TestExplorerParams.token));
|
||||
const databaseAccount = await getDatabaseAccount(
|
||||
token,
|
||||
portalRunnerSubscripton,
|
||||
portalRunnerResourceGroup,
|
||||
portalRunnerDatabaseAccount
|
||||
);
|
||||
const { token } = await credentials.getToken("https://management.core.windows.net/.default");
|
||||
updateUserContext({
|
||||
authorizationToken: `bearer ${token}`,
|
||||
});
|
||||
const databaseAccount = await get(subscriptionId, resourceGroup, accountName);
|
||||
const keys = await listKeys(subscriptionId, resourceGroup, accountName);
|
||||
|
||||
const initTestExplorerContent = {
|
||||
inputs: {
|
||||
databaseAccount: databaseAccount,
|
||||
subscriptionId: portalRunnerSubscripton,
|
||||
resourceGroup: portalRunnerResourceGroup,
|
||||
subscriptionId,
|
||||
resourceGroup,
|
||||
authorizationToken: `Bearer ${token}`,
|
||||
features: {},
|
||||
hasWriteAccess: true,
|
||||
@@ -88,7 +56,7 @@ const initTestExplorer = async (): Promise<void> => {
|
||||
quotaId: "Internal_2014-09-01",
|
||||
addCollectionDefaultFlight: "2",
|
||||
isTryCosmosDBSubscription: false,
|
||||
masterKey: portalRunnerDatabaseAccountKey,
|
||||
masterKey: keys.primaryMasterKey,
|
||||
loadDatabaseAccountTimestamp: 1604663109836,
|
||||
dataExplorerVersion: "1.0.1",
|
||||
sharedThroughputMinimum: 400,
|
||||
@@ -101,7 +69,7 @@ const initTestExplorer = async (): Promise<void> => {
|
||||
// add UI test only when feature is not dependent on flights anymore
|
||||
flights: [],
|
||||
selfServeType,
|
||||
} as ViewModels.DataExplorerInputsFrame,
|
||||
} as DataExplorerInputsFrame,
|
||||
};
|
||||
|
||||
const iframe = document.createElement("iframe");
|
||||
@@ -127,16 +95,8 @@ const initTestExplorer = async (): Promise<void> => {
|
||||
iframe.name = "explorer";
|
||||
iframe.classList.add("iframe");
|
||||
iframe.title = "explorer";
|
||||
iframe.src = getIframeSrc(selfServeType);
|
||||
iframe.src = iframeSrc;
|
||||
document.body.appendChild(iframe);
|
||||
};
|
||||
|
||||
const getIframeSrc = (selfServeType: string): string => {
|
||||
let iframeSrc = "explorer.html?platform=Portal&disablePortalInitCache";
|
||||
if (selfServeType) {
|
||||
iframeSrc = `selfServe.html?selfServeType=${selfServeType}`;
|
||||
}
|
||||
return iframeSrc;
|
||||
};
|
||||
|
||||
initTestExplorer();
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
export enum TestExplorerParams {
|
||||
portalRunnerDatabaseAccount = "portalRunnerDatabaseAccount",
|
||||
portalRunnerDatabaseAccountKey = "portalRunnerDatabaseAccountKey",
|
||||
portalRunnerSubscripton = "portalRunnerSubscripton",
|
||||
portalRunnerResourceGroup = "portalRunnerResourceGroup",
|
||||
selfServeType = "selfServeType",
|
||||
token = "token",
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
import { Frame } from "puppeteer";
|
||||
import { TestExplorerParams } from "./TestExplorerParams";
|
||||
import { ClientSecretCredential } from "@azure/identity";
|
||||
import { ApiKind } from "../../src/Contracts/DataModels";
|
||||
|
||||
let testExplorerFrame: Frame;
|
||||
export const getTestExplorerFrame = async (apiKind?: ApiKind, params?: Map<string, string>): Promise<Frame> => {
|
||||
if (testExplorerFrame) {
|
||||
return testExplorerFrame;
|
||||
}
|
||||
|
||||
let portalRunnerDatabaseAccount: string;
|
||||
let portalRunnerDatabaseAccountKey: string;
|
||||
|
||||
switch (apiKind) {
|
||||
case ApiKind.MongoDB:
|
||||
portalRunnerDatabaseAccount = process.env.PORTAL_RUNNER_MONGO_DATABASE_ACCOUNT;
|
||||
portalRunnerDatabaseAccountKey = process.env.PORTAL_RUNNER_MONGO_DATABASE_ACCOUNT_KEY;
|
||||
break;
|
||||
default:
|
||||
portalRunnerDatabaseAccount = process.env.PORTAL_RUNNER_DATABASE_ACCOUNT;
|
||||
portalRunnerDatabaseAccountKey = process.env.PORTAL_RUNNER_DATABASE_ACCOUNT_KEY;
|
||||
}
|
||||
|
||||
const notebooksTestRunnerTenantId = process.env.NOTEBOOKS_TEST_RUNNER_TENANT_ID;
|
||||
const notebooksTestRunnerClientId = process.env.NOTEBOOKS_TEST_RUNNER_CLIENT_ID;
|
||||
const notebooksTestRunnerClientSecret = process.env.NOTEBOOKS_TEST_RUNNER_CLIENT_SECRET;
|
||||
const portalRunnerSubscripton = process.env.PORTAL_RUNNER_SUBSCRIPTION;
|
||||
const portalRunnerResourceGroup = process.env.PORTAL_RUNNER_RESOURCE_GROUP;
|
||||
|
||||
const credentials = new ClientSecretCredential(
|
||||
notebooksTestRunnerTenantId,
|
||||
notebooksTestRunnerClientId,
|
||||
notebooksTestRunnerClientSecret
|
||||
);
|
||||
|
||||
const { token } = await credentials.getToken("https://management.core.windows.net/.default");
|
||||
|
||||
const testExplorerUrl = new URL("testExplorer.html", "https://localhost:1234");
|
||||
testExplorerUrl.searchParams.append(
|
||||
TestExplorerParams.portalRunnerDatabaseAccount,
|
||||
encodeURI(portalRunnerDatabaseAccount)
|
||||
);
|
||||
testExplorerUrl.searchParams.append(
|
||||
TestExplorerParams.portalRunnerDatabaseAccountKey,
|
||||
encodeURI(portalRunnerDatabaseAccountKey)
|
||||
);
|
||||
testExplorerUrl.searchParams.append(TestExplorerParams.portalRunnerSubscripton, encodeURI(portalRunnerSubscripton));
|
||||
testExplorerUrl.searchParams.append(
|
||||
TestExplorerParams.portalRunnerResourceGroup,
|
||||
encodeURI(portalRunnerResourceGroup)
|
||||
);
|
||||
testExplorerUrl.searchParams.append(TestExplorerParams.token, encodeURI(token));
|
||||
|
||||
if (params) {
|
||||
for (const key of params.keys()) {
|
||||
testExplorerUrl.searchParams.append(key, encodeURI(params.get(key)));
|
||||
}
|
||||
}
|
||||
|
||||
await page.goto(testExplorerUrl.toString());
|
||||
const handle = await page.waitForSelector("iframe");
|
||||
return await handle.contentFrame();
|
||||
};
|
||||
@@ -30,8 +30,8 @@ export function generateDatabaseName(baseName = "db", length = 1): string {
|
||||
return `${baseName}${crypto.randomBytes(length).toString("hex")}-${Date.now()}`;
|
||||
}
|
||||
|
||||
export async function createDatabase(frame: Frame): Promise<string> {
|
||||
const dbId = generateDatabaseName();
|
||||
export async function createDatabase(frame: Frame): Promise<{ databaseId: string; collectionId: string }> {
|
||||
const databaseId = generateDatabaseName();
|
||||
const collectionId = generateUniqueName("col");
|
||||
const shardKey = "partitionKey";
|
||||
// create new collection
|
||||
@@ -50,7 +50,7 @@ export async function createDatabase(frame: Frame): Promise<string> {
|
||||
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);
|
||||
await dbInput.type(databaseId);
|
||||
|
||||
// type collection id
|
||||
await frame.waitFor('input[data-test="addCollection-collectionId"]');
|
||||
@@ -67,7 +67,7 @@ export async function createDatabase(frame: Frame): Promise<string> {
|
||||
// click submit
|
||||
await frame.waitFor("#submitBtnAddCollection");
|
||||
await frame.click("#submitBtnAddCollection");
|
||||
return dbId;
|
||||
return { databaseId, collectionId };
|
||||
}
|
||||
|
||||
export async function onClickSaveButton(frame: Frame): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user