feat: Split reconnect logic PR (store) (#9520)

# Pull Request Template

## Description

This PR includes store filter parts split from this [Reconnect
PR](https://github.com/chatwoot/chatwoot/pull/9453)
This commit is contained in:
Sivin Varghese
2024-05-30 12:29:55 +05:30
committed by GitHub
parent 6c682a6869
commit e3eca47c31
22 changed files with 374 additions and 20 deletions

View File

@@ -659,4 +659,32 @@ describe('#addMentions', () => {
expect(commit.mock.calls).toEqual([[types.SET_CONTEXT_MENU_CHAT_ID, 1]]);
});
});
describe('#setChatListFilters', () => {
it('set chat list filters', () => {
const filters = {
inboxId: 1,
assigneeType: 'me',
status: 'open',
sortBy: 'created_at',
page: 1,
labels: ['label'],
teamId: 1,
conversationType: 'mention',
};
actions.setChatListFilters({ commit }, filters);
expect(commit.mock.calls).toEqual([
[types.SET_CHAT_LIST_FILTERS, filters],
]);
});
});
describe('#updateChatListFilters', () => {
it('update chat list filters', () => {
actions.updateChatListFilters({ commit }, { updatedWithin: 20 });
expect(commit.mock.calls).toEqual([
[types.UPDATE_CHAT_LIST_FILTERS, { updatedWithin: 20 }],
]);
});
});
});

View File

@@ -279,4 +279,45 @@ describe('#getters', () => {
expect(getters.getContextMenuChatId(state)).toEqual(1);
});
});
describe('#getChatListFilters', () => {
it('get chat list filters', () => {
const conversationFilters = {
inboxId: 1,
assigneeType: 'me',
status: 'open',
sortBy: 'created_at',
page: 1,
labels: ['label'],
teamId: 1,
conversationType: 'mention',
};
const state = { conversationFilters: conversationFilters };
expect(getters.getChatListFilters(state)).toEqual(conversationFilters);
});
});
describe('#getAppliedConversationFiltersQuery', () => {
it('get applied conversation filters query', () => {
const filtersList = [
{
attribute_key: 'status',
filter_operator: 'equal_to',
values: [{ id: 'snoozed', name: 'Snoozed' }],
query_operator: 'and',
},
];
const state = { appliedFilters: filtersList };
expect(getters.getAppliedConversationFiltersQuery(state)).toEqual({
payload: [
{
attribute_key: 'status',
filter_operator: 'equal_to',
query_operator: undefined,
values: ['snoozed'],
},
],
});
});
});
});

View File

@@ -279,6 +279,66 @@ describe('#mutations', () => {
});
});
describe('#SET_ALL_CONVERSATION', () => {
it('set all conversation', () => {
const state = { allConversations: [{ id: 1 }] };
const data = [{ id: 1, name: 'test' }];
mutations[types.SET_ALL_CONVERSATION](state, data);
expect(state.allConversations).toEqual(data);
});
it('set all conversation in reconnect if selected chat id and conversation id is the same', () => {
const state = {
allConversations: [{ id: 1, status: 'open' }],
selectedChatId: 1,
};
const data = [{ id: 1, name: 'test', status: 'resolved' }];
mutations[types.SET_ALL_CONVERSATION](state, data);
expect(state.allConversations).toEqual(data);
});
it('set all conversation in reconnect if selected chat id and conversation id is the same then do not update messages', () => {
const state = {
allConversations: [{ id: 1, messages: [{ id: 1, content: 'test' }] }],
selectedChatId: 1,
};
const data = [
{
id: 1,
name: 'test',
messages: [{ id: 1, content: 'updated message' }],
},
];
const expected = [
{ id: 1, name: 'test', messages: [{ id: 1, content: 'test' }] },
];
mutations[types.SET_ALL_CONVERSATION](state, data);
expect(state.allConversations).toEqual(expected);
});
it('set all conversation in reconnect if selected chat id and conversation id is not the same', () => {
const state = {
allConversations: [{ id: 1, status: 'open' }],
selectedChatId: 2,
};
const data = [{ id: 1, name: 'test', status: 'resolved' }];
mutations[types.SET_ALL_CONVERSATION](state, data);
expect(state.allConversations).toEqual(data);
});
it('set all conversation in reconnect if selected chat id and conversation id is not the same then update messages', () => {
const state = {
allConversations: [{ id: 1, messages: [{ id: 1, content: 'test' }] }],
selectedChatId: 2,
};
const data = [
{ id: 1, name: 'test', messages: [{ id: 1, content: 'tested' }] },
];
mutations[types.SET_ALL_CONVERSATION](state, data);
expect(state.allConversations).toEqual(data);
});
});
describe('#SET_ALL_ATTACHMENTS', () => {
it('set all attachments', () => {
const state = {
@@ -411,4 +471,54 @@ describe('#mutations', () => {
expect(state.contextMenuChatId).toEqual(2);
});
});
describe('#SET_CHAT_LIST_FILTERS', () => {
it('set chat list filters', () => {
const conversationFilters = {
inboxId: 1,
assigneeType: 'me',
status: 'open',
sortBy: 'created_at',
page: 1,
labels: ['label'],
teamId: 1,
conversationType: 'mention',
};
const state = { conversationFilters: conversationFilters };
mutations[types.SET_CHAT_LIST_FILTERS](state, conversationFilters);
expect(state.conversationFilters).toEqual(conversationFilters);
});
});
describe('#UPDATE_CHAT_LIST_FILTERS', () => {
it('update chat list filters', () => {
const conversationFilters = {
inboxId: 1,
assigneeType: 'me',
status: 'open',
sortBy: 'created_at',
page: 1,
labels: ['label'],
teamId: 1,
conversationType: 'mention',
};
const state = { conversationFilters: conversationFilters };
mutations[types.UPDATE_CHAT_LIST_FILTERS](state, {
inboxId: 2,
updatedWithin: 20,
assigneeType: 'all',
});
expect(state.conversationFilters).toEqual({
inboxId: 2,
assigneeType: 'all',
status: 'open',
sortBy: 'created_at',
page: 1,
labels: ['label'],
teamId: 1,
conversationType: 'mention',
updatedWithin: 20,
});
});
});
});