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
8 changes: 3 additions & 5 deletions app/views/ExploreView/exploreView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
ExploreView as DXExploreView,
ExploreViewProps,
} from "@databiosphere/findable-ui/lib/views/ExploreView/exploreView";
import { ExploreView as DXExploreView } from "@databiosphere/findable-ui/lib/views/ExploreView/exploreView";
import type { ExploreViewProps } from "@databiosphere/findable-ui/lib/views/ExploreView/types";
import type { JSX } from "react";
import { useDefaultEntityFilters } from "./hooks/useDefaultEntityFilters/hook";

Expand All @@ -15,7 +13,7 @@ import { useDefaultEntityFilters } from "./hooks/useDefaultEntityFilters/hook";
* The default is applied once per session via sessionStorage and is not reapplied
* after the user interacts with filters or navigates between tabs.
*
* @param props - ExploreView props (entityListType, data, etc.).
* @param props - ExploreView props (entityListType and the statically loaded entities, if any).
* @returns ExploreView component with default entity filters applied.
*/
export const ExploreView = (props: ExploreViewProps): JSX.Element => {
Expand Down
22 changes: 16 additions & 6 deletions e2e/hprc-filters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from "@playwright/test";
import { expect, test } from "@playwright/test";
import { HPRC_TABS } from "./hprc-tabs";
import {
testAllFiltersPresence,
Expand Down Expand Up @@ -58,25 +58,33 @@ test("Expect filter counts to update for the first five on the Alignments tab",
test('Check that selecting the first filter through the "Search all Filters" textbox works correctly on the Raw Sequencing Data tab', async ({
page,
}) => {
await testSelectFiltersThroughSearchBar(page, HPRC_TABS.rawSequencingData);
expect(
await testSelectFiltersThroughSearchBar(page, HPRC_TABS.rawSequencingData)
).toBe(true);
});

test('Check that selecting the first filter through the "Search all Filters" textbox works correctly on the Assemblies tab', async ({
page,
}) => {
await testSelectFiltersThroughSearchBar(page, HPRC_TABS.assemblies);
expect(
await testSelectFiltersThroughSearchBar(page, HPRC_TABS.assemblies)
).toBe(true);
});

test('Check that selecting the first filter through the "Search all Filters" textbox works correctly on the Annotations tab', async ({
page,
}) => {
await testSelectFiltersThroughSearchBar(page, HPRC_TABS.annotations);
expect(
await testSelectFiltersThroughSearchBar(page, HPRC_TABS.annotations)
).toBe(true);
});

test('Check that selecting the first filter through the "Search all Filters" textbox works correctly on the Alignments tab', async ({
page,
}) => {
await testSelectFiltersThroughSearchBar(page, HPRC_TABS.alignments);
expect(
await testSelectFiltersThroughSearchBar(page, HPRC_TABS.alignments)
).toBe(true);
});

test("Expect at least one filter to exist on the Samples tab and for all filters to function", async ({
Expand All @@ -97,5 +105,7 @@ test("Expect filter counts to update for the first three filters on the Samples
test('Check that selecting the first filter through the "Search all Filters" textbox works correctly on the Samples tab', async ({
page,
}) => {
await testSelectFiltersThroughSearchBar(page, HPRC_TABS.samples);
expect(await testSelectFiltersThroughSearchBar(page, HPRC_TABS.samples)).toBe(
true
);
});
66 changes: 30 additions & 36 deletions e2e/testFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TEST_IDS } from "@databiosphere/findable-ui/lib/tests/testIds";
import { expect, Locator, Page } from "@playwright/test";
import { TabDescription } from "./testInterfaces";

Expand Down Expand Up @@ -302,39 +303,38 @@ export const getNamedFilterOptionLocator = (
});
};

interface FilterOptionNameAndLocator {
interface SearchAllFiltersOption {
count: number;
locator: Locator;
name: string;
}

const MAX_FILTER_OPTIONS_TO_CHECK = 10;

/**
* Gets the name of the filter option associated with a locator
* @param page - a Playwright Page object, on which a filter must be currently selected
* @returns the innerText of the first nonempty filter option as a promise
* Gets the first unselected "Search all filters" option with a nonempty term, along with its term and count.
* Unselected, so that clicking it adds a filter rather than removing a default one.
* @param page - a Playwright Page object, on which the "Search all filters" dropdown must be open
* @returns the locator, term and count of the first nonempty option as a promise
*/
const getFirstNonEmptyFilterOptionNameAndIndex = async (
const getFirstNonEmptySearchAllFiltersOption = async (
page: Page
): Promise<FilterOptionNameAndLocator> => {
let filterToSelect = "";
let filterOptionLocator = undefined;
let i = 0;
while (filterToSelect === "" && i < MAX_FILTER_OPTIONS_TO_CHECK) {
// Filter options display as "[text]\n[number]" , sometimes with extra whitespace, so we want the string before the newline
const filterOptionRegex = /^(.*)\n+(\d+)\s*$/;
filterOptionLocator = getNthFilterOptionLocator(page, i);
filterToSelect = ((await filterOptionLocator.innerText())
.trim()
.match(filterOptionRegex) ?? ["", ""])[1];
i += 1;
}
if (filterOptionLocator === undefined) {
throw new Error(
"No locator found within the maximum number of filter options"
);
): Promise<SearchAllFiltersOption> => {
const locator = page
.getByRole("option", { selected: false })
.filter({
has: page.getByTestId(TEST_IDS.FILTER_TERM).filter({ hasText: /\S/ }),
})
.first();
await expect(locator).toBeVisible();
const name = (
await locator.getByTestId(TEST_IDS.FILTER_TERM).innerText()
).trim();
const count = Number(
(await locator.getByTestId(TEST_IDS.FILTER_COUNT).innerText()).trim()
);
if (Number.isNaN(count)) {
throw new Error(`Search all filters option "${name}" has no numeric count`);
}
return { locator: filterOptionLocator, name: filterToSelect };
return { count, locator, name };
};

const FILTER_CSS_SELECTOR = "#sidebar-positioner";
Expand Down Expand Up @@ -370,22 +370,16 @@ export async function testSelectFiltersThroughSearchBar(
await expect(searchFiltersInputLocator).toBeVisible();
await searchFiltersInputLocator.click();
// Select the first filter with associated text
const firstFilterWithTextNameAndLocator =
await getFirstNonEmptyFilterOptionNameAndIndex(page);
const filterCount = getFilterNumberFromText(
await firstFilterWithTextNameAndLocator.locator.innerText()
);
await firstFilterWithTextNameAndLocator.locator.click();
const { count, locator, name } =
await getFirstNonEmptySearchAllFiltersOption(page);
await locator.click();
// Close the filter search dropdown
await page.keyboard.press("Escape");
const filterTagLocator = getFilterTagLocator(
page,
firstFilterWithTextNameAndLocator.name
);
const filterTagLocator = getFilterTagLocator(page, name);
// Check the filter tag is selected
await expect(filterTagLocator).toBeVisible();
// Check that the filter counts are equal to the number associated with the selected filter
const filterCountSuccess = await verifyFilterCount(page, filterCount);
const filterCountSuccess = await verifyFilterCount(page, count);
if (!filterCountSuccess) {
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"gen-schema": "poetry run ./catalog/schema/scripts/gen-schema.sh"
},
"dependencies": {
"@databiosphere/findable-ui": "^60.0.0",
"@databiosphere/findable-ui": "^63.0.0",
"@emotion/react": "^11.14.0",
"@emotion/server": "^11",
"@emotion/styled": "^11.14.1",
Expand All @@ -40,7 +40,7 @@
"@tanstack/react-virtual": "^3.13.13",
"copy-to-clipboard": "^3.3.3",
"gray-matter": "^4.0.3",
"ky": "^1.7.2",
"ky": "^1.10.0",
"next": "^16.4.5",
"next-mdx-remote": "^6",
"react": "^19.2.3",
Expand Down
29 changes: 11 additions & 18 deletions pages/[entityListType]/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AzulEntitiesStaticResponse } from "@databiosphere/findable-ui/lib/apis/azul/common/entities";
import { getEntityConfig } from "@databiosphere/findable-ui/lib/config/utils";
import { getEntityService } from "@databiosphere/findable-ui/lib/hooks/useEntityService";
import { EXPLORE_MODE } from "@databiosphere/findable-ui/lib/hooks/useExploreMode/types";
import { seedDatabase } from "@databiosphere/findable-ui/lib/utils/seedDatabase";
import type { ExploreViewProps } from "@databiosphere/findable-ui/lib/views/ExploreView/types";
import { config } from "app/config/config";
import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from "next";
import { ParsedUrlQuery } from "querystring";
Expand All @@ -13,22 +13,14 @@ interface PageUrl extends ParsedUrlQuery {
entityListType: string;
}

interface ListPageProps extends AzulEntitiesStaticResponse {
entityListType: string;
}

/**
* Explore view page.
* @param props - Explore view page props.
* @param props.entityListType - Entity list type.
* @param props - Explore view page props: the entity list type and its statically loaded entities, if any.
* @returns ExploreView component.
*/
const IndexPage = ({
entityListType,
...props
}: ListPageProps): JSX.Element => {
if (!entityListType) return <></>;
return <ExploreView entityListType={entityListType} {...props} />;
const IndexPage = (props: ExploreViewProps): JSX.Element => {
if (!props.entityListType) return <></>;
return <ExploreView {...props} />;
};

/**
Expand All @@ -54,17 +46,17 @@ export const getStaticPaths: GetStaticPaths = async () => {
* @param context - Object containing values related to the current context.
* @returns static props.
*/
export const getStaticProps: GetStaticProps<
AzulEntitiesStaticResponse
> = async (context: GetStaticPropsContext) => {
export const getStaticProps: GetStaticProps<ExploreViewProps> = async (
context: GetStaticPropsContext
) => {
const appConfig = config();
const { entityListType } = context.params as PageUrl;
const { entities } = appConfig;
const entityConfig = getEntityConfig(entities, entityListType);
const { exploreMode } = entityConfig;
const { fetchAllEntities } = getEntityService(entityConfig, undefined); // Determine the type of fetch, either from an API endpoint or a TSV.

const props: AzulEntitiesStaticResponse = { entityListType };
const props: ExploreViewProps = { entityListType };

// Seed database.
if (exploreMode === EXPLORE_MODE.CS_FETCH_CS_FILTERING) {
Expand All @@ -75,7 +67,8 @@ export const getStaticProps: GetStaticProps<
}

// Entities are client-side fetched from a local database seeded from a configured TSV.
props.data = await fetchAllEntities(entityListType, undefined);
// The explore view takes the entities alone, not the rest of the response.
props.data = (await fetchAllEntities(entityListType, undefined)).hits;

return {
props,
Expand Down
4 changes: 2 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "@databiosphere/findable-ui";
import { AzulEntitiesStaticResponse } from "@databiosphere/findable-ui/lib/apis/azul/common/entities";
import { Error } from "@databiosphere/findable-ui/lib/components/Error/error";
import { ErrorBoundary } from "@databiosphere/findable-ui/lib/components/ErrorBoundary/errorBoundary";
import { Head } from "@databiosphere/findable-ui/lib/components/Head/head";
Expand All @@ -20,7 +19,8 @@ import type { AppProps } from "next/app";
import type { JSX } from "react";
import { config } from "../app/config/config";

export interface PageProps extends AzulEntitiesStaticResponse {
export interface PageProps {
entityListType: string;
pageTitle?: string;
}

Expand Down
Loading