feat: Create a new conversation from the contact panel (#2019)

* Chore: Improve button component styles
This commit is contained in:
Nithin David Thomas
2021-04-16 20:31:07 +05:30
committed by GitHub
parent c287ad08fb
commit 864471a21e
16 changed files with 469 additions and 9 deletions

View File

@@ -38,4 +38,43 @@ describe('#actions', () => {
]);
});
});
describe('#create', () => {
it('sends correct actions if API is success', async () => {
axios.post.mockResolvedValue({ data: conversationList[0] });
await actions.create(
{ commit },
{ inboxId: 1, message: { content: 'hi' }, contactId: 4, sourceId: 5 }
);
expect(commit.mock.calls).toEqual([
[types.default.SET_CONTACT_CONVERSATIONS_UI_FLAG, { isCreating: true }],
[
types.default.ADD_CONTACT_CONVERSATION,
{ id: 4, data: conversationList[0] },
],
[
types.default.SET_CONTACT_CONVERSATIONS_UI_FLAG,
{ isCreating: false },
],
]);
});
it('sends correct actions if API is error', async () => {
axios.post.mockRejectedValue({ message: 'Incorrect header' });
await expect(
actions.create(
{ commit },
{ inboxId: 1, message: { content: 'hi' }, contactId: 4, sourceId: 5 }
)
).rejects.toThrow(Error);
expect(commit.mock.calls).toEqual([
[types.default.SET_CONTACT_CONVERSATIONS_UI_FLAG, { isCreating: true }],
[
types.default.SET_CONTACT_CONVERSATIONS_UI_FLAG,
{ isCreating: false },
],
]);
});
});
});

View File

@@ -26,4 +26,17 @@ describe('#mutations', () => {
});
});
});
describe('#ADD_CONTACT_CONVERSATION', () => {
it('Adds new contact conversation to records', () => {
const state = { records: {} };
mutations[types.default.ADD_CONTACT_CONVERSATION](state, {
id: 1,
data: { id: 1, contact_id: 1, message: 'hello' },
});
expect(state.records).toEqual({
1: [{ id: 1, contact_id: 1, message: 'hello' }],
});
});
});
});