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

Commit

Permalink
Make e2e tests pass (#667)
Browse files Browse the repository at this point in the history
* Make e2e tests pass

* Fix lint error (copy of #666)
  • Loading branch information
obulat authored Jan 21, 2022
1 parent 1f90e2e commit 097dc4d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 65 deletions.
49 changes: 10 additions & 39 deletions test/e2e/content-types.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test.beforeEach(async ({ context }) => {
const contentTypes = [
{
id: 'all',
name: 'All',
name: 'All content',
url: '/search/?q=cat',
supported: true,
sources: 6,
Expand All @@ -57,29 +57,13 @@ const contentTypes = [
supported: false,
sources: 5,
},
{
id: 'video',
name: 'Video',
url: '/search/video/?q=cat',
supported: false,
sources: 4,
},
]

for (const [i, contentType] of contentTypes.entries()) {
test(`Can open ${contentType.name} search page on SSR`, async ({ page }) => {
await page.goto(contentType.url)

// Meta data
if (contentType.supported) {
const searchMetaData = await page.locator('[data-testid="search-meta"]')

await expect(searchMetaData).toContainText(
contentType.id === 'all' ? 'image results' : `${contentType.id} results`
)
await expect(searchMetaData).toContainText('Are these results relevant')
await expect(searchMetaData).toContainText('Safer Browsing')

const searchResult = await page.locator('[data-testid="search-results"]')
await expect(searchResult).toBeVisible()
await expect(searchResult).not.toBeEmpty()
Expand All @@ -102,34 +86,21 @@ for (const [i, contentType] of contentTypes.entries()) {
const sourceButtons = await page.locator('.meta-search a')
await expect(sourceButtons).toHaveCount(contentType.sources)
})
test.skip(`Can open ${contentType.name} page client-side`, async ({
page,
}) => {
const pageToOpen = (i + 1) % contentTypes.length
await page.goto(contentTypes[pageToOpen].url)

await page.click(`[role="tab"]:has-text("${contentType.name}")`)
test(`Can open ${contentType.name} page client-side`, async ({ page }) => {
const pageToOpen = contentTypes[(i + 1) % contentTypes.length]
await page.goto(pageToOpen.url)
await page.click(`[aria-label="${pageToOpen.name}"]`)

await Promise.all([
page.waitForNavigation(/*{ url: '/search/audio?q=cat' }*/),
page.click(`button[role="radio"]:has-text("${contentType.name}")`),
])
const urlParam = contentType.id === 'all' ? '' : contentType.id
const expectedURL = `/search/${urlParam}?q=cat`
await expect(page).toHaveURL(expectedURL)

// Selected content page
const currentTabLabel = await page
.locator('[aria-current="page"]')
.textContent()

expect(currentTabLabel.trim()).toEqual(contentType.name)

// Meta data
if (contentType.supported) {
const searchMetaData = await page.locator('[data-testid="search-meta"]')

await expect(searchMetaData).toContainText(
contentType.id === 'all' ? 'image results' : `${contentType.id} results`
)
await expect(searchMetaData).toContainText('Are these results relevant')
await expect(searchMetaData).toContainText('Safer Browsing')

const searchResult = await page.locator('[data-testid="search-results"]')
await expect(searchResult).toBeVisible()
await expect(searchResult).not.toBeEmpty()
Expand Down
27 changes: 19 additions & 8 deletions test/e2e/homepage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,40 @@ test.beforeEach(async ({ context }) => {
)
})

test('can change type and search for audio/modification from homepage', async ({
page,
}) => {
test('can change type and search for audio from homepage', async ({ page }) => {
// Go to http://localhost:8444/
await page.goto('/')
await page.click('text=Audio')
await page.check('text=Modify or adapt >> input[name="licenseType"]')
await page.click('[aria-label="All content"]')
await page.click('button[role="radio"]:has-text("Audio")')

const searchInput = page.locator('main input[type="search"]')
await searchInput.type('cat')
await page.click('button:has-text("Search")')
const expectedUrl = '/search/audio?q=cat&license_type=modification'
await page.click('[aria-label="Search"]')
const expectedUrl = '/search/audio?q=cat'
await expect(page).toHaveURL(expectedUrl)
})

test('can search for all results from homepage', async ({ page }) => {
await page.goto('/')

const searchInput = page.locator('main input[type="search"]')
await searchInput.type('cat')
await page.click('[aria-label="Search"]')

await expect(page).toHaveURL('search/?q=cat')

await expect(page.locator('img')).toHaveCount(20)
})
test('can search for images from homepage, and then load more results', async ({
page,
}) => {
await page.goto('/')
await page.click('[aria-label="All content"]')
await page.click('button[role="radio"]:has-text("Images")')

const searchInput = page.locator('main input[type="search"]')
await searchInput.type('cat')
await page.click('button:has-text("Search")')
await page.click('[aria-label="Search"]')

await expect(page).toHaveURL('search/image?q=cat')

Expand Down
23 changes: 6 additions & 17 deletions test/e2e/search-query-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,39 +38,27 @@ test('q query parameter is set as the search term', async ({ page }) => {

const searchInput = page.locator('main input[type="search"]')
await searchInput.type('cat')
await page.click('button:has-text("Search")')
await page.click('[aria-label="Search"]')

await expect(page.locator('header input[type="search"]')).toHaveValue('cat')
await expect(page).toHaveURL('search/image?q=cat')
await expect(page).toHaveURL('search/?q=cat')
})

test('selecting `audio` on homepage, you can search for audio', async ({
page,
}) => {
await page.goto('/')
await page.click('[aria-label="All content"]')
await page.click('button[role="radio"]:has-text("Audio")')

await page.type('main input[type="search"]', 'cat')
await page.click('button:has-text("Audio")')
await page.click('button:has-text("Search")')
await page.click('[aria-label="Search"]')

await expect(page.locator('header input[type="search"]')).toHaveValue('cat')

await expect(page).toHaveURL('search/audio?q=cat')
})

test('selecting license type filter on homepage applies filters', async ({
page,
}) => {
await page.goto('/')

await page.type('main input[type="search"]', 'cat')
await page.click('label:has-text("Use commercially")')
await page.click('button:has-text("Search")')

await expect(page).toHaveURL('search/image?q=cat&license_type=commercial')
await expect(page.locator('header input[type="search"]')).toHaveValue('cat')
})

test.skip('url filter parameters not used by current mediaType are discarded', async ({
page,
}) => {
Expand Down Expand Up @@ -104,6 +92,7 @@ test('can search for a different term', async ({ page }) => {
await page.keyboard.press('Enter')
await expect(page).toHaveURL('/search/image?q=dog')
})

test('search for a different term keeps query parameters', async ({ page }) => {
await page.goto('/search/image?q=cat&license=by&extension=jpg')
await page.fill('header input[type="search"]', 'dog')
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/search-query-server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test('url query to filter, image tab, several filters for one filter type select
await expect(svg).toBeChecked()
})

test('url mature query is set, and can be unchecked using the Safer Browsing popup', async ({
test.skip('url mature query is set, and can be unchecked using the Safer Browsing popup', async ({
page,
}) => {
await page.goto('/search/image?q=cat&mature=true')
Expand Down

0 comments on commit 097dc4d

Please sign in to comment.