Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Oct 9, 2023
1 parent 3479d5a commit ef70739
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
7 changes: 6 additions & 1 deletion __tests__/e2e/local-search/index.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Local search included
---
title: Local search frontmatter title
---
# Local search included

# {{ $frontmatter.title }}
31 changes: 23 additions & 8 deletions __tests__/e2e/local-search/local-search.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
beforeEach(async () => {
await goto('/')
})

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')
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(await searchResults.locator('li[role=option]').count()).toBe(2)

expect(
await searchResults.filter({ hasText: 'Local search included' }).count()
Expand All @@ -28,4 +33,14 @@ describe('local search', () => {
.count()
).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)
})
})

0 comments on commit ef70739

Please sign in to comment.