2020-07-23 18:03:17 +00:00
|
|
|
import types from '../../../mutation-types';
|
|
|
|
import { mutations } from '../../conversations';
|
|
|
|
|
|
|
|
describe('#mutations', () => {
|
|
|
|
describe('#EMPTY_ALL_CONVERSATION', () => {
|
|
|
|
it('empty conversations', () => {
|
|
|
|
const state = { allConversations: [{ id: 1 }], selectedChatId: 1 };
|
|
|
|
mutations[types.EMPTY_ALL_CONVERSATION](state);
|
|
|
|
expect(state.allConversations).toEqual([]);
|
|
|
|
expect(state.selectedChatId).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#MARK_MESSAGE_READ', () => {
|
|
|
|
it('mark conversation as read', () => {
|
|
|
|
const state = { allConversations: [{ id: 1 }] };
|
|
|
|
const lastSeen = new Date().getTime() / 1000;
|
|
|
|
mutations[types.MARK_MESSAGE_READ](state, { id: 1, lastSeen });
|
|
|
|
expect(state.allConversations).toEqual([
|
|
|
|
{ id: 1, agent_last_seen_at: lastSeen },
|
|
|
|
]);
|
|
|
|
});
|
2020-08-03 08:10:20 +00:00
|
|
|
|
|
|
|
it('doesnot send any mutation if chat doesnot exist', () => {
|
|
|
|
const state = { allConversations: [] };
|
|
|
|
const lastSeen = new Date().getTime() / 1000;
|
|
|
|
mutations[types.MARK_MESSAGE_READ](state, { id: 1, lastSeen });
|
|
|
|
expect(state.allConversations).toEqual([]);
|
|
|
|
});
|
2020-07-23 18:03:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('#CLEAR_CURRENT_CHAT_WINDOW', () => {
|
|
|
|
it('clears current chat window', () => {
|
|
|
|
const state = { selectedChatId: 1 };
|
|
|
|
mutations[types.CLEAR_CURRENT_CHAT_WINDOW](state);
|
|
|
|
expect(state.selectedChatId).toEqual(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#SET_CURRENT_CHAT_WINDOW', () => {
|
|
|
|
it('set current chat window', () => {
|
|
|
|
const state = { selectedChatId: 1 };
|
|
|
|
mutations[types.SET_CURRENT_CHAT_WINDOW](state, { id: 2 });
|
|
|
|
expect(state.selectedChatId).toEqual(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not set current chat window', () => {
|
|
|
|
const state = { selectedChatId: 1 };
|
|
|
|
mutations[types.SET_CURRENT_CHAT_WINDOW](state);
|
|
|
|
expect(state.selectedChatId).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
2020-07-25 17:24:45 +00:00
|
|
|
|
|
|
|
describe('#SET_CONVERSATION_CAN_REPLY', () => {
|
|
|
|
it('set canReply flag', () => {
|
|
|
|
const state = { allConversations: [{ id: 1, can_reply: false }] };
|
|
|
|
mutations[types.SET_CONVERSATION_CAN_REPLY](state, {
|
|
|
|
conversationId: 1,
|
|
|
|
canReply: true,
|
|
|
|
});
|
|
|
|
expect(state.allConversations[0].can_reply).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
2020-10-11 14:54:26 +00:00
|
|
|
|
|
|
|
describe('#ADD_MESSAGE', () => {
|
|
|
|
it('does not add message to the store if conversation does not exist', () => {
|
|
|
|
const state = { allConversations: [] };
|
|
|
|
mutations[types.ADD_MESSAGE](state, { conversationId: 1 });
|
|
|
|
expect(state.allConversations).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add message to the conversation if it does not exist in the store', () => {
|
|
|
|
global.bus = { $emit: jest.fn() };
|
|
|
|
const state = {
|
|
|
|
allConversations: [{ id: 1, messages: [] }],
|
|
|
|
selectedChatId: -1,
|
|
|
|
};
|
|
|
|
mutations[types.ADD_MESSAGE](state, {
|
|
|
|
conversation_id: 1,
|
|
|
|
content: 'Test message',
|
|
|
|
created_at: 1602256198,
|
|
|
|
});
|
|
|
|
expect(state.allConversations).toEqual([
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
messages: [
|
|
|
|
{
|
|
|
|
conversation_id: 1,
|
|
|
|
content: 'Test message',
|
|
|
|
created_at: 1602256198,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
timestamp: 1602256198,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
expect(global.bus.$emit).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add message to the conversation and emit scrollToMessage if it does not exist in the store', () => {
|
|
|
|
global.bus = { $emit: jest.fn() };
|
|
|
|
const state = {
|
|
|
|
allConversations: [{ id: 1, messages: [] }],
|
|
|
|
selectedChatId: 1,
|
|
|
|
};
|
|
|
|
mutations[types.ADD_MESSAGE](state, {
|
|
|
|
conversation_id: 1,
|
|
|
|
content: 'Test message',
|
|
|
|
created_at: 1602256198,
|
|
|
|
});
|
|
|
|
expect(state.allConversations).toEqual([
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
messages: [
|
|
|
|
{
|
|
|
|
conversation_id: 1,
|
|
|
|
content: 'Test message',
|
|
|
|
created_at: 1602256198,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
timestamp: 1602256198,
|
|
|
|
},
|
|
|
|
]);
|
2022-03-23 07:57:50 +00:00
|
|
|
expect(global.bus.$emit).toHaveBeenCalledWith('SCROLL_TO_MESSAGE');
|
2020-10-11 14:54:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('update message if it exist in the store', () => {
|
|
|
|
global.bus = { $emit: jest.fn() };
|
|
|
|
const state = {
|
|
|
|
allConversations: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
messages: [
|
|
|
|
{
|
|
|
|
conversation_id: 1,
|
|
|
|
content: 'Test message',
|
|
|
|
created_at: 1602256198,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
selectedChatId: 1,
|
|
|
|
};
|
|
|
|
mutations[types.ADD_MESSAGE](state, {
|
|
|
|
conversation_id: 1,
|
|
|
|
content: 'Test message 1',
|
|
|
|
created_at: 1602256198,
|
|
|
|
});
|
|
|
|
expect(state.allConversations).toEqual([
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
messages: [
|
|
|
|
{
|
|
|
|
conversation_id: 1,
|
|
|
|
content: 'Test message 1',
|
|
|
|
created_at: 1602256198,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
expect(global.bus.$emit).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2021-08-02 07:41:07 +00:00
|
|
|
|
2021-09-29 14:03:51 +00:00
|
|
|
describe('#CHANGE_CONVERSATION_STATUS', () => {
|
2021-08-02 07:41:07 +00:00
|
|
|
it('updates the conversation status correctly', () => {
|
|
|
|
const state = {
|
|
|
|
allConversations: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
messages: [],
|
|
|
|
status: 'open',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2021-09-29 14:03:51 +00:00
|
|
|
mutations[types.CHANGE_CONVERSATION_STATUS](state, {
|
2021-08-02 07:41:07 +00:00
|
|
|
conversationId: '1',
|
|
|
|
status: 'resolved',
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(state.allConversations).toEqual([
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
messages: [],
|
|
|
|
status: 'resolved',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2021-10-30 01:39:46 +00:00
|
|
|
|
|
|
|
describe('#UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES', () => {
|
|
|
|
it('update conversation custom attributes', () => {
|
|
|
|
const custom_attributes = { order_id: 1001 };
|
|
|
|
const state = { allConversations: [{ id: 1 }], selectedChatId: 1 };
|
|
|
|
mutations[types.UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES](state, {
|
|
|
|
conversationId: 1,
|
|
|
|
custom_attributes,
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
state.allConversations[0].custom_attributes.custom_attributes
|
|
|
|
).toEqual(custom_attributes);
|
|
|
|
});
|
|
|
|
});
|
2021-08-02 07:41:07 +00:00
|
|
|
});
|
2021-11-18 13:45:02 +00:00
|
|
|
|
|
|
|
describe('#SET_CONVERSATION_FILTERS', () => {
|
|
|
|
it('set conversation filter', () => {
|
|
|
|
const appliedFilters = [
|
|
|
|
{
|
|
|
|
attribute_key: 'status',
|
|
|
|
filter_operator: 'equal_to',
|
|
|
|
values: [{ id: 'snoozed', name: 'Snoozed' }],
|
|
|
|
query_operator: 'and',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
mutations[types.SET_CONVERSATION_FILTERS](appliedFilters);
|
|
|
|
expect(appliedFilters).toEqual([
|
|
|
|
{
|
|
|
|
attribute_key: 'status',
|
|
|
|
filter_operator: 'equal_to',
|
|
|
|
values: [{ id: 'snoozed', name: 'Snoozed' }],
|
|
|
|
query_operator: 'and',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#CLEAR_CONVERSATION_FILTERS', () => {
|
|
|
|
it('clears applied conversation filters', () => {
|
|
|
|
const state = {
|
|
|
|
appliedFilters: [
|
|
|
|
{
|
|
|
|
attribute_key: 'status',
|
|
|
|
filter_operator: 'equal_to',
|
|
|
|
values: [{ id: 'snoozed', name: 'Snoozed' }],
|
|
|
|
query_operator: 'and',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
mutations[types.CLEAR_CONVERSATION_FILTERS](state);
|
|
|
|
expect(state.appliedFilters).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
2020-07-23 18:03:17 +00:00
|
|
|
});
|