mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-03 20:48:07 +00:00
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:
@@ -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 }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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'],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -91,4 +91,13 @@ describe('#actions', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setActiveConversationFolder', () => {
|
||||
it('set active conversation folder', async () => {
|
||||
await actions.setActiveConversationFolder({ commit }, customViewList[0]);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_ACTIVE_CONVERSATION_FOLDER, customViewList[0]],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -76,4 +76,11 @@ describe('#getters', () => {
|
||||
isDeleting: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('getActiveConversationFolder', () => {
|
||||
const state = { activeConversationFolder: customViewList[0] };
|
||||
expect(getters.getActiveConversationFolder(state)).toEqual(
|
||||
customViewList[0]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,4 +34,12 @@ describe('#mutations', () => {
|
||||
expect(state.records).toEqual(updateCustomViewList);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#SET_ACTIVE_CONVERSATION_FOLDER', () => {
|
||||
it('set active conversation folder', () => {
|
||||
const state = { activeConversationFolder: customViewList[0] };
|
||||
mutations[types.SET_ACTIVE_CONVERSATION_FOLDER](state, customViewList[0]);
|
||||
expect(state.activeConversationFolder).toEqual(customViewList[0]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -283,4 +283,34 @@ describe('#actions', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setNotificationFilters', () => {
|
||||
it('set notification filters', async () => {
|
||||
const filters = {
|
||||
page: 1,
|
||||
status: 'read',
|
||||
type: 'all',
|
||||
sortOrder: 'desc',
|
||||
};
|
||||
await actions.setNotificationFilters({ commit }, filters);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.SET_NOTIFICATION_FILTERS, filters],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateNotificationFilters', () => {
|
||||
it('update notification filters', async () => {
|
||||
const filters = {
|
||||
page: 1,
|
||||
status: 'unread',
|
||||
type: 'all',
|
||||
sortOrder: 'desc',
|
||||
};
|
||||
await actions.updateNotificationFilters({ commit }, filters);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.UPDATE_NOTIFICATION_FILTERS, filters],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -81,4 +81,18 @@ describe('#getters', () => {
|
||||
};
|
||||
expect(getters.getMeta(state)).toEqual({ unreadCount: 1 });
|
||||
});
|
||||
|
||||
it('getNotificationFilters', () => {
|
||||
const state = {
|
||||
notificationFilters: {
|
||||
page: 1,
|
||||
status: 'unread',
|
||||
type: 'all',
|
||||
sortOrder: 'desc',
|
||||
},
|
||||
};
|
||||
expect(getters.getNotificationFilters(state)).toEqual(
|
||||
state.notificationFilters
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -52,19 +52,19 @@ describe('#mutations', () => {
|
||||
});
|
||||
|
||||
describe('#SET_NOTIFICATIONS', () => {
|
||||
it('set notifications ', () => {
|
||||
it('set notifications', () => {
|
||||
const state = { records: {} };
|
||||
mutations[types.SET_NOTIFICATIONS](state, [
|
||||
{ id: 1 },
|
||||
{ id: 2 },
|
||||
{ id: 3 },
|
||||
{ id: 4 },
|
||||
{ id: 1, primary_actor_id: 1 },
|
||||
{ id: 2, primary_actor_id: 2 },
|
||||
{ id: 3, primary_actor_id: 3 },
|
||||
{ id: 4, primary_actor_id: 4 },
|
||||
]);
|
||||
expect(state.records).toEqual({
|
||||
1: { id: 1 },
|
||||
2: { id: 2 },
|
||||
3: { id: 3 },
|
||||
4: { id: 4 },
|
||||
1: { id: 1, primary_actor_id: 1 },
|
||||
2: { id: 2, primary_actor_id: 2 },
|
||||
3: { id: 3, primary_actor_id: 3 },
|
||||
4: { id: 4, primary_actor_id: 4 },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user