Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Improve e2e tests (#840)
Olga Bulat26af972f90f3
diff --git a/src/components/VContentReport/VContentReportForm.vue b/src/components/VContentReport/VContentReportForm.vueindex 3e381a93e..d57438ee1 100644--- a/src/components/VContentReport/VContentReportForm.vue+++ b/src/components/VContentReport/VContentReportForm.vue@@ -110,6 +110,7 @@import { computed, defineComponent, ref } from '@nuxtjs/composition-api'import VButton from '~/components/VButton.vue'+import VIcon from '~/components/VIcon/VIcon.vue'import VRadio from '~/components/VRadio/VRadio.vue'import VDmcaNotice from '~/components/VContentReport/VDmcaNotice.vue'import VReportDescForm from '~/components/VContentReport/VReportDescForm.vue'@@ -124,6 +125,7 @@ export default defineComponent({name: 'VContentReportForm',components: {VButton,+ VIcon,VRadio,VDmcaNotice,VReportDescForm,diff --git a/src/components/VContentSwitcher/VContentSwitcherPopover.vue b/src/components/VContentSwitcher/VContentSwitcherPopover.vueindex ef512153b..f6f611e87 100644--- a/src/components/VContentSwitcher/VContentSwitcherPopover.vue+++ b/src/components/VContentSwitcher/VContentSwitcherPopover.vue@@ -9,9 +9,11 @@<VContentSwitcherButton:a11y-props="a11yProps":active-item="activeItem"+ aria-controls="content-switcher-popover"/></template><VContentTypes+ id="content-switcher-popover"size="medium":active-item="activeItem"@select="selectItem"diff --git a/src/components/VContentSwitcher/VMobileMenuModal.vue b/src/components/VContentSwitcher/VMobileMenuModal.vueindex 7d7c821b3..265c802b6 100644--- a/src/components/VContentSwitcher/VMobileMenuModal.vue+++ b/src/components/VContentSwitcher/VMobileMenuModal.vue@@ -4,6 +4,7 @@<VContentSwitcherButton:a11y-props="triggerA11yProps":active-item="activeItem"+ aria-controls="content-switcher-modal"/></div><VMobileModalContent@@ -13,7 +14,11 @@:aria-label="$t('header.filter-button.simple')":initial-focus-element="initialFocusElement">- <nav class="p-6" aria-labelledby="content-switcher-heading">+ <nav+ id="content-switcher-modal"+ class="p-6"+ aria-labelledby="content-switcher-heading"+ ><VContentTypesref="contentTypesNode"size="small"diff --git a/test/e2e/content-types.spec.js b/test/e2e/content-types.spec.jsindex e623952c1..e47e6ad2d 100644--- a/test/e2e/content-types.spec.js+++ b/test/e2e/content-types.spec.js@@ -1,38 +1,24 @@const { test, expect } = require('@playwright/test')+const { mockAllSearch, changeContentType } = require('./utils')/*** Using SSR:- * 1. Can open 'all' tab, and see Meta, image grid and Meta search form.- * 2. Can open 'image' tab, and see Meta, image grid and Meta search form.- * 3. Can open 'audio' tab, and see Meta, audio grid and Meta search form.- * 4. Can open 'video' tab, and see Meta, and Meta search form.+ * 1. Can open 'all' content type page, and see Meta, image grid and Meta search form.+ * 2. Can open 'image' content type page, and see Meta, image grid and Meta search form.+ * 3. Can open 'audio' content type page, and see Meta, audio grid and Meta search form.+ * 4. Can open 'video' content type page, and see Meta, and Meta search form.** On client side:- * 1. Can open 'all' tab, and see Meta, image grid and Meta search form; can load more images.- * 2. Can open 'image' tab, and see Meta, image grid and Meta search form; can load more images.- * 3. Can open 'audio' page, and see Meta, audio grid and Meta search form; can not (currently) load more audios.- * 4. Can open 'video' page, and see Meta, and Meta search form; can not see load more button.+ * 1. Can open 'all' content type page, and see Meta, image grid and Meta search form; can load more images.+ * 2. Can open 'image' content type page, and see Meta, image grid and Meta search form; can load more images.+ * 3. Can open 'audio' content type page, and see Meta, audio grid and Meta search form; can not (currently) load more audios.+ * 4. Can open 'video' content type page, and see Meta, and Meta search form; can not see load more button.*/test.beforeEach(async ({ context }) => {- // Block any image or audio (jamendo.com) requests for each test in this file.- await context.route(/\.(png|jpeg|jpg|svg)$/, (route) => route.abort())+ // Block any audio (jamendo.com) requests for each test in this file.await context.route('**.jamendo.com**', (route) => route.abort())-- // Replace all the thumbnail requests with a single sample image- await context.route(- 'https://api.openverse.engineering/v1/thumbs/**',- (route) => route.fulfill({ path: 'test/e2e/resources/sample_image.jpg' })- )- // Serve mock data on all image search requests- await context.route(- 'https://api.openverse.engineering/v1/images/**',- (route) =>- route.fulfill({- headers: { 'Access-Control-Allow-Origin': '*' },- path: 'test/e2e/resources/mock_data.json',- })- )+ await mockAllSearch(context)})const contentTypes = [@@ -91,9 +77,8 @@ for (const contentType of contentTypes) {const pageToOpen =contentType.id === 'all' ? contentTypes[1] : contentTypes[0]await page.goto(pageToOpen.url)- await page.click(`[aria-label="${pageToOpen.name}"]`)+ await changeContentType(page, contentType.name)- await page.click(`button[role="radio"]:has-text("${contentType.name}")`)const urlParam = contentType.id === 'all' ? '' : contentType.idconst expectedURL = `/search/${urlParam}?q=cat`await expect(page).toHaveURL(expectedURL)diff --git a/test/e2e/filters.spec.js b/test/e2e/filters.spec.jsindex 6910a4815..3c8dc0d03 100644--- a/test/e2e/filters.spec.js+++ b/test/e2e/filters.spec.js@@ -1,83 +1,75 @@const { test, expect } = require('@playwright/test')--const openFilters = async (page) => {- const filterButtonSelector =- '[aria-controls="filter-sidebar"], [aria-controls="filter-modal"]'- const isPressed = async () =>- await page.getAttribute(filterButtonSelector, 'aria-pressed')- if ((await isPressed()) !== 'true') {- await page.click(filterButtonSelector)- expect(await isPressed()).toEqual('true')- }-}+const {+ assertCheckboxCheckedStatus,+ openFilters,+ mockAllSearch,+ changeContentType,+} = require('./utils')test.beforeEach(async ({ context }) => {- // Block any image or audio (jamendo.com) requests for each test in this file.- await context.route(/\.(png|jpeg|jpg|svg)$/, (route) => route.abort())+ // Block any audio (jamendo.com) requests for each test in this file.await context.route(/.+jamendo.com.+/, (route) => route.abort())- // Replace all the thumbnail requests with a single sample image- await context.route(- 'https://api.openverse.engineering/v1/thumbs/**',- (route) => route.fulfill({ path: 'test/e2e/resources/sample_image.jpg' })- )- // Serve mock data on all image search requests- await context.route(- 'https://api.openverse.engineering/v1/images/?***',- (route) => route.fulfill({ path: 'test/e2e/resources/mock_data.json' })- )+ await mockAllSearch(context)})-// todo(obulat): remove this test if we do not have filter tags-test.skip('can unset filters using filter tags', async ({ page }) => {- // Serve mock data on all image search requests- await page.route('https://api.openverse.engineering/v1/images/?**', (route) =>- route.fulfill({ path: 'test/e2e/resources/mock_data.json' })+test('common filters are retained when media type changes from all media to single type', async ({+ page,+}) => {+ await page.goto(+ '/search/?q=cat&license_type=commercial&license=cc0&searchBy=creator')- await page.goto('/search/image?q=cat&license=cc0')-- const cc0Tag = page.locator('[aria-label="Remove CC0 filter"]')await openFilters(page)- expect(await page.getAttribute('[aria-label="1 Filter"]', 'aria-label')).toBe(- '1 Filter'++ for (let checkbox of ['cc0', 'commercial', 'creator']) {+ await assertCheckboxCheckedStatus(page, checkbox)+ }+ await changeContentType(page, 'Images')++ await expect(page).toHaveURL(+ '/search/image?q=cat&license_type=commercial&license=cc0&searchBy=creator')- const cc0Checkbox = page.locator('label:has-text("CC0")')-- await expect(cc0Checkbox).toBeChecked()- await expect(cc0Tag).toHaveCount(1)- page.on('requestfinished', (request) => {- const url = request.url()- // Only check the URL for an image search query `?`, not thumbs or related requests- const baseUrl = 'https://api.openverse.engineering/v1/images/?'- if (url.startsWith(baseUrl)) {- expect(url).toEqual(baseUrl + 'q=cat')- }- })- await cc0Tag.click()- await expect(page).toHaveURL('/search/image?q=cat')- await expect(cc0Checkbox).not.toBeChecked()- await expect(page.locator('[aria-label="Remove CC0 filter"]')).toHaveCount(0)+ for (let checkbox of ['cc0', 'commercial', 'creator']) {+ await assertCheckboxCheckedStatus(page, checkbox)+ }})-test.skip('filters are updated when media type changes', async ({ page }) => {- // Serve mock data on all image search requests- await page.route('https://api.openverse.engineering/v1/images?**', (route) =>- route.fulfill({ path: 'test/e2e/resources/mock_data.json' })+test('common filters are retained when media type changes from single type to all media', async ({+ page,+}) => {+ await page.goto(+ '/search/audio?q=cat&license_type=commercial&license=cc0&searchBy=creator')- await page.goto('/search/image?q=cat&aspect_ratio=tall')await openFilters(page)- const tallCheckbox = page.locator('label:has-text("Tall")')+ for (let checkbox of ['cc0', 'commercial', 'creator']) {+ await assertCheckboxCheckedStatus(page, checkbox)+ }++ await changeContentType(page, 'All content')++ await expect(page).toHaveURL(+ '/search/?q=cat&license_type=commercial&license=cc0&searchBy=creator'+ )++ for (let checkbox of ['cc0', 'commercial', 'creator']) {+ await assertCheckboxCheckedStatus(page, checkbox)+ }+})+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 expect(tallCheckbox).toBeChecked()+ await assertCheckboxCheckedStatus(page, 'Tall')+ await assertCheckboxCheckedStatus(page, 'cc0')- await page.click('[aria-label="Images"]')- await page.click(`a:has-text("Audio")`)+ await changeContentType(page, 'Audio')- await expect(page).toHaveURL('/search/audio?q=cat')+ await expect(page).toHaveURL('/search/audio?q=cat&license=cc0')- await expect(tallCheckbox).toHaveCount(0)+ await expect(page.locator('label:has-text("Tall")')).toHaveCount(0)+ await assertCheckboxCheckedStatus(page, 'cc0')})test('new media request is sent when a filter is selected', async ({@@ -90,17 +82,19 @@ test('new media request is sent when a filter is selected', async ({'https://api.openverse.engineering/v1/images/?**',(route) => {apiRequest = route.request().url()- route.fulfill({ path: 'test/e2e/resources/mock_data.json' })+ route.fulfill({+ path: 'test/e2e/resources/mock_image_data.json',+ headers: { 'Access-Control-Allow-Origin': '*' },+ })})await page.goto('/search/image?q=cat')await openFilters(page)- const cc0Checkbox = page.locator('label:has-text("CC0")')- await expect(cc0Checkbox).not.toBeChecked()- await cc0Checkbox.click()+ await assertCheckboxCheckedStatus(page, 'cc0', false)+ await page.click('label:has-text("CC0")')- await expect(cc0Checkbox).toBeChecked()+ await assertCheckboxCheckedStatus(page, 'cc0', true)await expect(apiRequest).toEqual('https://api.openverse.engineering/v1/images/?q=cat&license=cc0')diff --git a/test/e2e/homepage.spec.js b/test/e2e/homepage.spec.jsindex ecb2f48e5..d123110d6 100644--- a/test/e2e/homepage.spec.js+++ b/test/e2e/homepage.spec.js@@ -14,7 +14,7 @@ test.beforeEach(async ({ context }) => {'https://api.openverse.engineering/v1/images/**',(route) =>route.fulfill({- path: 'test/e2e/resources/mock_data.json',+ path: 'test/e2e/resources/mock_image_data.json',headers: { 'Access-Control-Allow-Origin': '*' },}))diff --git a/test/e2e/resources/mock_audio_data.json b/test/e2e/resources/mock_audio_data.jsonnew file mode 100644index 000000000..23b882578--- /dev/null+++ b/test/e2e/resources/mock_audio_data.json@@ -0,0 +1,599 @@+{+ "result_count": 1073,+ "page_count": 54,+ "page_size": 20,+ "page": 1,+ "results": [+ {+ "id": "1bbebf0f-7b91-431b-af79-58a82c97bf78",+ "title": "paper sounds",+ "foreign_landing_url": "https://freesound.org/people/swordofkings128/sounds/398026",+ "creator": "swordofkings128",+ "creator_url": "https://freesound.org/people/swordofkings128",+ "url": "https://freesound.org/data/previews/398/398026_7586736-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "turning-pages" },+ { "name": "paper" },+ { "name": "fumbling" },+ { "name": "sony-ic-recorder" }+ ],+ "fields_matched": ["description", "title"],+ "duration": 14090,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/1bbebf0f-7b91-431b-af79-58a82c97bf78/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/1bbebf0f-7b91-431b-af79-58a82c97bf78/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/1bbebf0f-7b91-431b-af79-58a82c97bf78/",+ "related_url": "http://api.openverse.engineering/v1/audio/1bbebf0f-7b91-431b-af79-58a82c97bf78/related/"+ },+ {+ "id": "5f04ff20-a616-442a-a0c6-6706def7f6d7",+ "title": "Various Guitar Case sounds",+ "foreign_landing_url": "https://freesound.org/people/reconsider59/sounds/397995",+ "creator": "reconsider59",+ "creator_url": "https://freesound.org/people/reconsider59",+ "url": "https://freesound.org/data/previews/397/397995_5388550-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "guitar" },+ { "name": "case" },+ { "name": "clasp" },+ { "name": "snap" }+ ],+ "fields_matched": ["description", "title"],+ "duration": 56988,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/5f04ff20-a616-442a-a0c6-6706def7f6d7/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/5f04ff20-a616-442a-a0c6-6706def7f6d7/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/5f04ff20-a616-442a-a0c6-6706def7f6d7/",+ "related_url": "http://api.openverse.engineering/v1/audio/5f04ff20-a616-442a-a0c6-6706def7f6d7/related/"+ },+ {+ "id": "622138b1-ef25-4bbd-9365-c713ebd3b965",+ "title": "GUI Sound Effects_073.mp3",+ "foreign_landing_url": "https://freesound.org/people/jalastram/sounds/397626",+ "creator": "jalastram",+ "creator_url": "https://freesound.org/people/jalastram",+ "url": "https://freesound.org/data/previews/397/397626_3905081-hq.mp3",+ "license": "by",+ "license_version": "3.0",+ "license_url": "https://creativecommons.org/licenses/by/3.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "Sound" },+ { "name": "SFX" },+ { "name": "Menu" },+ { "name": "GUI" },+ { "name": "Beep" },+ { "name": "Game" },+ { "name": "Design" },+ { "name": "Effects" },+ { "name": "Interface" }+ ],+ "fields_matched": ["description", "tags.name", "title"],+ "duration": 1924,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/622138b1-ef25-4bbd-9365-c713ebd3b965/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/622138b1-ef25-4bbd-9365-c713ebd3b965/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/622138b1-ef25-4bbd-9365-c713ebd3b965/",+ "related_url": "http://api.openverse.engineering/v1/audio/622138b1-ef25-4bbd-9365-c713ebd3b965/related/"+ },+ {+ "id": "201a7b33-0d4b-4094-8da3-7ed111e292e6",+ "title": "Bus in India - Interior Sound",+ "foreign_landing_url": "https://freesound.org/people/florianreichelt/sounds/434849",+ "creator": "florianreichelt",+ "creator_url": "https://freesound.org/people/florianreichelt",+ "url": "https://freesound.org/data/previews/434/434849_6253486-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "house" },+ { "name": "modern" },+ { "name": "sign" },+ { "name": "design" },+ { "name": "home" },+ { "name": "technology" },+ { "name": "transport" },+ { "name": "speed" },+ { "name": "travel" },+ { "name": "isolated" },+ { "name": "lamp" },+ { "name": "music" },+ { "name": "communication" },+ { "name": "interior" },+ { "name": "white" },+ { "name": "transportation" },+ { "name": "business" },+ { "name": "bus" },+ { "name": "symbol" },+ { "name": "vehicle" },+ { "name": "illustration" },+ { "name": "phone" },+ { "name": "icon" },+ { "name": "sound" },+ { "name": "room" },+ { "name": "light" },+ { "name": "vector" },+ { "name": "car" },+ { "name": "audio" },+ { "name": "road" }+ ],+ "fields_matched": ["description", "tags.name", "title"],+ "duration": 117139,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/201a7b33-0d4b-4094-8da3-7ed111e292e6/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/201a7b33-0d4b-4094-8da3-7ed111e292e6/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/201a7b33-0d4b-4094-8da3-7ed111e292e6/",+ "related_url": "http://api.openverse.engineering/v1/audio/201a7b33-0d4b-4094-8da3-7ed111e292e6/related/"+ },+ {+ "id": "346482ff-1ce9-4a18-a925-b75f2cc4cfa3",+ "title": "Spray Sounds",+ "foreign_landing_url": "https://freesound.org/people/TheFlakesMaster/sounds/400661",+ "creator": "TheFlakesMaster",+ "creator_url": "https://freesound.org/people/TheFlakesMaster",+ "url": "https://freesound.org/data/previews/400/400661_7682129-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [{ "name": "spray" }, { "name": "freshener" }, { "name": "air" }],+ "fields_matched": ["description", "title"],+ "duration": 9125,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/346482ff-1ce9-4a18-a925-b75f2cc4cfa3/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/346482ff-1ce9-4a18-a925-b75f2cc4cfa3/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/346482ff-1ce9-4a18-a925-b75f2cc4cfa3/",+ "related_url": "http://api.openverse.engineering/v1/audio/346482ff-1ce9-4a18-a925-b75f2cc4cfa3/related/"+ },+ {+ "id": "7931897b-45c5-4836-9588-179f64f3d2f3",+ "title": "sound recorder grabbed.flac",+ "foreign_landing_url": "https://freesound.org/people/kyles/sounds/455831",+ "creator": "kyles",+ "creator_url": "https://freesound.org/people/kyles",+ "url": "https://freesound.org/data/previews/455/455831_612689-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "sound" },+ { "name": "recorder" },+ { "name": "handling" },+ { "name": "grab" }+ ],+ "fields_matched": ["description", "tags.name", "title"],+ "duration": 2583,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/7931897b-45c5-4836-9588-179f64f3d2f3/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/7931897b-45c5-4836-9588-179f64f3d2f3/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/7931897b-45c5-4836-9588-179f64f3d2f3/",+ "related_url": "http://api.openverse.engineering/v1/audio/7931897b-45c5-4836-9588-179f64f3d2f3/related/"+ },+ {+ "id": "01e7063f-82de-4904-9b65-20004d8647b6",+ "title": "sound 1.wav",+ "foreign_landing_url": "https://freesound.org/people/sabbyt2/sounds/400166",+ "creator": "sabbyt2",+ "creator_url": "https://freesound.org/people/sabbyt2",+ "url": "https://freesound.org/data/previews/400/400166_7283708-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "impact" },+ { "name": "stone" },+ { "name": "molcajete" }+ ],+ "fields_matched": ["title"],+ "duration": 650,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/01e7063f-82de-4904-9b65-20004d8647b6/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/01e7063f-82de-4904-9b65-20004d8647b6/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/01e7063f-82de-4904-9b65-20004d8647b6/",+ "related_url": "http://api.openverse.engineering/v1/audio/01e7063f-82de-4904-9b65-20004d8647b6/related/"+ },+ {+ "id": "0fe56605-0105-40c0-a6d7-19b788816ade",+ "title": "Fuckin' Sound",+ "foreign_landing_url": "https://www.jamendo.com/track/1094",+ "creator": "Religionnaire",+ "creator_url": "https://www.jamendo.com/artist/159/religionnaire",+ "url": "https://mp3d.jamendo.com/download/track/1094/mp32",+ "license": "by",+ "license_version": "2.0",+ "license_url": "https://creativecommons.org/licenses/by/2.0/",+ "provider": "jamendo",+ "source": "jamendo",+ "category": "music",+ "tags": [+ { "name": "vocal" },+ { "name": "male" },+ { "name": "speed_medium" }+ ],+ "fields_matched": ["title"],+ "genres": ["pop", "electronic"],+ "duration": 271000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/0fe56605-0105-40c0-a6d7-19b788816ade/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/0fe56605-0105-40c0-a6d7-19b788816ade/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/0fe56605-0105-40c0-a6d7-19b788816ade/",+ "related_url": "http://api.openverse.engineering/v1/audio/0fe56605-0105-40c0-a6d7-19b788816ade/related/"+ },+ {+ "id": "8b656ad2-cfab-490b-9592-45975d5db125",+ "title": "hotel large open hallway with heavy wind against roof overhead ceiling beams crack and little hall sounds echo2 Gaza 2016.wav",+ "foreign_landing_url": "https://freesound.org/people/kyles/sounds/406306",+ "creator": "kyles",+ "creator_url": "https://freesound.org/people/kyles",+ "url": "https://freesound.org/data/previews/406/406306_612689-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "heavy" },+ { "name": "hallway" },+ { "name": "hotel" },+ { "name": "roof" },+ { "name": "wind" }+ ],+ "fields_matched": ["description", "title"],+ "duration": 224182,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/8b656ad2-cfab-490b-9592-45975d5db125/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/8b656ad2-cfab-490b-9592-45975d5db125/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/8b656ad2-cfab-490b-9592-45975d5db125/",+ "related_url": "http://api.openverse.engineering/v1/audio/8b656ad2-cfab-490b-9592-45975d5db125/related/"+ },+ {+ "id": "a6d58309-6b4e-426c-b6db-5810827669c9",+ "title": "sound scape in york.mp3",+ "foreign_landing_url": "https://freesound.org/people/klavo1985/sounds/404012",+ "creator": "klavo1985",+ "creator_url": "https://freesound.org/people/klavo1985",+ "url": "https://freesound.org/data/previews/404/404012_4701691-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "town" },+ { "name": "city" },+ { "name": "noise" },+ { "name": "field-recording" },+ { "name": "people" },+ { "name": "cars" },+ { "name": "recording" },+ { "name": "street" },+ { "name": "traffic" },+ { "name": "ambience" },+ { "name": "soundscape" }+ ],+ "fields_matched": ["title"],+ "duration": 875749,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/a6d58309-6b4e-426c-b6db-5810827669c9/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/a6d58309-6b4e-426c-b6db-5810827669c9/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/a6d58309-6b4e-426c-b6db-5810827669c9/",+ "related_url": "http://api.openverse.engineering/v1/audio/a6d58309-6b4e-426c-b6db-5810827669c9/related/"+ },+ {+ "id": "2db76ebe-d504-46a3-b760-d4a15dfaca1e",+ "title": "CLUB STRIP OF SAMPLES I MADE BY KRIS USING DRIVEN SNARE ON FREE SOUND ON SIMPLER A.L.mp3",+ "foreign_landing_url": "https://freesound.org/people/klavo1985/sounds/400592",+ "creator": "klavo1985",+ "creator_url": "https://freesound.org/people/klavo1985",+ "url": "https://freesound.org/data/previews/400/400592_4701691-hq.mp3",+ "license": "by",+ "license_version": "3.0",+ "license_url": "https://creativecommons.org/licenses/by/3.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "club" },+ { "name": "trance" },+ { "name": "dance" },+ { "name": "techno" },+ { "name": "rave" },+ { "name": "hard-techno" }+ ],+ "fields_matched": ["title"],+ "duration": 14029,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/2db76ebe-d504-46a3-b760-d4a15dfaca1e/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/2db76ebe-d504-46a3-b760-d4a15dfaca1e/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/2db76ebe-d504-46a3-b760-d4a15dfaca1e/",+ "related_url": "http://api.openverse.engineering/v1/audio/2db76ebe-d504-46a3-b760-d4a15dfaca1e/related/"+ },+ {+ "id": "5335e35d-bfa4-4ba9-b73a-d381361bb237",+ "title": "Dub this sound",+ "foreign_landing_url": "https://www.jamendo.com/track/10937",+ "creator": "Mr Haze",+ "creator_url": "https://www.jamendo.com/artist/1558/mr.haze",+ "url": "https://mp3d.jamendo.com/download/track/10937/mp32",+ "license": "by-nc-nd",+ "license_version": "2.5",+ "license_url": "https://creativecommons.org/licenses/by-nc-nd/2.5/",+ "provider": "jamendo",+ "source": "jamendo",+ "category": "music",+ "tags": [+ { "name": "vocal" },+ { "name": "male" },+ { "name": "speed_medium" }+ ],+ "fields_matched": ["title"],+ "duration": 282000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/5335e35d-bfa4-4ba9-b73a-d381361bb237/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/5335e35d-bfa4-4ba9-b73a-d381361bb237/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/5335e35d-bfa4-4ba9-b73a-d381361bb237/",+ "related_url": "http://api.openverse.engineering/v1/audio/5335e35d-bfa4-4ba9-b73a-d381361bb237/related/"+ },+ {+ "id": "1ebfbf2a-e63d-4b8b-9629-1b7eeb866bad",+ "title": "Reggae Sound Party Drums Dub Style",+ "foreign_landing_url": "https://www.jamendo.com/track/7059",+ "creator": "KEPAY",+ "creator_url": "https://www.jamendo.com/artist/1037/kepay",+ "url": "https://mp3d.jamendo.com/download/track/7059/mp32",+ "license": "by-nc-nd",+ "license_version": "2.5",+ "license_url": "https://creativecommons.org/licenses/by-nc-nd/2.5/",+ "provider": "jamendo",+ "source": "jamendo",+ "category": "music",+ "tags": [+ { "name": "vocal" },+ { "name": "male" },+ { "name": "speed_medium" }+ ],+ "fields_matched": ["title"],+ "duration": 123000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/1ebfbf2a-e63d-4b8b-9629-1b7eeb866bad/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/1ebfbf2a-e63d-4b8b-9629-1b7eeb866bad/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/1ebfbf2a-e63d-4b8b-9629-1b7eeb866bad/",+ "related_url": "http://api.openverse.engineering/v1/audio/1ebfbf2a-e63d-4b8b-9629-1b7eeb866bad/related/"+ },+ {+ "id": "176706fd-91ab-4ef4-ae62-46ed0351af28",+ "title": "Teufelsberg ambient sounds 2 - including fabric flapping.wav",+ "foreign_landing_url": "https://freesound.org/people/dbspin/sounds/396674",+ "creator": "dbspin",+ "creator_url": "https://freesound.org/people/dbspin",+ "url": "https://freesound.org/data/previews/396/396674_255403-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "building" },+ { "name": "abandoned" },+ { "name": "wind" }+ ],+ "fields_matched": ["title"],+ "duration": 258741,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/176706fd-91ab-4ef4-ae62-46ed0351af28/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/176706fd-91ab-4ef4-ae62-46ed0351af28/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/176706fd-91ab-4ef4-ae62-46ed0351af28/",+ "related_url": "http://api.openverse.engineering/v1/audio/176706fd-91ab-4ef4-ae62-46ed0351af28/related/"+ },+ {+ "id": "b86e69a3-e7f4-444e-963b-d600e2d38e0a",+ "title": "Sci-Fi Sound Effect",+ "foreign_landing_url": "https://freesound.org/people/harrietniamh/sounds/400100",+ "creator": "harrietniamh",+ "creator_url": "https://freesound.org/people/harrietniamh",+ "url": "https://freesound.org/data/previews/400/400100_4061049-hq.mp3",+ "license": "by",+ "license_version": "3.0",+ "license_url": "https://creativecommons.org/licenses/by/3.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "atmosphere" },+ { "name": "sci-fi" },+ { "name": "science-fiction" },+ { "name": "artificial" },+ { "name": "digital" },+ { "name": "soundscape" }+ ],+ "fields_matched": ["description", "title"],+ "duration": 19821,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/b86e69a3-e7f4-444e-963b-d600e2d38e0a/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/b86e69a3-e7f4-444e-963b-d600e2d38e0a/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/b86e69a3-e7f4-444e-963b-d600e2d38e0a/",+ "related_url": "http://api.openverse.engineering/v1/audio/b86e69a3-e7f4-444e-963b-d600e2d38e0a/related/"+ },+ {+ "id": "c3132b55-efaf-4a87-81b3-29b533fb63ae",+ "title": "Dub this sound (dub)",+ "foreign_landing_url": "https://www.jamendo.com/track/10938",+ "creator": "Mr Haze",+ "creator_url": "https://www.jamendo.com/artist/1558/mr.haze",+ "url": "https://mp3d.jamendo.com/download/track/10938/mp32",+ "license": "by-nc-nd",+ "license_version": "2.5",+ "license_url": "https://creativecommons.org/licenses/by-nc-nd/2.5/",+ "provider": "jamendo",+ "source": "jamendo",+ "category": "music",+ "tags": [{ "name": "instrumental" }, { "name": "speed_medium" }],+ "fields_matched": ["title"],+ "duration": 264000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/c3132b55-efaf-4a87-81b3-29b533fb63ae/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/c3132b55-efaf-4a87-81b3-29b533fb63ae/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/c3132b55-efaf-4a87-81b3-29b533fb63ae/",+ "related_url": "http://api.openverse.engineering/v1/audio/c3132b55-efaf-4a87-81b3-29b533fb63ae/related/"+ },+ {+ "id": "4765ac85-c6d8-47db-9aa1-b4a20def0a32",+ "title": "Dolby 5.1 Surround Sound Test 2",+ "foreign_landing_url": "https://freesound.org/people/Guardian2433/sounds/403344",+ "creator": "Guardian2433",+ "creator_url": "https://freesound.org/people/Guardian2433",+ "url": "https://freesound.org/data/previews/403/403344_1027116-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "recording" },+ { "name": "tests" },+ { "name": "audio" },+ { "name": "dual-stereo" },+ { "name": "demo" },+ { "name": "demonstrations" },+ { "name": "1" },+ { "name": "5" },+ { "name": "test" },+ { "name": "demonstration" },+ { "name": "mixdown" }+ ],+ "fields_matched": ["description", "title"],+ "duration": 379368,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/4765ac85-c6d8-47db-9aa1-b4a20def0a32/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/4765ac85-c6d8-47db-9aa1-b4a20def0a32/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/4765ac85-c6d8-47db-9aa1-b4a20def0a32/",+ "related_url": "http://api.openverse.engineering/v1/audio/4765ac85-c6d8-47db-9aa1-b4a20def0a32/related/"+ },+ {+ "id": "e00cf153-bf71-4641-b95e-91c7a0bb6091",+ "title": "34th St Sound Installation Subway Take 2",+ "foreign_landing_url": "https://freesound.org/people/sheriff/sounds/456061",+ "creator": "sheriff",+ "creator_url": "https://freesound.org/people/sheriff",+ "url": "https://freesound.org/data/previews/456/456061_38089-hq.mp3",+ "license": "by",+ "license_version": "3.0",+ "license_url": "https://creativecommons.org/licenses/by/3.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "city" },+ { "name": "atmosphere" },+ { "name": "noise" },+ { "name": "installation" },+ { "name": "field-recording" },+ { "name": "nyc" },+ { "name": "ambient" },+ { "name": "new" },+ { "name": "york" },+ { "name": "street" },+ { "name": "34th" },+ { "name": "trains" },+ { "name": "ambience" },+ { "name": "art" },+ { "name": "soundscape" },+ { "name": "subway" }+ ],+ "fields_matched": ["description", "title"],+ "duration": 109481,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/e00cf153-bf71-4641-b95e-91c7a0bb6091/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/e00cf153-bf71-4641-b95e-91c7a0bb6091/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/e00cf153-bf71-4641-b95e-91c7a0bb6091/",+ "related_url": "http://api.openverse.engineering/v1/audio/e00cf153-bf71-4641-b95e-91c7a0bb6091/related/"+ },+ {+ "id": "13adbec9-8933-43fa-94ab-d62c9ce8cb84",+ "title": "Walking Sounds 1.wav",+ "foreign_landing_url": "https://freesound.org/people/JohnBelardi/sounds/401570",+ "creator": "JohnBelardi",+ "creator_url": "https://freesound.org/people/JohnBelardi",+ "url": "https://freesound.org/data/previews/401/401570_7714957-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "loyola-high-school" },+ { "name": "noise" },+ { "name": "field-recording" },+ { "name": "atmosphere" },+ { "name": "traffic" },+ { "name": "los-angeles" },+ { "name": "airplane" }+ ],+ "fields_matched": ["description", "title"],+ "duration": 60000,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/13adbec9-8933-43fa-94ab-d62c9ce8cb84/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/13adbec9-8933-43fa-94ab-d62c9ce8cb84/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/13adbec9-8933-43fa-94ab-d62c9ce8cb84/",+ "related_url": "http://api.openverse.engineering/v1/audio/13adbec9-8933-43fa-94ab-d62c9ce8cb84/related/"+ },+ {+ "id": "8c0c8dfd-f34e-4562-8d44-fa00177ba851",+ "title": "Abstract Sound part 1.",+ "foreign_landing_url": "https://freesound.org/people/PappaBert/sounds/405153",+ "creator": "PappaBert",+ "creator_url": "https://freesound.org/people/PappaBert",+ "url": "https://freesound.org/data/previews/405/405153_7663691-hq.mp3",+ "license": "cc0",+ "license_version": "1.0",+ "license_url": "https://creativecommons.org/publicdomain/zero/1.0/",+ "provider": "freesound",+ "source": "freesound",+ "category": "sound",+ "tags": [+ { "name": "jangle" },+ { "name": "clank" },+ { "name": "fiel-recording" },+ { "name": "machine" },+ { "name": "strange" },+ { "name": "mechanical" },+ { "name": "rale" },+ { "name": "soundscape" }+ ],+ "fields_matched": ["title"],+ "duration": 6423,+ "bit_rate": 128000,+ "thumbnail": "http://api.openverse.engineering/v1/audio/8c0c8dfd-f34e-4562-8d44-fa00177ba851/thumb/",+ "waveform": "http://api.openverse.engineering/v1/audio/8c0c8dfd-f34e-4562-8d44-fa00177ba851/waveform/",+ "detail_url": "http://api.openverse.engineering/v1/audio/8c0c8dfd-f34e-4562-8d44-fa00177ba851/",+ "related_url": "http://api.openverse.engineering/v1/audio/8c0c8dfd-f34e-4562-8d44-fa00177ba851/related/"+ }+ ]+}diff --git a/test/e2e/resources/mock_data.json b/test/e2e/resources/mock_image_data.jsonsimilarity index 100%rename from test/e2e/resources/mock_data.jsonrename to test/e2e/resources/mock_image_data.jsondiff --git a/test/e2e/search-query-client.spec.js b/test/e2e/search-query-client.spec.jsindex 9addf9c87..ce0d376d9 100644--- a/test/e2e/search-query-client.spec.js+++ b/test/e2e/search-query-client.spec.js@@ -1,4 +1,5 @@const { test, expect } = require('@playwright/test')+const { mockAllSearch, changeContentType } = require('./utils')/*** When navigating to the search page on the client side:@@ -13,24 +14,10 @@ const { test, expect } = require('@playwright/test')*/test.beforeEach(async ({ context }) => {- // Block any image or audio (jamendo.com) requests for each test in this file.- await context.route(/\.(png|jpeg|jpg|svg)$/, (route) => route.abort())+ // Block any audio (jamendo.com) requests for each test in this file.await context.route('**.jamendo.com**', (route) => route.abort())- // Replace all the thumbnail requests with a single sample image- await context.route(- 'https://api.openverse.engineering/v1/thumbs/**',- (route) => route.fulfill({ path: 'test/e2e/resources/sample_image.jpg' })- )- // Serve mock data on all image search requests- await context.route(- 'https://api.openverse.engineering/v1/images/**',- (route) =>- route.fulfill({- path: 'test/e2e/resources/mock_data.json',- headers: { 'Access-Control-Allow-Origin': '*' },- })- )+ await mockAllSearch(context)})test('q query parameter is set as the search term', async ({ page }) => {@@ -59,30 +46,21 @@ test('selecting `audio` on homepage, you can search for audio', async ({await expect(page).toHaveURL('search/audio?q=cat')})-test.skip('url filter parameters not used by current mediaType are discarded', async ({+test('url filter parameters not used by current mediaType are discarded', async ({page,}) => {- // TODO(obulat): Discard unused filter parameters for mediaType- // Some filter types have different possible values for different media types.- // For example, image has 'photograph' category, but audio doesn't (but it has- // 'music', 'sound'). On switching the media type when clicking on another- // search tab, such filters should be reset, and the query should be updated.await page.goto('/search/image?q=cat&categories=photograph')- await page.click('[role="tab"]:has-text("Audio")')+ await changeContentType(page, 'Audio')await expect(page).toHaveURL('/search/audio?q=cat')})-test.skip('url filter types not used by current mediaType are discarded', async ({+test('url filter types not used by current mediaType are discarded', async ({page,}) => {- // TODO(obulat): Discard unused filter types for mediaType- // Some filter types only apply to one media type. On switching the media type- // when clicking on another search tab, such filters should be reset,- // and the query should be updated.await page.goto('/search/image?q=cat&aspect_ratio=tall')- await page.click('[role="tab"]:has-text("Audio")')+ await changeContentType(page, 'Audio')await expect(page).toHaveURL('/search/audio?q=cat')})diff --git a/test/e2e/search-query-server.spec.js b/test/e2e/search-query-server.spec.jsindex b712b4920..e1cceb624 100644--- a/test/e2e/search-query-server.spec.js+++ b/test/e2e/search-query-server.spec.js@@ -1,47 +1,23 @@const { test, expect } = require('@playwright/test')+const { mockAllSearch, openFilters } = require('./utils')+const { currentContentType, assertCheckboxCheckedStatus } = require('./utils')/*** URL is correctly converted into search state:* 1. `q` parameter is set as the search input value- * 2. /search/<path>?query - path is used to choose the search tab+ * 2. /search/<path>?query - path is used to choose the content type* 3. query parameters are used to set the filter data:- * 3a. One of each values for `all` tab+ * 3a. One of each values for `all` content* 3b. Several query values - several filter checkboxes* 3c. Mature filter* 3d. Query parameters that are not used for current media type are discarded* All of these tests test server-generated search page, not the one generated on the client*/-const openFilters = async (page) => {- const filterButtonSelector =- '[aria-controls="filter-sidebar"], [aria-controls="filter-modal"]'- const isPressed = async () =>- await page.getAttribute(filterButtonSelector, 'aria-pressed')- if ((await isPressed()) !== 'true') {- await page.click(filterButtonSelector)- expect(await isPressed()).toEqual('true')- }-}-test.beforeEach(async ({ context }) => {// Block any image or audio (jamendo.com) requests for each test in this file.- await context.route(/\.(png|jpeg|jpg|svg)$/, (route) => route.abort())await context.route('**.jamendo.com**', (route) => route.abort())-- // Replace all the thumbnail requests with a single sample image- await context.route(- 'https://api.openverse.engineering/v1/thumbs/**',- (route) => route.fulfill({ path: 'test/e2e/resources/sample_image.jpg' })- )- // Serve mock data on all image search requests- await context.route(- 'https://api.openverse.engineering/v1/images/**',- (route) =>- route.fulfill({- path: 'test/e2e/resources/mock_data.json',- headers: { 'Access-Control-Allow-Origin': '*' },- })- )+ await mockAllSearch(context)})test('q query parameter is set as the search term', async ({ page }) => {@@ -55,27 +31,23 @@ test('q query parameter is set as the search term', async ({ page }) => {// await expect(searchInput).toBeFocused()})-test.skip('url path /search/ is used to select `all` search tab', async ({+test('url path /search/ is used to select `all` search tab', async ({page,}) => {await page.goto('/search/?q=cat')- const activeTabLabel = await page- .locator('[role="tab"][aria-selected="true"]')- .textContent()- expect(activeTabLabel.trim()).toEqual('All')+ const contentType = await currentContentType(page)+ expect(contentType.trim()).toEqual('All content')})-test.skip('url path /search/audio is used to select `audio` search tab', async ({+test('url path /search/audio is used to select `audio` search tab', async ({page,}) => {const audioSearchUrl = '/search/audio?q=cat'await page.goto(audioSearchUrl)- const activeTabLabel = await page- .locator('[role="tab"][aria-selected="true"]')- .textContent()- expect(activeTabLabel.trim()).toEqual('Audio')+ const contentType = await currentContentType(page)+ expect(contentType.trim()).toEqual('Audio')})test('url query to filter, all tab, one parameter per filter type', async ({@@ -86,14 +58,9 @@ test('url query to filter, all tab, one parameter per filter type', async ({)await openFilters(page)- const cc0Checkbox = await page.locator('label:has-text("CC0")')- await expect(cc0Checkbox).toBeChecked()-- const commercial = await page.locator('label:text-matches("commercial", "i")')- await expect(commercial).toBeChecked()-- const searchByCreator = await page.locator('label:has-text("Creator")')- await expect(searchByCreator).toBeChecked()+ await assertCheckboxCheckedStatus(page, 'cc0')+ await assertCheckboxCheckedStatus(page, 'commercial')+ await assertCheckboxCheckedStatus(page, 'creator')})test('url query to filter, image tab, several filters for one filter type selected', async ({@@ -103,18 +70,10 @@ test('url query to filter, image tab, several filters for one filter type select'/search/image?q=cat&searchBy=creator&extension=jpg,png,gif,svg')await openFilters(page)-- const jpeg = page.locator('label:text-matches("jp(e*)g", "i")')- await expect(jpeg).toBeChecked()-- const png = page.locator('label:text-matches("png", "i")')- await expect(png).toBeChecked()-- const gif = page.locator('label:text-matches("gif", "i")')- await expect(gif).toBeChecked()-- const svg = page.locator('label:text-matches("svgs", "i")')- await expect(svg).toBeChecked()+ const checkboxes = ['jpeg', 'png', 'gif', 'svgs']+ for (let checkbox of checkboxes) {+ await assertCheckboxCheckedStatus(page, checkbox)+ }})test.skip('url mature query is set, and can be unchecked using the Safer Browsing popup', async ({diff --git a/test/e2e/search.spec.js b/test/e2e/search.spec.jsindex 6cbdbef36..920cf2ad8 100644--- a/test/e2e/search.spec.js+++ b/test/e2e/search.spec.js@@ -7,17 +7,12 @@* On error: shows error message*/const { expect, test } = require('@playwright/test')+const { mockAllSearch } = require('./utils')test.beforeEach(async ({ context }) => {- // Block any image or audio (jamendo.com) requests for each test in this file.- await context.route(/\.(png|jpeg|jpg|svg)$/, (route) => route.abort())+ // Block any audio (jamendo.com) requests for each test in this file.await context.route('**.jamendo.com**', (route) => route.abort())-- // Replace all the thumbnail requests with a single sample image- await context.route(- 'https://api.openverse.engineering/v1/thumbs/**',- (route) => route.fulfill({ path: 'test/e2e/resources/sample_image.jpg' })- )+ await mockAllSearch(context)})test.skip('shows search result metadata', async ({ page }) => {diff --git a/test/e2e/utils.js b/test/e2e/utils.jsnew file mode 100644index 000000000..3a6e85650--- /dev/null+++ b/test/e2e/utils.js@@ -0,0 +1,102 @@+const { expect } = require('@playwright/test')++const openFilters = async (page) => {+ const filterButtonSelector =+ '[aria-controls="filter-sidebar"], [aria-controls="filter-modal"]'+ const isPressed = async () =>+ await page.getAttribute(filterButtonSelector, 'aria-pressed')+ if ((await isPressed()) !== 'true') {+ await page.click(filterButtonSelector)+ expect(await isPressed()).toEqual('true')+ }+}++const assertCheckboxCheckedStatus = async (page, label, checked = true) => {+ const checkbox = page.locator(`label:has-text("${label}")`)+ if (checked) {+ await expect(checkbox).toBeChecked()+ } else {+ await expect(checkbox).not.toBeChecked()+ }+}++/**+ * Replace all the thumbnail requests with a single sample image+ */+const mockThumbnails = async (context) => {+ await context.route(+ 'https://api.openverse.engineering/v1/thumbs/**',+ (route) =>+ route.fulfill({+ path: 'test/e2e/resources/sample_image.jpg',+ headers: { 'Access-Control-Allow-Origin': '*' },+ })+ )+}+/**+ * Replace all the image search requests with mock data+ */+const mockImageSearch = async (context) => {+ // Serve mock data on all image search requests+ await context.route(+ 'https://api.openverse.engineering/v1/images/?***',+ (route) =>+ route.fulfill({+ path: 'test/e2e/resources/mock_image_data.json',+ headers: { 'Access-Control-Allow-Origin': '*' },+ })+ )+}+/**+ * Replace all the image search requests with mock data+ */+const mockAudioSearch = async (context) => {+ // Serve mock data on all image search requests+ await context.route(+ 'https://api.openverse.engineering/v1/audio/?***',+ (route) =>+ route.fulfill({+ path: 'test/e2e/resources/mock_audio_data.json',+ headers: { 'Access-Control-Allow-Origin': '*' },+ })+ )+}+const mockImages = async (context) => {+ await context.route(/\.(png|jpeg|jpg|svg)$/, (route) => route.abort())+}++const changeContentType = async (page, to) => {+ await page.click(+ `button[aria-controls="content-switcher-popover"], button[aria-controls="content-switcher-modal"]`+ )+ await page.click(`button[role="radio"]:has-text("${to}")`)+}+/**+ * Finds a button with a popup to the left of the filters button which doesn't have a 'menu' label+ * @param page+ * @returns {Promise<string>}+ */+const currentContentType = async (page) => {+ const contentSwitcherButton = await page.locator(+ `button[aria-controls="content-switcher-popover"], button[aria-controls="content-switcher-modal"]`+ )+ return contentSwitcherButton.textContent()+}++const mockAllSearch = async (context) => {+ await Promise.all([+ mockAudioSearch(context),+ mockImageSearch(context),+ mockThumbnails(context),+ mockImages(context),+ ])+}++module.exports = {+ openFilters,+ changeContentType,+ currentContentType,+ assertCheckboxCheckedStatus,+ mockAllSearch,+ mockThumbnails,+}