Skip to content

Commit

Permalink
prettified
Browse files Browse the repository at this point in the history
  • Loading branch information
royendo committed Dec 21, 2024
1 parent 80eeb9f commit fe2a204
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 67 deletions.
21 changes: 20 additions & 1 deletion web-local/tests/utils/commonHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { asyncWaitUntil } from "@rilldata/web-common/lib/waitUtils";
import type { Page } from "playwright";
import { expect } from "@playwright/test";

export async function openFileNavEntryContextMenu(
page: Page,
Expand All @@ -19,7 +20,7 @@ export async function clickMenuButton(
text: string,
role: "menuitem" | "option" = "menuitem",
) {
await page.getByRole(role, { name: text }).click();
await page.getByRole(role, { name: text }).first().click();
}

export async function waitForProfiling(
Expand Down Expand Up @@ -162,3 +163,21 @@ export async function actionUsingMenu(
await openFileNavEntryContextMenu(page, filePath);
await clickMenuButton(page, action);
}

export async function checkExistInConnector(
page: Page,
connector: String,

Check failure on line 169 in web-local/tests/utils/commonHelpers.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using the primitive `string` as a type name, rather than the upper-cased `String`
db: String,

Check failure on line 170 in web-local/tests/utils/commonHelpers.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using the primitive `string` as a type name, rather than the upper-cased `String`
fileName: String,

Check failure on line 171 in web-local/tests/utils/commonHelpers.ts

View workflow job for this annotation

GitHub Actions / build

Prefer using the primitive `string` as a type name, rather than the upper-cased `String`
) {
await page.locator(`li[aria-label="${connector}"]`).click();
await page.locator(`li[aria-label="${db}"]`).click();
await page.locator(`li[aria-label^="${db}."]`).click(); //table name dynamic
await expect(
page
.locator(
`[aria-label*="${connector}-${db}."][aria-label*=".${fileName}"]`,
)
.first(),
).toBeVisible(); //table name dynamic
}
115 changes: 53 additions & 62 deletions web-local/tests/utils/inspectorHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,69 @@
import { expect } from "@playwright/test";
import type { Page } from "playwright";


// checking source inspector
// checking source inspector rows and column values.
export async function checkInspectorSource(
page: Page,
expectedRows: string, //expected row count
expectedColumns: string, //expected column_count
sourceColumns: Array<string>,
page: Page,
expectedRows: string, //expected row count
expectedColumns: string, //expected column_count
sourceColumns: Array<string>,
) {
// check row count
const inspectorRows = await page.getByRole('cell', { name: /rows$/i });
const fullTextRow = await inspectorRows.textContent();

// Extract the numeric part from the string
const numericValueRow = fullTextRow?.match(/\d{1,3}(,\d{3})*/)?.[0];
expect(numericValueRow).toBe(expectedRows);
// check row count
const inspectorRows = await page.getByRole("cell", { name: /rows$/i });
const fullTextRow = await inspectorRows.textContent();

// check column count
const inspectorCols = await page.getByRole('cell', { name: /columns$/i });
const fullTextCol = await inspectorCols.textContent();
// Extract the numeric part from the string
const numericValueRow = fullTextRow?.match(/\d{1,3}(,\d{3})*/)?.[0];
expect(numericValueRow).toBe(expectedRows);

// Extract the numeric part from the string
const numericValueCol = fullTextCol?.match(/\d{1,3}(,\d{3})*/)?.[0];
expect(numericValueCol).toBe(expectedColumns);
// check column count
const inspectorCols = await page.getByRole("cell", { name: /columns$/i });
const fullTextCol = await inspectorCols.textContent();

// checking the column details,
await Promise.all([
testColumnsAndChartnDiv(page, sourceColumns)
]);
// Extract the numeric part from the string
const numericValueCol = fullTextCol?.match(/\d{1,3}(,\d{3})*/)?.[0];
expect(numericValueCol).toBe(expectedColumns);

};
// checking the column details,
await Promise.all([testColumnsAndChartnDiv(page, sourceColumns)]);
}

// function that opens each column and checks if not empty. Need to check with CH source to see if this is actually working. //closes div
async function testColumnsAndChartnDiv(page, expectedColumns) {
for (const columnName of expectedColumns) {
// Click the button by its name
await page.getByRole('button', { name: columnName }).click();

// Wait for the column div to be visible
const presentationDiv = await page.waitForSelector('div[role="presentation"]', { state: 'visible' });
// Assert that the div is not empty (not falsy) IE: has contents
expect(presentationDiv).not.toBeFalsy();

// await presentationDiv.hover();
// Wait for the tooltip div to appear
// const tooltipDiv = await page.waitForSelector('div[role="tooltip"]', { state: 'visible' });
// Assert that the tooltip div is visible
// expect(tooltipDiv).not.toBeFalsy();

// Close the column div by clicking the button again
await page.getByRole('button', { name: columnName }).click();
}
for (const columnName of expectedColumns) {
// Click the button by its name
await page.getByRole("button", { name: columnName }).click();

// Wait for the column div to be visible
const presentationDiv = await page.waitForSelector(
'div[role="presentation"]',
{ state: "visible" },
);
// Assert that the div is not empty (not falsy) IE: has contents
expect(presentationDiv).not.toBeFalsy();

// Close the column div by clicking the button again
await page.getByRole("button", { name: columnName }).click();
}
}


// checking model inspector
// checking model inspector rows and column values.
export async function checkInspectorModel(
page: Page,
expectedRows: string, //expected row count
expectedColumns: string, //expected column_count
sourceColumns: Array<string>,
page: Page,
expectedRows: string, //expected row count
expectedColumns: string, //expected column_count
sourceColumns: Array<string>,
) {
const inspectorWrapper = await page.locator('.inspector-wrapper');

// Check if the text '100,000 rows' and '16 columns' exists within the container, needed to change as UI changes a bit from source
await expect(inspectorWrapper.locator(`text="${expectedRows} rows"`)).toHaveCount(1);
await expect(inspectorWrapper.locator(`text="${expectedColumns} columns"`)).toHaveCount(1);


// checking the column details for not empty,
await Promise.all([
testColumnsAndChartnDiv(page, sourceColumns)

]);

};
const inspectorWrapper = await page.locator(".inspector-wrapper");

// Check if the text '100,000 rows' and '16 columns' exists within the container, needed to change as UI changes a bit from source
await expect(
inspectorWrapper.locator(`text="${expectedRows} rows"`),
).toHaveCount(1);
await expect(
inspectorWrapper.locator(`text="${expectedColumns} columns"`),
).toHaveCount(1);

// checking the column details for not empty,
await Promise.all([testColumnsAndChartnDiv(page, sourceColumns)]);
}
7 changes: 3 additions & 4 deletions web-local/tests/utils/sourceHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ export async function waitForTable(
) {
const [, fileName] = splitFolderAndFileName(filePath);
const name = extractFileName(fileName);
console.log(name);
// add checks later, need to figure out how this works

await Promise.all([
// page.getByText("View this source").click(), Once v52 released, need to select View this Source
waitForFileNavEntry(page, filePath, true),
page.getByText("View this source").click(),
waitForFileNavEntry(page, filePath, false),
waitForProfiling(page, name, columns), //this one is imported bc failed sources will still navigate
]);
}
Expand Down
1 change: 1 addition & 0 deletions web-local/tests/utils/waitHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export async function waitForFileNavEntry(
navigated: boolean,
) {
await page.getByLabel(`${filePath} Nav Entry`).waitFor();

if (navigated) {
await page.waitForURL(new RegExp(`/files${filePath}`));
}
Expand Down

0 comments on commit fe2a204

Please sign in to comment.