test: add test case

pull/3032/head
buqiyuan 2 years ago
parent 3479d5a0ce
commit ef70739d17

@ -1 +1,6 @@
---
title: Local search frontmatter title
---
# Local search included # Local search included
# {{ $frontmatter.title }}

@ -1,18 +1,23 @@
const getSearchResults = async (text: string) => {
await page.locator('#local-search button').click()
const input = await page.waitForSelector('input#localsearch-input')
await input.fill(text)
await page.waitForSelector('ul#localsearch-list', { state: 'visible' })
return page.locator('#localsearch-list')
}
describe('local search', () => { describe('local search', () => {
beforeEach(async () => { beforeEach(async () => {
await goto('/') await goto('/')
}) })
test('exclude content from search results', async () => { test('exclude content from search results', async () => {
await page.locator('#local-search button').click() const searchResults = await getSearchResults('local')
const input = await page.waitForSelector('input#localsearch-input') expect(await searchResults.locator('li[role=option]').count()).toBe(2)
await input.type('local')
await page.waitForSelector('ul#localsearch-list', { state: 'visible' })
const searchResults = page.locator('#localsearch-list')
expect(await searchResults.locator('li[role=option]').count()).toBe(1)
expect( expect(
await searchResults.filter({ hasText: 'Local search included' }).count() await searchResults.filter({ hasText: 'Local search included' }).count()
@ -28,4 +33,14 @@ describe('local search', () => {
.count() .count()
).toBe(0) ).toBe(0)
}) })
test('frontmatter content from search results', async () => {
const searchResults = await getSearchResults('local')
expect(
await searchResults
.filter({ hasText: 'Local search frontmatter title' })
.count()
).toBe(1)
})
}) })

Loading…
Cancel
Save