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

Update Playwright tests utilities to work both when the new_header flag is enabled and when it's disabled #1914

Merged
merged 1 commit into from
Oct 19, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<VSearchBarButton
:icon-path="sourceIcon"
:aria-label="
areFiltersSelected
? $t('header.aria.menu-notification')
: $t('header.aria.menu')
appliedFilterCount
? $tc('header.content-settings-button.with-count', appliedFilterCount)
: $t('header.content-settings-button.simple')
"
aria-haspopup="dialog"
:aria-expanded="isPressed"
Expand All @@ -13,7 +13,7 @@
>
<template #notification>
<span
v-if="areFiltersSelected"
v-if="appliedFilterCount"
class="absolute top-[-2px] right-[-2px] h-[8px] w-[8px] rounded bg-pink"
/>
</template>
Expand All @@ -32,9 +32,9 @@ export default {
type: Boolean,
default: false,
},
areFiltersSelected: {
type: Boolean,
default: false,
appliedFilterCount: {
type: Number,
default: 0,
},
},
setup() {
Expand Down
10 changes: 5 additions & 5 deletions src/components/VHeader/VHeaderMobile/VContentSettingsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<template #trigger="{ visible, a11Props }">
<VContentSettingsButton
:is-pressed="visible"
:are-filters-selected="areFiltersSelected"
:applied-filter-count="appliedFilterCount"
v-bind="a11Props"
/>
</template>
Expand All @@ -32,7 +32,7 @@
class="self-center ms-auto hover:bg-dark-charcoal hover:text-white"
size="search-medium"
:icon-props="{ iconPath: closeIcon }"
:aria-label="$t('browse-page.aria.close')"
:aria-label="$t('modal.aria-close')"
@click="closeModal"
/>
</template>
Expand Down Expand Up @@ -120,11 +120,10 @@ export default defineComponent({
const isClearButtonDisabled = computed(
() => !searchStore.isAnyFilterApplied
)
const appliedFilterCount = computed(() => searchStore.appliedFilterCount)
const clearFiltersLabel = computed(() =>
searchStore.isAnyFilterApplied
? i18n.t('filter-list.clear-numbered', {
number: searchStore.appliedFilterCount,
})
? i18n.tc('filter-list.clear-numbered', appliedFilterCount.value)
: i18n.t('filter-list.clear')
)

Expand All @@ -145,6 +144,7 @@ export default defineComponent({
changeSelectedTab,

areFiltersSelected,
appliedFilterCount,
showClearFiltersButton,
isClearButtonDisabled,
clearFiltersLabel,
Expand Down
8 changes: 6 additions & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"aria": {
"primary": "primary",
"menu": "menu",
"menu-notification": "Some filters are applied",
"search": "search",
"sr-search": "search button"
},
Expand All @@ -60,7 +59,11 @@
"with-count": "{count} Filter|{count} Filters"
},
"see-results": "See results",
"back-button": "Go back"
"back-button": "Go back",
"content-settings-button": {
"simple": "Menu",
"with-count": "Menu. {count} filter applied|Menu. {count} filters applied"
}
},
"navigation": {
"about": "About",
Expand Down Expand Up @@ -628,6 +631,7 @@
"interpunct": "•",
"modal": {
"close": "Close",
"aria-close": "Close the modal",
"close-named": "Close {name}"
},
"error-images": {
Expand Down
2 changes: 1 addition & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
Normally when you build Openverse, you download the updated information about locales and translation files to `src/locales` folder. To prevent too many requests during CI, we save the locale files that are necessary to run the app during Playwright tests.

1. `scripts/valid-locales.json` contains a list of valid locales with properties including their translation status (the percentage of strings that are translated).
2. `es.json` is the `es` locale file used for search navigation tests (`../playwright/e2e/search-navigation.spec.ts`).
2. `es.json` is the `es` locale file used for search navigation tests (`../playwright/e2e/search-navigation-old.spec.ts`).
3. `ru.json` is the `ru` locale file used for testing the translation banner because the current translated percentage is ~40%, which is below the banner threshold of 90%.
4. `ar.json` is the machine-translated `ar` locale file used for RTL testing.
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { test, expect, Page } from '@playwright/test'
import { expect, Page, test } from '@playwright/test'

import {
assertCheckboxStatus,
openFilters,
changeContentType,
goToSearchTerm,
OLD_HEADER,
openFilters,
} from '~~/test/playwright/utils/navigation'

import { mockProviderApis } from '~~/test/playwright/utils/route'

import {
supportedSearchTypes,
ALL_MEDIA,
IMAGE,
AUDIO,
IMAGE,
supportedSearchTypes,
} from '~/constants/media'

test.describe.configure({ mode: 'parallel' })
Expand Down Expand Up @@ -48,7 +49,7 @@ for (const searchType of supportedSearchTypes) {
}) => {
await goToSearchTerm(page, 'cat', { searchType })

await openFilters(page)
await openFilters(page, OLD_HEADER)

await assertCheckboxCount(page, 'total', FILTER_COUNTS[searchType])
})
Expand All @@ -58,7 +59,7 @@ test('initial filters are applied based on the url', async ({ page }) => {
await page.goto(
'/search/?q=cat&license_type=commercial&license=cc0&searchBy=creator'
)
await openFilters(page)
await openFilters(page, OLD_HEADER)
const expectedFilters = ['cc0', 'commercial', 'creator']

for (const checkbox of expectedFilters) {
Expand All @@ -72,13 +73,13 @@ test('common filters are retained when media type changes from all media to sing
await page.goto(
'/search/?q=cat&license_type=commercial&license=cc0&searchBy=creator'
)
await openFilters(page)
await openFilters(page, OLD_HEADER)
const expectedFilters = ['cc0', 'commercial', 'creator']

for (const checkbox of expectedFilters) {
await assertCheckboxStatus(page, checkbox)
}
await changeContentType(page, 'Images')
await changeContentType(page, 'Images', OLD_HEADER)

await expect(page).toHaveURL(
'/search/image?q=cat&license_type=commercial&license=cc0&searchBy=creator'
Expand All @@ -94,13 +95,13 @@ test('common filters are retained when media type changes from single type to al
await page.goto(
'/search/image?q=cat&license_type=commercial&license=cc0&searchBy=creator'
)
await openFilters(page)
await openFilters(page, OLD_HEADER)

for (const checkbox of ['cc0', 'commercial', 'creator']) {
await assertCheckboxStatus(page, checkbox)
}

await changeContentType(page, 'All content')
await changeContentType(page, 'All content', OLD_HEADER)

for (const checkbox of ['cc0', 'commercial', 'creator']) {
await assertCheckboxStatus(page, checkbox)
Expand All @@ -114,7 +115,7 @@ test('selecting some filters can disable dependent filters', async ({
page,
}) => {
await page.goto('/search/audio?q=cat&license_type=commercial')
await openFilters(page)
await openFilters(page, OLD_HEADER)

// by-nc is special because we normally test for fuzzy match, and by-nc matches 3 labels.
const byNc = page.locator('input[value="by-nc"]')
Expand Down Expand Up @@ -144,12 +145,12 @@ test('selecting some filters can disable dependent filters', async ({
*/
test('filters are updated when media type changes', async ({ page }) => {
await page.goto('/search/image?q=cat&aspect_ratio=tall&license=cc0')
await openFilters(page)
await openFilters(page, OLD_HEADER)

await assertCheckboxStatus(page, 'tall')
await assertCheckboxStatus(page, 'cc0')

await changeContentType(page, 'Audio')
await changeContentType(page, 'Audio', OLD_HEADER)

// Only CC0 checkbox is checked, and the filter button label is '1 Filter'
await assertCheckboxStatus(page, 'cc0')
Expand All @@ -164,7 +165,7 @@ test('new media request is sent when a filter is selected', async ({
page,
}) => {
await page.goto('/search/image?q=cat')
await openFilters(page)
await openFilters(page, OLD_HEADER)

await assertCheckboxStatus(page, 'cc0', '', 'unchecked')

Expand All @@ -190,7 +191,7 @@ for (const [searchType, source] of [
await page.goto(
`/search/${searchType}?q=birds&source=${source.toLowerCase()}`
)
await openFilters(page)
await openFilters(page, OLD_HEADER)

await assertCheckboxStatus(page, source, '', 'checked')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { test, expect } from '@playwright/test'
import {
closeMobileMenu,
goToSearchTerm,
OLD_HEADER,
openContentTypes,
openFilters,
openMobileMenu,
} from '~~/test/playwright/utils/navigation'

const mockUaString =
Expand All @@ -20,27 +21,27 @@ test.describe.configure({ mode: 'parallel' })
test('Can open filters menu on mobile at least twice', async ({ page }) => {
await page.goto('/search/?q=cat')

await openFilters(page)
await openFilters(page, OLD_HEADER)
await expect(page.locator(`input[type="checkbox"]`)).toHaveCount(11, {
timeout: 100,
})
await closeMobileMenu(page)
await closeMobileMenu(page, OLD_HEADER)
await expect(page.locator(`input[type="checkbox"]`)).toHaveCount(0, {
timeout: 100,
})

await openFilters(page)
await openFilters(page, OLD_HEADER)
await expect(page.locator(`input[type="checkbox"]`)).toHaveCount(11, {
timeout: 100,
})
})

test('Can open mobile menu at least twice', async ({ page }) => {
await goToSearchTerm(page, 'cat')
await openMobileMenu(page)
await openContentTypes(page, OLD_HEADER)
await expect(page.locator('button', { hasText: 'Close' })).toBeVisible()
await closeMobileMenu(page)
await closeMobileMenu(page, OLD_HEADER)
await expect(page.locator('button', { hasText: 'Close' })).not.toBeVisible()
await openMobileMenu(page)
await openContentTypes(page, OLD_HEADER)
await expect(page.locator('button', { hasText: 'Close' })).toBeVisible()
})
7 changes: 7 additions & 0 deletions test/playwright/e2e/recent-searches.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ test('shows recent searches in reverse chronological order', async ({
test('clicking takes user to that search', async ({ page }) => {
await executeSearches(page)
expect(page.url()).toContain('?q=galah')
// Click on the input to open the Recent searches
await page.locator('input[type="search"]').click()
await page
.locator(`[aria-label="Recent searches"]`)
.locator('[id="option-1"]')
Expand All @@ -45,6 +47,9 @@ test('clicking takes user to that search', async ({ page }) => {
})

test('recent searches shows message when blank', async ({ page }) => {
// Click on the input to open the Recent searches
await page.locator('input[type="search"]').click()

const recentSearchesText = await page
.locator('[data-testid="recent-searches"]')
.textContent()
Expand All @@ -53,6 +58,8 @@ test('recent searches shows message when blank', async ({ page }) => {

test('clicking Clear clears the recent searches', async ({ page }) => {
await executeSearches(page)
// Click on the input to open the Recent searches
await page.locator('input[type="search"]').click()
await page.locator('[aria-label="Clear recent searches"]').click()
const recentSearchesText = await page
.locator('[data-testid="recent-searches"]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test'

import {
goToSearchTerm,
OLD_HEADER,
openFilters,
} from '~~/test/playwright/utils/navigation'
import { mockProviderApis } from '~~/test/playwright/utils/route'
Expand All @@ -18,7 +19,7 @@ test.describe('search history navigation', () => {
}) => {
await goToSearchTerm(page, 'galah')
// Open filter sidebar
await openFilters(page)
await openFilters(page, OLD_HEADER)

// Apply a filter
await page.click('#modification')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect, test } from '@playwright/test'
import {
changeContentType,
goToSearchTerm,
OLD_HEADER,
} from '~~/test/playwright/utils/navigation'
import { mockProviderApis } from '~~/test/playwright/utils/route'

Expand Down Expand Up @@ -51,7 +52,7 @@ test('url filter parameters not used by current mediaType are discarded', async
query: 'category=photograph',
})

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

Expand All @@ -63,7 +64,7 @@ test('url filter types not used by current mediaType are discarded', async ({
query: 'aspect_ratio=tall',
})

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
assertCheckboxStatus,
currentContentType,
goToSearchTerm,
OLD_HEADER,
openFilters,
} from '~~/test/playwright/utils/navigation'
import { mockProviderApis } from '~~/test/playwright/utils/route'
Expand Down Expand Up @@ -44,7 +45,7 @@ test('url path /search/ is used to select `all` search tab', async ({
}) => {
await page.goto('/search/?q=cat')

const contentType = await currentContentType(page)
const contentType = await currentContentType(page, OLD_HEADER)
expect(contentType?.trim()).toEqual('All content')
})

Expand All @@ -53,7 +54,7 @@ test('url path /search/audio is used to select `audio` search tab', async ({
}) => {
await goToSearchTerm(page, 'cat', { searchType: AUDIO })

const contentType = await currentContentType(page)
const contentType = await currentContentType(page, OLD_HEADER)
expect(contentType?.trim()).toEqual('Audio')
})

Expand All @@ -64,7 +65,7 @@ test('url query to filter, all tab, one parameter per filter type', async ({
query: 'license=cc0&license_type=commercial&searchBy=creator',
})

await openFilters(page)
await openFilters(page, OLD_HEADER)
for (const checkbox of ['cc0', 'commercial', 'creator']) {
await assertCheckboxStatus(page, checkbox)
}
Expand All @@ -77,7 +78,7 @@ test('url query to filter, image tab, several filters for one filter type select
searchType: IMAGE,
query: 'searchBy=creator&extension=jpg,png,gif,svg',
})
await openFilters(page)
await openFilters(page, OLD_HEADER)
const checkboxes = ['jpeg', 'png', 'gif', 'svg']
for (const checkbox of checkboxes) {
const forValue = checkbox === 'jpeg' ? 'jpg' : checkbox
Expand Down
Loading