Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Update tests and snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Jan 3, 2023
1 parent e4ab853 commit 6c3ff7a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
22 changes: 12 additions & 10 deletions test/playwright/e2e/search-types-old.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {
changeContentType,
goToSearchTerm,
OLD_HEADER,
searchTypePath,
} from "~~/test/playwright/utils/navigation"
import { mockProviderApis } from "~~/test/playwright/utils/route"

import { searchPath } from "~/constants/media"

/**
* Using SSR:
* 1. Can open 'all content' search page, and see search results.
Expand Down Expand Up @@ -35,15 +36,15 @@ const allContentConfig = {
name: "All content",
url: "/search/?q=birds",
canLoadMore: true,
metaSourceCount: 7,
externalSourceCount: 7,
} as const

const imageConfig = {
id: "image",
name: "Images",
url: "/search/image?q=birds",
canLoadMore: true,
metaSourceCount: 7,
externalSourceCount: 7,
results: /Over 10,000 results/,
} as const

Expand All @@ -52,7 +53,7 @@ const audioConfig = {
name: "Audio",
url: "/search/audio?q=birds",
canLoadMore: true,
metaSourceCount: 3,
externalSourceCount: 3,
results: /764 results/,
} as const

Expand All @@ -71,14 +72,17 @@ async function checkLoadMore(page: Page, searchType: SearchTypeConfig) {
await expect(loadMoreSection).toContainText("Load more")
}
}
async function checkMetasearchForm(page: Page, searchType: SearchTypeConfig) {
async function checkExternalSourcesForm(
page: Page,
searchType: SearchTypeConfig
) {
const metaSearchForm = await page.locator(
'[data-testid="external-sources-form"]'
)
await expect(metaSearchForm).toHaveCount(1)

const sourceButtons = await page.locator(".external-sources a")
await expect(sourceButtons).toHaveCount(searchType.metaSourceCount)
await expect(sourceButtons).toHaveCount(searchType.externalSourceCount)
}

async function checkSearchMetadata(page: Page, searchType: SearchTypeConfig) {
Expand All @@ -90,18 +94,16 @@ async function checkSearchMetadata(page: Page, searchType: SearchTypeConfig) {
}

async function checkPageMeta(page: Page, searchType: SearchTypeConfig) {
const urlParam = searchTypePath(searchType.id)

const expectedTitle = `birds | Openverse`
const expectedURL = `/search/${urlParam}?q=birds`
const expectedURL = `${searchPath(searchType.id)}?q=birds`

await expect(page).toHaveTitle(expectedTitle)
await expect(page).toHaveURL(expectedURL)
}
async function checkSearchResult(page: Page, searchType: SearchTypeConfig) {
await checkSearchMetadata(page, searchType)
await checkLoadMore(page, searchType)
await checkMetasearchForm(page, searchType)
await checkExternalSourcesForm(page, searchType)
await checkPageMeta(page, searchType)
}

Expand Down
26 changes: 9 additions & 17 deletions test/playwright/e2e/search-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {
changeContentType,
enableNewHeader,
goToSearchTerm,
searchTypePath,
} from "~~/test/playwright/utils/navigation"
import { mockProviderApis } from "~~/test/playwright/utils/route"
import breakpoints from "~~/test/playwright/utils/breakpoints"

import { searchPath } from "~/constants/media"

/**
* Using SSR:
* 1. Can open 'all content' search page, and see search results.
Expand All @@ -32,15 +33,13 @@ const allContentConfig = {
name: "All content",
url: "/search/?q=birds",
canLoadMore: true,
metaSourceCount: 7,
} as const

const imageConfig = {
id: "image",
name: "Images",
url: "/search/image?q=birds",
canLoadMore: true,
metaSourceCount: 7,
results: /Over 10,000 results/,
} as const

Expand All @@ -49,7 +48,6 @@ const audioConfig = {
name: "Audio",
url: "/search/audio?q=birds",
canLoadMore: true,
metaSourceCount: 3,
results: /764 results/,
} as const

Expand All @@ -68,37 +66,31 @@ async function checkLoadMore(page: Page, searchType: SearchTypeConfig) {
await expect(loadMoreSection).toContainText("Load more")
}
}
async function checkMetasearchForm(page: Page, searchType: SearchTypeConfig) {
const metaSearchForm = await page.locator(
'[data-testid="external-sources-form"]'
)
await expect(metaSearchForm).toHaveCount(1)

const sourceButtons = await page.locator(".external-sources a")
await expect(sourceButtons).toHaveCount(searchType.metaSourceCount)
async function checkExternalSourcesForm(page: Page) {
await expect(
page.locator('[data-testid="external-sources-form"]')
).toBeVisible()
}

async function checkSearchMetadata(page: Page, searchType: SearchTypeConfig) {
if (searchType.canLoadMore) {
const searchResult = await page.locator('[data-testid="search-results"]')
const searchResult = page.locator('[data-testid="search-results"]')
await expect(searchResult).toBeVisible()
await expect(searchResult).not.toBeEmpty()
}
}

async function checkPageMeta(page: Page, searchType: SearchTypeConfig) {
const urlParam = searchTypePath(searchType.id)

const expectedTitle = `birds | Openverse`
const expectedURL = `/search/${urlParam}?q=birds`
const expectedURL = `${searchPath(searchType.id)}?q=birds`

await expect(page).toHaveTitle(expectedTitle)
await expect(page).toHaveURL(expectedURL)
}
async function checkSearchResult(page: Page, searchType: SearchTypeConfig) {
await checkSearchMetadata(page, searchType)
await checkLoadMore(page, searchType)
await checkMetasearchForm(page, searchType)
await checkExternalSourcesForm(page)
await checkPageMeta(page, searchType)
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6c3ff7a

Please sign in to comment.