diff --git a/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js index d25b70589..b2d68c94f 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js @@ -404,6 +404,33 @@ describe('#actions', () => { expect(commit.mock.calls).toEqual([[types.CLEAR_CONVERSATION_FILTERS]]); }); }); + + describe('#updateConversationLastActivity', () => { + it('sends correct action', async () => { + await actions.updateConversationLastActivity( + { commit }, + { conversationId: 1, lastActivityAt: 12121212 } + ); + expect(commit.mock.calls).toEqual([ + [ + 'UPDATE_CONVERSATION_LAST_ACTIVITY', + { conversationId: 1, lastActivityAt: 12121212 }, + ], + ]); + }); + }); + + describe('#setChatSortFilter', () => { + it('sends correct action', async () => { + await actions.setChatSortFilter( + { commit }, + { data: 'sort_on_created_at' } + ); + expect(commit.mock.calls).toEqual([ + ['CHANGE_CHAT_SORT_FILTER', { data: 'sort_on_created_at' }], + ]); + }); + }); }); describe('#deleteMessage', () => { diff --git a/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js index 7dc0dade5..f9d775df2 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js @@ -6,43 +6,127 @@ commonHelpers(); describe('#getters', () => { describe('#getAllConversations', () => { - it('order conversations based on last message date', () => { + it('order conversations based on last activity', () => { const state = { allConversations: [ { id: 1, messages: [ { - created_at: 1466424480, + content: 'test1', }, ], + created_at: 2466424490, + last_activity_at: 2466424490, }, { id: 2, - messages: [ - { - created_at: 2466424490, - }, - ], + messages: [{ content: 'test2' }], + created_at: 1466424480, + last_activity_at: 1466424480, }, ], }; + + expect(getters.getAllConversations(state)).toEqual([ + { + id: 1, + messages: [ + { + content: 'test1', + }, + ], + created_at: 2466424490, + last_activity_at: 2466424490, + }, + { + id: 2, + messages: [{ content: 'test2' }], + created_at: 1466424480, + last_activity_at: 1466424480, + }, + ]); + }); + it('order conversations based on created at', () => { + const state = { + allConversations: [ + { + id: 1, + messages: [ + { + content: 'test1', + }, + ], + created_at: 1683645801, // Tuesday, 9 May 2023 + last_activity_at: 2466424490, + }, + { + id: 2, + messages: [{ content: 'test2' }], + created_at: 1652109801, // Monday, 9 May 2022 + last_activity_at: 1466424480, + }, + ], + chatSortFilter: 'sort_on_created_at', + }; + expect(getters.getAllConversations(state)).toEqual([ { id: 2, - messages: [ - { - created_at: 2466424490, - }, - ], + messages: [{ content: 'test2' }], + created_at: 1652109801, + last_activity_at: 1466424480, }, { id: 1, messages: [ { - created_at: 1466424480, + content: 'test1', }, ], + created_at: 1683645801, + last_activity_at: 2466424490, + }, + ]); + }); + it('order conversations based on default order', () => { + const state = { + allConversations: [ + { + id: 1, + messages: [ + { + content: 'test1', + }, + ], + created_at: 2466424490, + last_activity_at: 2466424490, + }, + { + id: 2, + messages: [{ content: 'test2' }], + created_at: 1466424480, + last_activity_at: 1466424480, + }, + ], + }; + + expect(getters.getAllConversations(state)).toEqual([ + { + id: 1, + messages: [ + { + content: 'test1', + }, + ], + created_at: 2466424490, + last_activity_at: 2466424490, + }, + { + id: 2, + messages: [{ content: 'test2' }], + created_at: 1466424480, + last_activity_at: 1466424480, }, ]); }); diff --git a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js index 738de5c55..2c4bdb2cc 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js @@ -39,6 +39,19 @@ describe('#mutations', () => { describe('#ASSIGN_TEAM', () => { it('clears current chat window', () => { + const state = { allConversations: [{ id: 1, meta: {} }] }; + mutations[types.UPDATE_CONVERSATION_LAST_ACTIVITY](state, { + lastActivityAt: 1602256198, + conversationId: 1, + }); + + expect(state.allConversations).toEqual([ + { id: 1, meta: {}, last_activity_at: 1602256198 }, + ]); + }); + }); + describe('#UPDATE_CONVERSATION_LAST_ACTIVITY', () => { + it('update conversation last activity', () => { const state = { allConversations: [{ id: 1, meta: {} }] }; mutations[types.ASSIGN_TEAM](state, { team: { id: 1, name: 'Team 1' }, @@ -50,6 +63,16 @@ describe('#mutations', () => { }); }); + describe('#CHANGE_CHAT_SORT_FILTER', () => { + it('update conversation sort filter', () => { + const state = { chatSortFilter: 'latest' }; + mutations[types.CHANGE_CHAT_SORT_FILTER](state, { + data: 'sort_on_created_at', + }); + expect(state.chatSortFilter).toEqual({ data: 'sort_on_created_at' }); + }); + }); + describe('#SET_CURRENT_CHAT_WINDOW', () => { it('set current chat window', () => { const state = { selectedChatId: 1 };