-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(suggestion): check queryAll is correctly called with good params
- Loading branch information
1 parent
79b220f
commit 63de61f
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/drive/web/modules/services/components/SuggestionProvider.spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
import SuggestionProvider from './SuggestionProvider' | ||
|
||
let files = [] | ||
const mockClient = { queryAll: jest.fn().mockReturnValue(files) } | ||
const mockIntentAttributesClient = 'intent-attributes-client' | ||
|
||
jest.mock('cozy-client', () => { | ||
return { | ||
...jest.requireActual('cozy-client'), | ||
withClient: Component => () => { | ||
const intent = { attributes: { client: mockIntentAttributesClient } } | ||
return <Component client={mockClient} intent={intent}></Component> | ||
} | ||
} | ||
}) | ||
jest.mock('./iconContext', () => ({ getIconUrl: () => 'iconUrl' })) | ||
|
||
describe('SuggestionProvider', () => { | ||
it('should query all files to display fuzzy suggestion', () => { | ||
// Given | ||
let events = {} | ||
window.addEventListener = jest.fn((event, callback) => { | ||
events[event] = callback | ||
}) | ||
window.postMessage = jest.fn() | ||
|
||
render(<SuggestionProvider />) | ||
const event = { | ||
origin: mockIntentAttributesClient, | ||
data: { query: 'query', id: 'id' } | ||
} | ||
|
||
// When | ||
events.message(event) | ||
|
||
// Then | ||
expect(mockClient.queryAll).toHaveBeenCalledWith({ | ||
doctype: 'io.cozy.files', | ||
fields: ['_id', 'trashed', 'dir_id', 'name', 'path'], | ||
limit: 1000, | ||
partialFilter: { | ||
_id: { $ne: 'io.cozy.files.trash-dir' }, | ||
trashed: { $or: [{ $exists: false }, { $eq: false }] } | ||
}, | ||
selector: { _id: { $gt: null } } | ||
}) | ||
}) | ||
}) |