feat: Allow users to mark a conversation as unread (#5924)

Allow users to mark conversations as unread.
Loom video: https://www.loom.com/share/ab70552d3c9c48b685da7dfa64be8bb3

fixes: #5552

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Sojan Jose
2022-11-24 07:55:45 +00:00
committed by GitHub
parent e593e516b8
commit 606fc9046a
20 changed files with 190 additions and 48 deletions

View File

@@ -245,7 +245,7 @@ describe('#actions', () => {
jest.runAllTimers();
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls).toEqual([
[types.MARK_MESSAGE_READ, { id: 1, lastSeen }],
[types.UPDATE_MESSAGE_UNREAD_COUNT, { id: 1, lastSeen }],
]);
});
it('sends correct mutations if api is unsuccessful', async () => {
@@ -255,6 +255,30 @@ describe('#actions', () => {
});
});
describe('#markMessagesUnread', () => {
it('sends correct mutations if API is successful', async () => {
const lastSeen = new Date().getTime() / 1000;
axios.post.mockResolvedValue({
data: { id: 1, agent_last_seen_at: lastSeen, unread_count: 1 },
});
await actions.markMessagesUnread({ commit }, { id: 1 });
jest.runAllTimers();
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls).toEqual([
[
types.UPDATE_MESSAGE_UNREAD_COUNT,
{ id: 1, lastSeen, unreadCount: 1 },
],
]);
});
it('sends correct mutations if API is unsuccessful', async () => {
axios.post.mockRejectedValue({ message: 'Incorrect header' });
await expect(
actions.markMessagesUnread({ commit }, { id: 1 })
).rejects.toThrow(Error);
});
});
describe('#sendEmailTranscript', () => {
it('sends correct mutations if api is successful', async () => {
axios.post.mockResolvedValue({});

View File

@@ -11,20 +11,20 @@ describe('#mutations', () => {
});
});
describe('#MARK_MESSAGE_READ', () => {
describe('#UPDATE_MESSAGE_UNREAD_COUNT', () => {
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 });
mutations[types.UPDATE_MESSAGE_UNREAD_COUNT](state, { id: 1, lastSeen });
expect(state.allConversations).toEqual([
{ id: 1, agent_last_seen_at: lastSeen },
{ id: 1, agent_last_seen_at: lastSeen, unread_count: 0 },
]);
});
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 });
mutations[types.UPDATE_MESSAGE_UNREAD_COUNT](state, { id: 1, lastSeen });
expect(state.allConversations).toEqual([]);
});
});