2021-01-17 17:14:03 +00:00
|
|
|
import { mutations } from '../../conversation/mutations';
|
2019-12-11 15:27:06 +00:00
|
|
|
|
|
|
|
const temporaryMessagePayload = {
|
|
|
|
content: 'hello',
|
|
|
|
id: 1,
|
|
|
|
message_type: 0,
|
|
|
|
status: 'in_progress',
|
|
|
|
};
|
|
|
|
|
|
|
|
const incomingMessagePayload = {
|
|
|
|
content: 'hello',
|
|
|
|
id: 1,
|
|
|
|
message_type: 0,
|
|
|
|
status: 'sent',
|
|
|
|
};
|
|
|
|
|
|
|
|
const outgoingMessagePayload = {
|
|
|
|
content: 'hello',
|
|
|
|
id: 1,
|
|
|
|
message_type: 1,
|
|
|
|
status: 'sent',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('#mutations', () => {
|
|
|
|
describe('#pushMessageToConversation', () => {
|
|
|
|
it('add message to conversation if outgoing', () => {
|
|
|
|
const state = { conversations: {} };
|
|
|
|
mutations.pushMessageToConversation(state, outgoingMessagePayload);
|
|
|
|
expect(state.conversations).toEqual({
|
|
|
|
1: outgoingMessagePayload,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add message to conversation if message in undelivered', () => {
|
|
|
|
const state = { conversations: {} };
|
|
|
|
mutations.pushMessageToConversation(state, temporaryMessagePayload);
|
|
|
|
expect(state.conversations).toEqual({
|
|
|
|
1: temporaryMessagePayload,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('replaces temporary message in conversation with actual message', () => {
|
|
|
|
const state = {
|
|
|
|
conversations: {
|
|
|
|
rand_id_123: {
|
|
|
|
content: 'hello',
|
|
|
|
id: 'rand_id_123',
|
|
|
|
message_type: 0,
|
|
|
|
status: 'in_progress',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
mutations.pushMessageToConversation(state, incomingMessagePayload);
|
|
|
|
expect(state.conversations).toEqual({
|
|
|
|
1: incomingMessagePayload,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('adds message in conversation if it is a new message', () => {
|
|
|
|
const state = { conversations: {} };
|
|
|
|
mutations.pushMessageToConversation(state, incomingMessagePayload);
|
|
|
|
expect(state.conversations).toEqual({
|
|
|
|
1: incomingMessagePayload,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#setConversationListLoading', () => {
|
|
|
|
it('set status correctly', () => {
|
|
|
|
const state = { uiFlags: { isFetchingList: false } };
|
|
|
|
mutations.setConversationListLoading(state, true);
|
|
|
|
expect(state.uiFlags.isFetchingList).toEqual(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#setMessagesInConversation', () => {
|
|
|
|
it('sets allMessagesLoaded flag if payload is empty', () => {
|
|
|
|
const state = { uiFlags: { allMessagesLoaded: false } };
|
|
|
|
mutations.setMessagesInConversation(state, []);
|
|
|
|
expect(state.uiFlags.allMessagesLoaded).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets messages if payload is not empty', () => {
|
|
|
|
const state = {
|
|
|
|
uiFlags: { allMessagesLoaded: false },
|
|
|
|
conversations: {},
|
|
|
|
};
|
|
|
|
mutations.setMessagesInConversation(state, [{ id: 1, content: 'hello' }]);
|
|
|
|
expect(state.conversations).toEqual({
|
|
|
|
1: { id: 1, content: 'hello' },
|
|
|
|
});
|
|
|
|
expect(state.uiFlags.allMessagesLoaded).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
2020-03-30 06:45:06 +00:00
|
|
|
|
2020-05-04 17:37:56 +00:00
|
|
|
describe('#toggleAgentTypingStatus', () => {
|
|
|
|
it('sets isAgentTyping flag to true', () => {
|
|
|
|
const state = { uiFlags: { isAgentTyping: false } };
|
|
|
|
mutations.toggleAgentTypingStatus(state, { status: 'on' });
|
|
|
|
expect(state.uiFlags.isAgentTyping).toEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets isAgentTyping flag to false', () => {
|
2020-05-29 07:07:18 +00:00
|
|
|
const state = { uiFlags: { isAgentTyping: true } };
|
2020-05-04 17:37:56 +00:00
|
|
|
mutations.toggleAgentTypingStatus(state, { status: 'off' });
|
|
|
|
expect(state.uiFlags.isAgentTyping).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-17 15:45:20 +00:00
|
|
|
describe('#updateAttachmentMessageStatus', () => {
|
2020-03-30 06:45:06 +00:00
|
|
|
it('Updates status of loading messages if payload is not empty', () => {
|
|
|
|
const state = {
|
|
|
|
conversations: {
|
|
|
|
rand_id_123: {
|
|
|
|
content: '',
|
|
|
|
id: 'rand_id_123',
|
|
|
|
message_type: 0,
|
|
|
|
status: 'in_progress',
|
2020-04-02 06:58:38 +00:00
|
|
|
attachment: {
|
|
|
|
file: '',
|
|
|
|
file_type: 'image',
|
|
|
|
},
|
2020-03-30 06:45:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const message = {
|
|
|
|
id: '1',
|
|
|
|
content: '',
|
|
|
|
status: 'sent',
|
2020-04-17 15:45:20 +00:00
|
|
|
message_type: 0,
|
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
file: '',
|
|
|
|
file_type: 'image',
|
|
|
|
},
|
|
|
|
],
|
2020-03-30 06:45:06 +00:00
|
|
|
};
|
2020-04-17 15:45:20 +00:00
|
|
|
mutations.updateAttachmentMessageStatus(state, {
|
|
|
|
message,
|
|
|
|
tempId: 'rand_id_123',
|
|
|
|
});
|
2020-03-30 06:45:06 +00:00
|
|
|
|
|
|
|
expect(state.conversations).toEqual({
|
2020-04-02 06:58:38 +00:00
|
|
|
1: {
|
|
|
|
id: '1',
|
|
|
|
content: '',
|
|
|
|
message_type: 0,
|
|
|
|
status: 'sent',
|
2020-04-17 15:45:20 +00:00
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
file: '',
|
|
|
|
file_type: 'image',
|
|
|
|
},
|
|
|
|
],
|
2020-04-02 06:58:38 +00:00
|
|
|
},
|
2020-03-30 06:45:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-17 17:14:03 +00:00
|
|
|
|
|
|
|
describe('#clearConversations', () => {
|
|
|
|
it('clears the state', () => {
|
|
|
|
const state = { conversations: { 1: { id: 1 } } };
|
|
|
|
mutations.clearConversations(state);
|
|
|
|
expect(state.conversations).toEqual({});
|
|
|
|
});
|
|
|
|
});
|
2019-12-11 15:27:06 +00:00
|
|
|
});
|