This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
search-query-server.spec.js
91 lines (76 loc) · 2.95 KB
/
search-query-server.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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 content type
* 3. query parameters are used to set the filter data:
* 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
*/
test.beforeEach(async ({ context }) => {
// Block any image or audio (jamendo.com) requests for each test in this file.
await context.route('**.jamendo.com**', (route) => route.abort())
await mockAllSearch(context)
})
test('q query parameter is set as the search term', async ({ page }) => {
await page.goto(
'/search/?q=cat&license=cc0&license_type=commercial&searchBy=creator'
)
const searchInput = page.locator('input[type="search"]')
await expect(searchInput).toHaveValue('cat')
// Todo: focus the input?
// await expect(searchInput).toBeFocused()
})
test('url path /search/ is used to select `all` search tab', async ({
page,
}) => {
await page.goto('/search/?q=cat')
const contentType = await currentContentType(page)
expect(contentType.trim()).toEqual('All content')
})
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 contentType = await currentContentType(page)
expect(contentType.trim()).toEqual('Audio')
})
test('url query to filter, all tab, one parameter per filter type', async ({
page,
}) => {
await page.goto(
'/search/?q=cat&license=cc0&license_type=commercial&searchBy=creator'
)
await openFilters(page)
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 ({
page,
}) => {
await page.goto(
'/search/image?q=cat&searchBy=creator&extension=jpg,png,gif,svg'
)
await openFilters(page)
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 ({
page,
}) => {
await page.goto('/search/image?q=cat&mature=true')
await page.click('button:has-text("Safer Browsing")')
const matureCheckbox = await page.locator('text=Show Mature Content')
await expect(matureCheckbox).toBeChecked()
await page.click('text=Show Mature Content')
await expect(page).toHaveURL('/search/image?q=cat')
})