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
33 changes: 30 additions & 3 deletions pages/SearchResultsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ import { expect, Locator, Page } from '@playwright/test';
export class SearchResultsPage {
readonly page: Page;
readonly mainContent: Locator;
readonly resultLinks: Locator;
readonly noResultsMessage: Locator;

constructor(page: Page) {
this.page = page;
this.mainContent = page.locator('main, [role="main"], body').first();
}
this.page = page;
this.mainContent = page.locator('main, [role="main"], body').first();

this.resultLinks = page.locator(
'a[href*="/release/"], a[href*="/master/"], a[href*="/artist/"], a[href*="/label/"]'
);

this.noResultsMessage = page.getByText(
/no results|nothing found|did not match|try a different search/i
);
}

async expectSearchResultsPageLoaded(query: string): Promise<void> {
await expect(this.page).toHaveURL(/\/search(\?|\/|$)/);
Expand Down Expand Up @@ -35,4 +45,21 @@ export class SearchResultsPage {
releaseOrMasterResult.click(),
]);
}

async expectGracefulNoResultState(query: string): Promise<void> {
await expect(this.page).toHaveURL(/\/search(?:\?|\/|$)/);
await expect(this.mainContent).toContainText(query, { timeout: 10000 });

await expect(this.mainContent).not.toContainText(
/server error|something went wrong|application error|internal error/i
);

const resultCount = await this.resultLinks.count();
const noResultsMessageCount = await this.noResultsMessage.count();

expect(
resultCount === 0 || noResultsMessageCount > 0,
`Expected no result links or a no-results message for query: ${query}`
).toBeTruthy();
}
}
6 changes: 6 additions & 0 deletions test-data/negative-search-cases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"description": "unlikely search query",
"query": "zzzxxy-discogs-ui-no-results-qa-portfolio-2026"
}
]
33 changes: 33 additions & 0 deletions tests/search/negative-search.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test } from '@playwright/test';
import { HomePage } from '../../pages/HomePage';
import { SearchResultsPage } from '../../pages/SearchResultsPage';
import negativeSearchCases from '../../test-data/negative-search-cases.json';

type NegativeSearchCase = {
description: string;
query: string;
};

test.describe('Discogs negative search', () => {
for (const searchCase of negativeSearchCases as NegativeSearchCase[]) {
test(`@negative search handles ${searchCase.description} gracefully`, async ({
page,
}) => {
const homePage = new HomePage(page);
const searchResultsPage = new SearchResultsPage(page);

await test.step('Navigate to Discogs homepage', async () => {
await homePage.goto();
await homePage.expectPageLoaded();
});

await test.step(`Search for unlikely query: ${searchCase.query}`, async () => {
await homePage.searchFor(searchCase.query);
});

await test.step('Validate graceful no-result behavior', async () => {
await searchResultsPage.expectGracefulNoResultState(searchCase.query);
});
});
}
});
Loading