Skip to content

Commit

Permalink
Test wildcard search
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaong committed Jan 15, 2024
1 parent a0492a9 commit 7bc4b0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"jest": "^26.4.2",
"jest-environment-enzyme": "^7.1.1",
"jest-enzyme": "^7.1.1",
"minisearch": "6.0.0-beta.1",
"minisearch": "6.3.0",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"rollup": "^2.26.9",
Expand Down
18 changes: 18 additions & 0 deletions src/react-minisearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ const ChildComponent: React.FC<UseMiniSearch<DocumentType>> = ({
<button className='clear' onClick={() => { clearSearch(); clearSuggestions() }}>
Clear
</button>
<button className='wildcard-search' onClick={() => search(MiniSearch.wildcard)}>
Wildcard search
</button>
</div>
)
}
Expand Down Expand Up @@ -125,6 +128,21 @@ const testComponent = (Component: React.FC<Props>) => {
expect(wrap.find('ChildComponent').prop('rawResults')).toHaveLength(0)
})

it('performs a wildcard search', () => {
const wrap = mount(<Component {...props} />)
expect(wrap.find('.results li')).not.toExist()

wrap.find('button.wildcard-search').simulate('click')

const items = wrap.update().find('.results li')

expect(items).toHaveLength(documents.length)
expect(items.first()).toHaveText(documents[0].title)
expect(items.at(1)).toHaveText(documents[1].title)
expect(wrap.find('ChildComponent').prop('rawResults')).toHaveLength(documents.length)
expect(wrap.find('ChildComponent').prop('rawResults')[0]).toMatchObject({ id: documents[0].uid, terms: [] })
})

it('produces auto suggestions', () => {
const wrap = mount(<Component {...props} />)

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4358,10 +4358,10 @@ minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==

minisearch@6.0.0-beta.1:
version "6.0.0-beta.1"
resolved "https://registry.yarnpkg.com/minisearch/-/minisearch-6.0.0-beta.1.tgz#74296710fae758984b90f944cd532cc05791ac48"
integrity sha512-/qHyE4qBbBtli/zgR8H/Dus3cOxQdTciglY/QEyU6FDGCd4lRtYWwkhJ/yDXZvblFXoWwYILu3qCFqsTtF53+g==
minisearch@6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/minisearch/-/minisearch-6.3.0.tgz#985a2f1ca3c73c2d65af94f0616bfe57164b0b6b"
integrity sha512-ihFnidEeU8iXzcVHy74dhkxh/dn8Dc08ERl0xwoMMGqp4+LvRSCgicb+zGqWthVokQKvCSxITlh3P08OzdTYCQ==

mixin-deep@^1.2.0:
version "1.3.2"
Expand Down

0 comments on commit 7bc4b0d

Please sign in to comment.