Fix: sidebar filters not applying bug for chatlist (#1938)

This commit is contained in:
Nithin David Thomas
2021-03-20 17:42:29 +05:30
committed by GitHub
parent 4657e5c713
commit 484c32fae3
5 changed files with 201 additions and 81 deletions

View File

@@ -47,33 +47,59 @@ describe('#getters', () => {
]);
});
});
describe('#getNextChatConversation', () => {
it('return the next chat', () => {
const state = {
allConversations: [
{
id: 1,
},
{
id: 2,
},
],
selectedChatId: 1,
};
expect(getters.getNextChatConversation(state)).toEqual({
id: 2,
});
});
it('return null when there is only one chat', () => {
const state = {
allConversations: [
{
id: 1,
},
],
selectedChatId: 1,
};
expect(getters.getNextChatConversation(state)).toBeNull();
describe('#getUnAssignedChats', () => {
it('order returns only chats assigned to user', () => {
const conversationList = [
{
id: 1,
inbox_id: 2,
status: 1,
meta: { assignee: { id: 1 } },
labels: ['sales', 'dev'],
},
{
id: 2,
inbox_id: 2,
status: 1,
meta: {},
labels: ['dev'],
},
{
id: 11,
inbox_id: 3,
status: 1,
meta: { assignee: { id: 1 } },
labels: [],
},
{
id: 22,
inbox_id: 4,
status: 1,
meta: { team: { id: 5 } },
labels: ['sales'],
},
];
expect(
getters.getUnAssignedChats({ allConversations: conversationList })({
status: 1,
})
).toEqual([
{
id: 2,
inbox_id: 2,
status: 1,
meta: {},
labels: ['dev'],
},
{
id: 22,
inbox_id: 4,
status: 1,
meta: { team: { id: 5 } },
labels: ['sales'],
},
]);
});
});
});

View File

@@ -1,4 +1,38 @@
import { findPendingMessageIndex } from '../../conversations/helpers';
import {
findPendingMessageIndex,
applyPageFilters,
} from '../../conversations/helpers';
const conversationList = [
{
id: 1,
inbox_id: 2,
status: 1,
meta: {},
labels: ['sales', 'dev'],
},
{
id: 2,
inbox_id: 2,
status: 1,
meta: {},
labels: ['dev'],
},
{
id: 11,
inbox_id: 3,
status: 1,
meta: { team: { id: 5 } },
labels: [],
},
{
id: 22,
inbox_id: 4,
status: 1,
meta: { team: { id: 5 } },
labels: ['sales'],
},
];
describe('#findPendingMessageIndex', () => {
it('returns the correct index of pending message with id', () => {
@@ -18,20 +52,64 @@ describe('#findPendingMessageIndex', () => {
});
});
describe('#addOrUpdateChat', () => {
it('returns the correct index of pending message with id', () => {
const chat = {
messages: [{ id: 1, status: 'progress' }],
};
const message = { echo_id: 1 };
expect(findPendingMessageIndex(chat, message)).toEqual(0);
describe('#applyPageFilters', () => {
describe('#filter-team', () => {
it('returns true if conversation has team and team filter is active', () => {
const filters = {
status: 1,
teamId: 5,
};
expect(applyPageFilters(conversationList[3], filters)).toEqual(true);
});
it('returns true if conversation has no team and team filter is active', () => {
const filters = {
status: 1,
teamId: 5,
};
expect(applyPageFilters(conversationList[0], filters)).toEqual(false);
});
});
it('returns -1 if pending message with id is not present', () => {
const chat = {
messages: [{ id: 1, status: 'progress' }],
};
const message = { echo_id: 2 };
expect(findPendingMessageIndex(chat, message)).toEqual(-1);
describe('#filter-inbox', () => {
it('returns true if conversation has inbox and inbox filter is active', () => {
const filters = {
status: 1,
inboxId: 4,
};
expect(applyPageFilters(conversationList[3], filters)).toEqual(true);
});
it('returns true if conversation has no inbox and inbox filter is active', () => {
const filters = {
status: 1,
inboxId: 5,
};
expect(applyPageFilters(conversationList[0], filters)).toEqual(false);
});
});
describe('#filter-labels', () => {
it('returns true if conversation has labels and labels filter is active', () => {
const filters = {
status: 1,
labels: ['dev'],
};
expect(applyPageFilters(conversationList[0], filters)).toEqual(true);
});
it('returns true if conversation has no inbox and inbox filter is active', () => {
const filters = {
status: 1,
labels: ['dev'],
};
expect(applyPageFilters(conversationList[2], filters)).toEqual(false);
});
});
describe('#filter-status', () => {
it('returns true if conversation has status and status filter is active', () => {
const filters = {
status: 1,
};
expect(applyPageFilters(conversationList[1], filters)).toEqual(true);
});
});
});