feat: Add global message search (#1385)

* feat: Search messages by content

* Fix search UI

* Add specs

* chore: Filter search results

* Update highlight logic

* Rename query to searchTerm

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S
2020-11-08 01:46:45 +05:30
committed by GitHub
parent 22683cae66
commit 7718cf7d2c
15 changed files with 399 additions and 30 deletions

View File

@@ -0,0 +1,44 @@
import { actions } from '../../conversationSearch';
import types from '../../../mutation-types';
import axios from 'axios';
const commit = jest.fn();
global.axios = axios;
jest.mock('axios');
describe('#actions', () => {
describe('#get', () => {
it('sends correct actions if no query param is provided', () => {
actions.get({ commit }, { q: '' });
expect(commit.mock.calls).toEqual([[types.SEARCH_CONVERSATIONS_SET, []]]);
});
it('sends correct actions if query param is provided and API call is success', async () => {
axios.get.mockResolvedValue({
data: {
payload: [{ messages: [{ id: 1, content: 'value testing' }], id: 1 }],
},
});
await actions.get({ commit }, { q: 'value' });
expect(commit.mock.calls).toEqual([
[types.SEARCH_CONVERSATIONS_SET, []],
[types.SEARCH_CONVERSATIONS_SET_UI_FLAG, { isFetching: true }],
[
types.SEARCH_CONVERSATIONS_SET,
[{ messages: [{ id: 1, content: 'value testing' }], id: 1 }],
],
[types.SEARCH_CONVERSATIONS_SET_UI_FLAG, { isFetching: false }],
]);
});
it('sends correct actions if query param is provided and API call is errored', async () => {
axios.get.mockRejectedValue({});
await actions.get({ commit }, { q: 'value' });
expect(commit.mock.calls).toEqual([
[types.SEARCH_CONVERSATIONS_SET, []],
[types.SEARCH_CONVERSATIONS_SET_UI_FLAG, { isFetching: true }],
[types.SEARCH_CONVERSATIONS_SET_UI_FLAG, { isFetching: false }],
]);
});
});
});