2024-04-09 10:55:08 -07:00
|
|
|
import { AzureCliCredentials } from "@azure/ms-rest-nodeauth";
|
2020-09-30 16:42:33 -04:00
|
|
|
import crypto from "crypto";
|
2024-05-29 09:56:27 -07:00
|
|
|
import { Frame } from "playwright";
|
|
|
|
|
|
|
|
export enum AccountType {
|
|
|
|
Tables = "Tables",
|
|
|
|
Cassandra = "Cassandra",
|
|
|
|
Gremlin = "Gremlin",
|
|
|
|
Mongo = "Mongo",
|
|
|
|
Mongo32 = "Mongo32",
|
|
|
|
SQL = "SQL",
|
|
|
|
}
|
|
|
|
|
|
|
|
export const defaultAccounts: Record<AccountType, string> = {
|
|
|
|
[AccountType.Tables]: "portal-tables-runner",
|
|
|
|
[AccountType.Cassandra]: "portal-cassandra-runner",
|
|
|
|
[AccountType.Gremlin]: "portal-gremlin-runner",
|
|
|
|
[AccountType.Mongo]: "portal-mongo-runner",
|
|
|
|
[AccountType.Mongo32]: "portal-mongo32-runner",
|
|
|
|
[AccountType.SQL]: "portal-sql-runner-west-us",
|
|
|
|
};
|
|
|
|
|
|
|
|
const resourceGroup = process.env.DE_TEST_RESOURCE_GROUP ?? "runners";
|
|
|
|
const subscriptionId = process.env.DE_TEST_SUBSCRIPTION_ID ?? "69e02f2d-f059-4409-9eac-97e8a276ae2c";
|
|
|
|
|
|
|
|
export async function getTestExplorerUrl(accountType: AccountType) {
|
|
|
|
// We can't retrieve AZ CLI credentials from the browser so we get them here.
|
|
|
|
const token = await getAzureCLICredentialsToken();
|
|
|
|
const accountName =
|
|
|
|
process.env[`DE_TEST_ACCOUNT_NAME_${accountType.toLocaleUpperCase()}`] ?? defaultAccounts[accountType];
|
|
|
|
return `https://localhost:1234/testExplorer.html?accountName=${accountName}&resourceGroup=${resourceGroup}&subscriptionId=${subscriptionId}&token=${token}`;
|
|
|
|
}
|
2020-09-30 16:42:33 -04:00
|
|
|
|
2020-11-02 14:33:14 -05:00
|
|
|
export function generateUniqueName(baseName = "", length = 4): string {
|
2020-09-30 16:42:33 -04:00
|
|
|
return `${baseName}${crypto.randomBytes(length).toString("hex")}`;
|
|
|
|
}
|
2021-02-18 07:40:58 -06:00
|
|
|
|
2021-04-21 12:45:34 -05:00
|
|
|
export function generateDatabaseNameWithTimestamp(baseName = "db", length = 1): string {
|
2021-03-04 18:12:31 -06:00
|
|
|
return `${baseName}${crypto.randomBytes(length).toString("hex")}-${Date.now()}`;
|
|
|
|
}
|
2024-04-09 10:55:08 -07:00
|
|
|
|
|
|
|
export async function getAzureCLICredentials(): Promise<AzureCliCredentials> {
|
|
|
|
return await AzureCliCredentials.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getAzureCLICredentialsToken(): Promise<string> {
|
|
|
|
const credentials = await getAzureCLICredentials();
|
|
|
|
const token = (await credentials.getToken()).accessToken;
|
|
|
|
return token;
|
|
|
|
}
|
2024-05-29 09:56:27 -07:00
|
|
|
|
|
|
|
export function getPanelSelector(title: string) {
|
|
|
|
return `[data-test="Panel:${title}"]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTreeNodeSelector(id: string) {
|
|
|
|
return `[data-test="TreeNode:${id}"]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTreeMenuItemSelector(nodeId: string, itemLabel: string) {
|
|
|
|
return `[data-test="TreeNode/ContextMenu:${nodeId}"] [data-test="TreeNode/ContextMenuItem:${itemLabel}"]`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function openContextMenu(explorer: Frame, nodeIdentifier: string) {
|
|
|
|
const nodeSelector = getTreeNodeSelector(nodeIdentifier);
|
|
|
|
await explorer.hover(nodeSelector);
|
|
|
|
await explorer.click(`${nodeSelector} [data-test="TreeNode/ContextMenuTrigger"]`);
|
|
|
|
await explorer.waitForSelector(`[data-test="TreeNode/ContextMenu:${nodeIdentifier}"]`);
|
|
|
|
}
|