Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions app/components/Index/common/indexTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AzulSummaryResponse } from "@databiosphere/findable-ui/lib/apis/azul/common/entities";
import { Summary } from "@databiosphere/findable-ui/lib/components/Index/components/Hero/components/Summaries/summaries";
import { formatCountSize } from "@databiosphere/findable-ui/lib/utils/formatCountSize";
import {
BIND_SUMMARY_RESPONSE,
Expand All @@ -20,23 +19,19 @@ export function getPluralizedMetadataLabel(
}

/**
* Maps index summaries from summary API response.
* Maps entity list summaries from summary API response.
* @param summaries - Summary list.
* @param summaryResponse - Response model return from summary API.
* @returns summary counts.
* @returns summary key-value pairs (count, label).
*/
export function getSummaries(
export function mapSummary(
summaries: Array<keyof typeof SUMMARY>,
summaryResponse: AzulSummaryResponse
): Summary[] {
): [string, string][] {
return summaries.map((summary) => {
const summaryBinderFn = BIND_SUMMARY_RESPONSE[summary];
const count = summaryBinderFn(summaryResponse);
const formattedCount = formatCountSize(count);
const count = formatCountSize(summaryBinderFn(summaryResponse));
const label = SUMMARY_LABEL[summary];
return {
count: formattedCount,
label,
};
return [count, label];
});
}
1 change: 0 additions & 1 deletion app/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export { ManifestDownloadEntity } from "@databiosphere/findable-ui/lib/component
export { ManifestDownloadForm } from "@databiosphere/findable-ui/lib/components/Export/components/ManifestDownload/components/ManifestDownloadForm/manifestDownloadForm";
export { ManifestDownload } from "@databiosphere/findable-ui/lib/components/Export/components/ManifestDownload/manifestDownload";
export { AzulFileDownload } from "@databiosphere/findable-ui/lib/components/Index/components/AzulFileDownload/azulFileDownload";
export { Summaries } from "@databiosphere/findable-ui/lib/components/Index/components/Hero/components/Summaries/summaries";
export {
BackPageContentMainColumn,
BackPageContentSideColumn,
Expand Down
112 changes: 89 additions & 23 deletions e2e/anvil/anvil-index-export-button.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,94 @@
import test from "@playwright/test";
import {
testBulkDownloadIndexExportWorkflow,
testIndexExportSummary,
} from "../testFunctions";
import test, { ElementHandle, Response, Page } from "@playwright/test";
import { expect } from "@playwright/test";
import { testBulkDownloadIndexExportWorkflow } from "../testFunctions";
import { ANVIL_TABS } from "./anvil-tabs";
import { MUI_CLASSES, TEST_IDS } from "../features/common/constants";

test("Smoke test File Manifest Request index export workflow on the Files tab", async ({
page,
}) => {
test.setTimeout(120000);
const testResult = await testBulkDownloadIndexExportWorkflow(
test.describe("AnVIL Data Explorer Export", () => {
test("Smoke test File Manifest Request index export workflow on the Files tab", async ({
page,
ANVIL_TABS.FILES
);
if (!testResult) {
test.fail();
}
});
}) => {
test.setTimeout(120000);
const testResult = await testBulkDownloadIndexExportWorkflow(
page,
ANVIL_TABS.FILES
);
if (!testResult) {
test.fail();
}
});

test("Verifies that the Selected Data Summary on the export page displays the same label and count as the summary on the BioSamples tab", async ({
page,
}) => {
await page.goto("/biosamples");
await page.waitForURL(/\/biosamples/);
await Promise.all([waitForTestId(page, TEST_IDS.ENTITY_SUMMARY)]);

// Export button should be visible.
const button = page.getByTestId(TEST_IDS.EXPORT_BUTTON);
await expect(button).toBeVisible();

// Summary should be visible.
const summaryLocator = page.getByTestId(TEST_IDS.ENTITY_SUMMARY);
await expect(summaryLocator).toBeVisible();

// Get each summary span's inner text.
const innerTexts = await summaryLocator
.locator(MUI_CLASSES.TYPOGRAPHY) // Retrieves the count and label and omits the dot separator.
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Relying on the generic .MuiTypography-root selector can make tests brittle if other typography elements are added. Consider adding or using a dedicated data-testid on the summary items to target them more reliably.

Suggested change
.locator(MUI_CLASSES.TYPOGRAPHY) // Retrieves the count and label and omits the dot separator.
.getByTestId(TEST_IDS.SUMMARY_ITEM) // Retrieves the count and label and omits the dot separator.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving it as, for now.

.allTextContents();

test("Check that figures in the Selected Data Summary tab on the index export page matches figures on the index page on the BioSamples tab", async ({
page,
}) => {
const testResult = await testIndexExportSummary(page, ANVIL_TABS.BIOSAMPLES);
if (!testResult) {
test.fail();
}
// Pair each summary item's label and count by iterating through the text contents
// two at a time, and store them as [label, count] tuples in the summary array.
const summary: [string, string][] = [];
for (let i = 0; i < innerTexts.length; i += 2) {
summary.push([innerTexts[i + 1], innerTexts[i]]);
}

// Click the export button and wait for the summary API to be called.
await Promise.all([
button.click(),
page.waitForURL(/\/export/),
page.waitForResponse(urlOrPredicate),
waitForTestId(page, TEST_IDS.EXPORT_SUMMARY),
]);

// Export summary should be visible.
const exportSummaryLocator = page.getByTestId(TEST_IDS.EXPORT_SUMMARY);
await expect(exportSummaryLocator).toBeVisible();

// Test that each summary item is present in the export summary
// with corresponding count.
for (const [label, count] of summary) {
const summaryItem = exportSummaryLocator
.locator("> div")
.filter({ hasText: label });
await expect(summaryItem).toBeVisible();
await expect(summaryItem).toContainText(count, { timeout: 5000 });
}
});
});

/**
* Checks if the response is the index summary API.
* @param r - Response.
* @returns boolean.
*/
function urlOrPredicate(r: Response): boolean {
return r.url().includes("/index/summary") && r.status() === 200;
}

/**
* Waits for a locator to be visible.
* @param page - Page.
* @param testId - Test ID.
* @returns Promise<void>.
*/
function waitForTestId(
page: Page,
testId: string
): Promise<ElementHandle<HTMLElement | SVGElement>> {
return page.waitForSelector(`[data-testid="${testId}"]`, {
state: "visible",
});
}
3 changes: 3 additions & 0 deletions e2e/features/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ export const MUI_CLASSES = {
TABLE_ROW: ".MuiTableRow-root",
TABLE_SORT_LABEL: ".MuiTableSortLabel-root",
TABLE_SORT_LABEL_ICON: ".MuiTableSortLabel-icon",
TYPOGRAPHY: ".MuiTypography-root",
};

export const TEST_IDS = {
CLEAR_ALL_FILTERS: "clear-all-filters",
ENTITIES_VIEW: "entities-view",
ENTITY_SUMMARY: "entity-summary",
EXPORT_BUTTON: "export-button",
EXPORT_SUMMARY: "export-summary",
FILTERS: "filters",
FILTER_CONTROLS: "filter-controls",
FILTER_COUNT: "filter-count",
Expand Down
55 changes: 0 additions & 55 deletions e2e/testFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,61 +940,6 @@ export async function testBulkDownloadIndexExportWorkflow(
return true;
}

/**
* Check that the summary box on the "Choose Export Method" page has numbers that match those on the index page
* @param page - a Playwright page object
* @param tab - the tab to test on
* @returns - true if the test passes, false if it should fail but does not fail an assertion
*/
export async function testIndexExportSummary(
page: Page,
tab: TabDescription
): Promise<boolean> {
if (tab?.indexExportPage === undefined) {
console.log(
"testIndexExportSummmary Error: indexExportPage not specified for given tab, so test cannot run"
);
return false;
}
await page.goto(tab.url);
const headers: { header: string; value: string }[] = [];
const indexExportButtonLocator = page.getByRole("link", {
name: tab.indexExportPage.indexExportButtonText,
});
await expect(indexExportButtonLocator).toBeVisible();
for (const detail of tab.indexExportPage.detailsToCheck) {
// This Regexp gets a decimal number, some whitespace, then the name of the detail, matching how the detail box appears to Playwright.
const detailBoxRegexp = RegExp(`^(\\d+\\.\\d+k)\\s*${detail}$`);
// This gets the detail's value. The .trim() is necessary since innertext adds extraneous whitespace on Webkit
const headerValueArray = (await page.getByText(detailBoxRegexp).innerText())
.trim()
.match(detailBoxRegexp);
// Check that the regex matches the expected format
if (headerValueArray === null || headerValueArray.length !== 2) {
console.log(
"testIndexExportSummmary Error: The detail box text does not match the expected format"
);
return false;
}
// Save the header value and detail for later comparison
headers.push({
header: detail,
value: headerValueArray[1],
});
}
await indexExportButtonLocator.click();
for (const headerValue of headers) {
// Expect the correct value to be below the correct header in the dataset values table
await expect(
page
.locator(`:below(:text('${headerValue.header}'))`)
.getByText(headerValue.value)
.first()
).toBeVisible();
}
return true;
}

const PAGE_COUNT_REGEX = /Page \d+ of \d+/;
const MAX_PAGINATIONS = 200;

Expand Down
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ESM_PACKAGES = [
"@databiosphere/findable-ui",
"@observablehq/plot",
"@tanstack/react-table",
"@tanstack/react-virtual",
];

const withMDX = nextMDX({
Expand Down
53 changes: 25 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"check-system-status:anvil-cmg": "esrun e2e/anvil/anvil-check-system-status.ts"
},
"dependencies": {
"@databiosphere/findable-ui": "^37.1.0",
"@databiosphere/findable-ui": "^38.1.0",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@mdx-js/loader": "^3.0.1",
Expand All @@ -42,6 +42,7 @@
"@next/mdx": "^14.2.28",
"@observablehq/plot": "^0.6.17",
"@tanstack/react-table": "^8.19.2",
"@tanstack/react-virtual": "^3.13.12",
"@types/fhir": "^0.0.35",
"copy-to-clipboard": "3.3.1",
"csv-parse": "^5.0.4",
Expand Down
1 change: 0 additions & 1 deletion site-config/anvil-catalog/dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export function makeConfig(
studiesEntityConfig,
workspaceEntityConfig,
],
explorerTitle: APP_TITLE,
export: exportConfig, // TODO(cc) export config should be optional, we should add notFound to export pages.
gitHubUrl,
layout: {
Expand Down
Loading
Loading