121 lines
3.2 KiB
JavaScript
121 lines
3.2 KiB
JavaScript
import {
|
|
findPendingMessageIndex,
|
|
applyPageFilters,
|
|
} from '../../conversations/helpers';
|
|
|
|
const conversationList = [
|
|
{
|
|
id: 1,
|
|
inbox_id: 2,
|
|
status: 'open',
|
|
meta: {},
|
|
labels: ['sales', 'dev'],
|
|
},
|
|
{
|
|
id: 2,
|
|
inbox_id: 2,
|
|
status: 'open',
|
|
meta: {},
|
|
labels: ['dev'],
|
|
},
|
|
{
|
|
id: 11,
|
|
inbox_id: 3,
|
|
status: 'resolved',
|
|
meta: { team: { id: 5 } },
|
|
labels: [],
|
|
},
|
|
{
|
|
id: 22,
|
|
inbox_id: 4,
|
|
status: 'pending',
|
|
meta: { team: { id: 5 } },
|
|
labels: ['sales'],
|
|
},
|
|
];
|
|
|
|
describe('#findPendingMessageIndex', () => {
|
|
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);
|
|
});
|
|
|
|
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('#applyPageFilters', () => {
|
|
describe('#filter-team', () => {
|
|
it('returns true if conversation has team and team filter is active', () => {
|
|
const filters = {
|
|
status: 'resolved',
|
|
teamId: 5,
|
|
};
|
|
expect(applyPageFilters(conversationList[2], filters)).toEqual(true);
|
|
});
|
|
it('returns true if conversation has no team and team filter is active', () => {
|
|
const filters = {
|
|
status: 'open',
|
|
teamId: 5,
|
|
};
|
|
expect(applyPageFilters(conversationList[0], filters)).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe('#filter-inbox', () => {
|
|
it('returns true if conversation has inbox and inbox filter is active', () => {
|
|
const filters = {
|
|
status: 'pending',
|
|
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: 'open',
|
|
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: 'open',
|
|
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: 'open',
|
|
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: 'open',
|
|
};
|
|
expect(applyPageFilters(conversationList[1], filters)).toEqual(true);
|
|
});
|
|
it('returns true if conversation has status and status filter is all', () => {
|
|
const filters = {
|
|
status: 'all',
|
|
};
|
|
expect(applyPageFilters(conversationList[1], filters)).toEqual(true);
|
|
});
|
|
});
|
|
});
|