Skip to content

Commit

Permalink
fix: refactored tests (#4068)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpaten committed Jul 15, 2024
1 parent 0d1b687 commit bedd431
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
7 changes: 5 additions & 2 deletions explorer/e2e/anvil/anvil-filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "../testFunctions";
import { anvilFilters, anvilTabs, anvilTabTestOrder } from "./anvil-tabs";

test.describe.configure({ mode: "parallel" });
test.describe.configure({ mode: "parallel", timeout: 60 * 1000 });
const filter_index_list = [3, 4, 5, 7, 6, 2];

test("Check that all filters exist on the Datasets tab and are clickable", async ({
Expand Down Expand Up @@ -85,12 +85,15 @@ test("Check that filter checkboxes are persistent across pages on an arbitrary f
test("Check that filter menu counts match actual counts on the Datasets tab", async ({
page,
}) => {
await testFilterCounts(
const result = await testFilterCounts(
page,
anvilTabs.datasets,
filter_index_list.map((x) => anvilFilters[x]),
25
);
if (!result) {
test.fail();
}
});

test("Check that filter menu counts match actual counts on the Activities tab", async ({
Expand Down
42 changes: 27 additions & 15 deletions explorer/e2e/testFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,18 @@ export async function testFilterPersistence(
await expect(getFirstElementTextLocator(page, 0)).toBeVisible();
// For each tab, check that the selected filter is still checked
for (const tab of tabOrder.slice(1)) {
await page.getByRole("tab").getByText(tab.tabName).click();
await page.getByRole("tab").getByText(tab.tabName, { exact: true }).click();
await expect(page.getByText(filterRegex(testFilter))).toBeVisible();
await page.getByText(filterRegex(testFilter)).click();
const previously_selected = getNamedFilterButton(page, filterName);
await expect(previously_selected.getByRole("checkbox")).toBeChecked();
await page.locator("body").click();
}
// Return to the start tab and confirm that the filter stays checked and that some content is visible
await page.getByRole("tab").getByText(tabOrder[0].tabName).click();
await page
.getByRole("tab")
.getByText(tabOrder[0].tabName, { exact: true })
.click();
await expect(getFirstElementTextLocator(page, 0)).toBeVisible();
await page.getByText(filterRegex(testFilter)).click();
const previously_selected = getFirstFilterButton(page);
Expand All @@ -295,26 +298,32 @@ export async function testFilterCounts(
tab: TabDescription,
filters: string[],
elements_per_page: number
): Promise<void> {
): Promise<boolean> {
await page.goto(tab.url);
// For each arbitrarily selected filter
for (const filter of filters) {
// Select the filter
await page.getByText(filterRegex(filter)).click();
// Get the number associated with the first filter button, and select it
const filter_button = getFirstFilterButton(page);
const filterNumber = Number(
(await filter_button.innerText()).split("\n")[1]
);
const filter_numbers = (await filter_button.innerText()).split("\n");
const filter_number =
filter_numbers.map((x) => Number(x)).find((x) => !isNaN(x)) ?? -1;
if (!filter_number) {
return false;
}
await filter_button.getByRole("checkbox").setChecked(true);
//
await page.locator("body").click();
await expect(page.getByRole("checkbox")).toHaveCount(0);
const firstNumber =
filterNumber <= elements_per_page ? filterNumber : elements_per_page;
filter_number <= elements_per_page ? filter_number : elements_per_page;
console.log("Results 1 - " + firstNumber + " of " + filter_number);

await expect(
page.getByText("Results 1 - " + firstNumber + " of " + filterNumber)
page.getByText("Results 1 - " + firstNumber + " of " + filter_number)
).toBeVisible();
}
return true;
}

export async function testFilterBubbles(
Expand All @@ -326,15 +335,18 @@ export async function testFilterBubbles(
for (const filter of filters) {
await page.getByText(filterRegex(filter)).click();
const firstFilterButton = getFirstFilterButton(page);
const firstFilterName = (await firstFilterButton.innerText()).split(
"\n"
)[0];
await firstFilterButton.getByRole("checkbox").setChecked(true);
await page.locator("body").click();
const firstFilterName =
(await firstFilterButton.innerText())
.split("\n")
.find((x) => x.length > 0) ?? "";
await firstFilterButton.getByRole("checkbox").click();
await page.keyboard.press("Escape");
await expect(page.getByRole("checkbox")).toHaveCount(0);
const filterBlueButton = page
.getByRole("button")
.locator("#sidebar-positioner")
.getByText(firstFilterName);
await expect(filterBlueButton).toBeVisible();
await filterBlueButton.scrollIntoViewIfNeeded();
await filterBlueButton.click();
await expect(filterBlueButton).toHaveCount(0);
}
Expand Down
2 changes: 1 addition & 1 deletion explorer/playwright_anvil.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ const config: PlaywrightTestConfig = {
timeout: 240 * 1000,
url: "http://localhost:3000/",
},
workers: "75%",
workers: 1,
};
export default config;

0 comments on commit bedd431

Please sign in to comment.