feat: Add Advanced Conversation Filters (#3239)

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
Co-authored-by: Tejaswini <tejaswini@chatwoot.com>
This commit is contained in:
Fayaz Ahmed
2021-11-18 19:15:02 +05:30
committed by GitHub
parent bf96e8b68d
commit c2333214af
30 changed files with 1778 additions and 78 deletions

View File

@@ -1,6 +1,17 @@
import axios from 'axios';
import actions from '../../conversations/actions';
import types from '../../../mutation-types';
const dataToSend = {
payload: [
{
attribute_key: 'status',
filter_operator: 'equal_to',
values: ['open'],
query_operator: null,
},
],
};
import { dataReceived } from './testConversationResponse';
const commit = jest.fn();
const dispatch = jest.fn();
@@ -73,7 +84,30 @@ describe('#actions', () => {
inbox_id: 2,
};
actions.addConversation(
{ commit, dispatch, state: { currentInbox: 1 } },
{
commit,
dispatch,
state: { currentInbox: 1, appliedFilters: [] },
},
conversation
);
expect(commit.mock.calls).toEqual([]);
expect(dispatch.mock.calls).toEqual([]);
});
it('doesnot send mutation if conversation filters are applied', () => {
const conversation = {
id: 1,
messages: [],
meta: { sender: { id: 1, name: 'john-doe' } },
inbox_id: 1,
};
actions.addConversation(
{
commit,
dispatch,
state: { currentInbox: 1, appliedFilters: [{ id: 'random-filter' }] },
},
conversation
);
expect(commit.mock.calls).toEqual([]);
@@ -88,7 +122,11 @@ describe('#actions', () => {
inbox_id: 1,
};
actions.addConversation(
{ commit, dispatch, state: { currentInbox: 1 } },
{
commit,
dispatch,
state: { currentInbox: 1, appliedFilters: [] },
},
conversation
);
expect(commit.mock.calls).toEqual([
@@ -112,7 +150,10 @@ describe('#actions', () => {
meta: { sender: { id: 1, name: 'john-doe' } },
inbox_id: 1,
};
actions.addConversation({ commit, dispatch, state: {} }, conversation);
actions.addConversation(
{ commit, dispatch, state: { appliedFilters: [] } },
conversation
);
expect(commit.mock.calls).toEqual([
[types.ADD_CONVERSATION, conversation],
]);
@@ -262,6 +303,44 @@ describe('#actions', () => {
]);
});
});
describe('#fetchFilteredConversations', () => {
it('fetches filtered conversations with a mock commit', async () => {
axios.post.mockResolvedValue({
data: dataReceived,
});
await actions.fetchFilteredConversations({ commit }, dataToSend);
expect(commit).toHaveBeenCalledTimes(2);
expect(commit.mock.calls).toEqual([
['SET_LIST_LOADING_STATUS'],
['SET_ALL_CONVERSATION', dataReceived.payload],
]);
});
});
describe('#setConversationFilter', () => {
it('commits the correct mutation and sets filter state', () => {
const filters = [
{
attribute_key: 'status',
filter_operator: 'equal_to',
values: [{ id: 'snoozed', name: 'Snoozed' }],
query_operator: 'and',
},
];
actions.setConversationFilters({ commit }, filters);
expect(commit.mock.calls).toEqual([
[types.SET_CONVERSATION_FILTERS, filters],
]);
});
});
describe('#clearConversationFilter', () => {
it('commits the correct mutation and clears filter state', () => {
actions.clearConversationFilters({ commit });
expect(commit.mock.calls).toEqual([[types.CLEAR_CONVERSATION_FILTERS]]);
});
});
});
describe('#deleteMessage', () => {