diff --git a/.eslintrc.json b/.eslintrc.json index 938f4e68e3..9a1264d8b8 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,6 @@ "no-console": 1, "no-param-reassign": "error", "react-hooks/exhaustive-deps": "error" - }, "globals": { "fixture": false @@ -13,5 +12,13 @@ "react": { "version": "detect" } - } + }, + "overrides": [ + { + "files": ["*.spec.js[x]"], + "rules": { + "react/display-name": "off" + } + } + ] } diff --git a/src/drive/web/modules/services/components/SuggestionProvider.spec.jsx b/src/drive/web/modules/services/components/SuggestionProvider.spec.jsx new file mode 100644 index 0000000000..ba7d8d4e63 --- /dev/null +++ b/src/drive/web/modules/services/components/SuggestionProvider.spec.jsx @@ -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 + } + } +}) +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() + 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 } } + }) + }) +})