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
Revert "Dr 3796 Refactor search filter tests"
  • Loading branch information
samanthaandrews authored Oct 11, 2025
commit 02fb86e19c62085d3dff45032f6bc5cb9714109e
34 changes: 20 additions & 14 deletions playwright/base.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { test as base, expect, Page, TestInfo } from "@playwright/test";
import { test as base } from "@playwright/test";
import { applyRouteFilters } from "./utils/routeFilters";

// export function that applies filters conditionally
export async function applyGlobalFilters(page: Page, testInfo: TestInfo) {
const shouldSkipRouting = testInfo.tags.includes("@no-global-filter");
// Create custom fixture
type RouteFilterFixtures = {
routeFilterFixture: void;
};

if (!shouldSkipRouting) {
await applyRouteFilters(page);
}
}
// Extend base test object with custom fixture
export const test = base.extend<RouteFilterFixtures>({
routeFilterFixture: [
async ({ page }, use, testInfo) => {
// Check if test has a '@no-global-filter' tag
const shouldSkipRouting = testInfo.tags.includes("@no-global-filter");

// apply route filters
base.beforeEach(async ({ page }, testInfo) => {
// This maintains the auto-filtering for simple tests
await applyGlobalFilters(page, testInfo);
if (!shouldSkipRouting) {
// If tag is not present, apply global route filters to the test
await applyRouteFilters(page);
}
await use();
},
{ auto: true },
],
});

export const test = base.extend({}); // Keep the base extend for custom test object
export { expect };
export { expect } from "@playwright/test";
73 changes: 26 additions & 47 deletions playwright/pages/search.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class SearchPage {
readonly publisherSelected: Locator;
readonly divisionFilter: Locator;
readonly divisionOption: Locator;
readonly divisionSelected: Locator;
readonly typeFilter: Locator;
readonly typeOption: Locator;
readonly typeSelected: Locator;
Expand All @@ -48,7 +47,7 @@ export default class SearchPage {
readonly hideFilters: Locator;
readonly applyFilterButton: Locator;
readonly clearFilterButton: Locator;
readonly clearNameFilterApplied: Locator;
readonly clearTopicFilterApplied: Locator;
readonly clearAllFilters: Locator;

// sort search results
Expand Down Expand Up @@ -91,70 +90,50 @@ export default class SearchPage {
this.refineHeading = this.page.getByRole("heading", {
name: "Refine your search",
});

this.topicFilter = this.page.getByRole("button", { name: "Topic" });
this.topicOption = this.page
.getByLabel("topic filter options")
.locator("#select-topic")
.getByText("Maps in education", { exact: true });
this.topicSelected = this.page
.getByRole("button", { name: "Select topic" })
.getByText("Topic: Maps in education");

.locator("#select-topic")
.getByText("Topic: Maps in education", { exact: true });
this.nameFilter = this.page.getByRole("button", { name: "Name" });
this.nameOption = this.page
.getByLabel("name filter options")
.locator("#select-name")
.getByText("Sheldonian Theatre", { exact: true });
this.nameSelected = this.page.getByText("Name: Sheldonian Theatre", {
exact: true,
});
this.nameSelected = this.page
.locator("#select-name")
.getByText("Name: Sheldonian Theatre", { exact: true });
this.collectionFilter = this.page.getByRole("button", {
name: "Collection",
});
this.collectionOption = this.page
.getByLabel("collection filter options")
.getByText("Portolan atlas");

// The selected collection-filter check below currently uses a fuzzy match
// The selected filter check below currently uses a fuzzy match
// because the collection UUID is appended to the
// collectionSelected display text, which is visible to users when
// collections have short titles. (DR-3838)

this.collectionSelected = this.page.getByText("Collection: Portolan atlas");
this.placeFilter = this.page.getByRole("button", { name: "Place" });
this.placeOption = this.page
.getByLabel("place filter options")
.locator("#select-place")
.getByText("England", { exact: true });
this.placeSelected = this.page.getByText("Place: England", { exact: true });
this.placeSelected = this.page
.locator("#select-place")
.getByText("Place: England", { exact: true });
this.genreFilter = this.page.getByRole("button", { name: "Genre" });
this.genreOption = this.page
.getByLabel("genre filter options")
.getByText("Maps", { exact: true });
this.genreSelected = this.page.getByText("Genre: Maps", { exact: true });
this.publisherFilter = this.page.getByRole("button", { name: "Publisher" });
this.publisherOption = this.page
.getByLabel("publisher filter options")
.locator("#select-publisher")
.getByText("Printed at the Theater,", { exact: true });
this.publisherSelected = this.page.getByText(
"Publisher: Printed at the Theater,",
{ exact: true }
);
this.publisherSelected = this.page
.locator("#select-publisher")
.getByText("Publisher: Printed at the Theater,", { exact: true });
this.divisionFilter = this.page.getByRole("button", { name: "Division" });
this.divisionOption = this.page
.getByLabel("division filter options")
.getByText("Lionel Pincus and Princess Firyal Map Division", {
exact: true,
});
this.divisionSelected = this.page.getByText(
"Division: Lionel Pincus and Princess Firyal Map Division",
{ exact: true }
);
this.typeFilter = this.page.getByRole("button", { name: "Type" });
this.typeOption = this.page
.getByLabel("type filter options")
.getByText("Cartographic", { exact: true });
this.typeSelected = this.page.getByText("Type: Cartographic", {
exact: true,
});
this.startYear = this.page.getByRole("textbox", { name: "Start year" });
this.endYear = this.page.getByRole("textbox", { name: "End year" });
this.applyDates = this.page.getByRole("button", { name: "Apply dates" });
Expand All @@ -181,8 +160,8 @@ export default class SearchPage {
name: "Clear filter",
exact: true,
});
this.clearNameFilterApplied = this.page.getByRole("button", {
name: "Sheldonian Theatre, click to remove filter",
this.clearTopicFilterApplied = this.page.getByRole("button", {
name: "Maps in education, click to remove filter",
});
this.clearAllFilters = this.page
.locator("#search-filter-tags")
Expand Down Expand Up @@ -237,16 +216,16 @@ export default class SearchPage {
}

async filterSearchResults(): Promise<void> {
// filters a drop-down (Name) in the first row
await expect(this.nameFilter).toBeVisible();
await this.nameFilter.click();
await expect(this.nameOption).toBeVisible();
await this.nameOption.click();
// filters a drop-down in the first row
await expect(this.topicFilter).toBeVisible();
await this.topicFilter.click();
await expect(this.topicOption).toBeVisible();
await this.topicOption.click();
await expect(this.applyFilterButton).toBeVisible();
await this.applyFilterButton.click();
await expect(this.nameSelected).toBeVisible();
await expect(this.topicSelected).toBeVisible();

// filters a drop-down (Publisher) in the second row
// filters a drop-down in the second row
if (await this.showFilters.isVisible()) {
await expect(this.showFilters).toBeVisible();
await this.showFilters.click();
Expand Down
99 changes: 0 additions & 99 deletions playwright/tests/search-filters-modal.spec.ts

This file was deleted.

65 changes: 0 additions & 65 deletions playwright/tests/search-items-result.spec.ts

This file was deleted.

Loading