mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-24 20:14:35 -04:00
fix(deps): replace flexsearch-ts with orama
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
931ce68a32
commit
07162b7807
25 changed files with 266 additions and 215 deletions
58
frontend/src/hooks/common/use-cheatsheet-search.spec.ts
Normal file
58
frontend/src/hooks/common/use-cheatsheet-search.spec.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import type { CheatsheetSearchIndexEntry } from './use-cheatsheet-search'
|
||||
import { useCheatsheetSearch } from './use-cheatsheet-search'
|
||||
import { renderHook, waitFor } from '@testing-library/react'
|
||||
|
||||
describe('useDocumentSearch', () => {
|
||||
const searchEntries: CheatsheetSearchIndexEntry[] = [
|
||||
{
|
||||
id: 'test1',
|
||||
extensionId: 'test1',
|
||||
title: 'title1',
|
||||
description: 'description1',
|
||||
example: 'example1'
|
||||
},
|
||||
{
|
||||
id: 'test2',
|
||||
extensionId: 'test2',
|
||||
title: 'title2 sub',
|
||||
description: 'description2',
|
||||
example: 'example2'
|
||||
},
|
||||
{
|
||||
id: 'test3',
|
||||
extensionId: 'test3',
|
||||
title: 'title3 sub',
|
||||
description: 'description3',
|
||||
example: 'example3'
|
||||
}
|
||||
]
|
||||
|
||||
it('returns all entries if no search term is given', async () => {
|
||||
const { result } = renderHook((searchTerm: string) => useCheatsheetSearch(searchEntries, searchTerm), {
|
||||
initialProps: ''
|
||||
})
|
||||
|
||||
await waitFor(() => expect(result.current).toStrictEqual(searchEntries))
|
||||
})
|
||||
|
||||
it('results no entries if nothing has been found', async () => {
|
||||
const { result } = renderHook((searchTerm: string) => useCheatsheetSearch(searchEntries, searchTerm), {
|
||||
initialProps: 'Foo'
|
||||
})
|
||||
|
||||
await waitFor(() => expect(result.current).toHaveLength(0))
|
||||
})
|
||||
|
||||
it('returns multiple entries if matching', async () => {
|
||||
const { result } = renderHook((searchTerm: string) => useCheatsheetSearch(searchEntries, searchTerm), {
|
||||
initialProps: 'sub'
|
||||
})
|
||||
|
||||
await waitFor(() => expect(result.current).toHaveLength(2))
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue