fixes broken tests

This commit is contained in:
Nithin David 2021-09-17 21:50:16 +05:30
parent ee557bac90
commit bf98ccb6fb
3 changed files with 64 additions and 123 deletions

View file

@ -1,5 +1,5 @@
import MessagePublicAPI from 'widget/api/messagePublic'; import MessagePublicAPI from 'widget/api/messagesPublic';
import { refreshActionCableConnector } from '../../helpers/actionCable'; import { refreshActionCableConnector } from 'widget/helpers/actionCable';
import { import {
createTemporaryMessage, createTemporaryMessage,
createTemporaryAttachmentMessage, createTemporaryAttachmentMessage,

View file

@ -1,4 +1,4 @@
import { mutations } from '../../conversation_new/mutations'; import { mutations } from '../../conversationv2/mutations';
describe('#mutations', () => { describe('#mutations', () => {
describe('#setUIFlag', () => { describe('#setUIFlag', () => {
@ -82,7 +82,7 @@ describe('#mutations', () => {
}); });
expect(state.conversations).toEqual({ expect(state.conversations).toEqual({
byId: { byId: {
120: { id: 120, channel: 'facebook' }, 120: { id: 120, channel: 'facebook', content_attributes: {} },
}, },
allIds: [120], allIds: [120],
}); });
@ -199,7 +199,7 @@ describe('#mutations', () => {
}); });
}); });
describe('#addMessageIds', () => { describe('#addMessageIdsToConversation', () => {
it('it adds a list of message ids to existing conversation entry', () => { it('it adds a list of message ids to existing conversation entry', () => {
const state = { const state = {
conversations: { conversations: {
@ -212,31 +212,7 @@ describe('#mutations', () => {
{ id: 2, content: 'hi' }, { id: 2, content: 'hi' },
{ id: 3, content: 'hello' }, { id: 3, content: 'hello' },
]; ];
mutations.addMessageIds(state, { mutations.addMessageIdsToConversation(state, {
conversationId: 120,
messages,
});
expect(state.conversations.byId[120].messages).toEqual([2, 3]);
});
it('it does not clear existing messages in a conversation', () => {});
it('new message id is added as last in allIds message in a conversation', () => {});
it('it does not add messages if conversation is not present in store', () => {});
});
describe('#addMessageIds', () => {
it('it adds a list of message ids to existing conversation entry', () => {
const state = {
conversations: {
byId: { 120: { id: 120, messages: [] } },
allIds: [120],
},
messages: { byId: {}, allIds: [] },
};
const messages = [
{ id: 2, content: 'hi' },
{ id: 3, content: 'hello' },
];
mutations.addMessageIds(state, {
conversationId: 120, conversationId: 120,
messages, messages,
}); });
@ -251,7 +227,7 @@ describe('#mutations', () => {
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] }, messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
}; };
const messages = [{ id: 3, content: 'hello' }]; const messages = [{ id: 3, content: 'hello' }];
mutations.addMessageIds(state, { mutations.addMessageIdsToConversation(state, {
conversationId: 120, conversationId: 120,
messages, messages,
}); });
@ -266,7 +242,7 @@ describe('#mutations', () => {
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] }, messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
}; };
const messages = [{ id: 3, content: 'hello' }]; const messages = [{ id: 3, content: 'hello' }];
mutations.addMessageIds(state, { mutations.addMessageIdsToConversation(state, {
conversationId: 120, conversationId: 120,
messages, messages,
}); });
@ -274,62 +250,6 @@ describe('#mutations', () => {
}); });
}); });
describe('#updateMessageEntry', () => {
it('it updates message in conversation correctly', () => {
const state = {
conversations: {
byId: { 12: { id: 12, messages: [2] } },
allIds: [12],
},
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
};
const message = { id: 2, content: 'hello' };
mutations.updateMessageEntry(state, message);
expect(state.messages.byId[2].content).toEqual('hello');
});
it('it does not create message if message does not exist in conversation', () => {
const state = {
conversations: {
byId: { 12: { id: 12, messages: [2] } },
allIds: [12],
},
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
};
const message = { id: 23, content: 'hello' };
mutations.updateMessageEntry(state, message);
expect(state.messages.byId[23]).toEqual(undefined);
});
});
describe('#removeMessageEntry', () => {
it('it deletes message in conversation correctly', () => {
const state = {
conversations: {
byId: { 12: { id: 12, messages: [2] } },
allIds: [12],
},
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
};
const messageId = 2;
mutations.removeMessageEntry(state, messageId);
expect(state.messages.byId[2]).toEqual(undefined);
});
});
describe('#removeMessageId', () => {
it('it deletes message id in conversation correctly', () => {
const state = {
conversations: {
byId: { 12: { id: 12, messages: [2] } },
allIds: [12],
},
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
};
const messageId = 2;
mutations.removeMessageId(state, messageId);
expect(state.messages.allIds).toEqual([]);
});
});
describe('#removeMessageIdFromConversation', () => { describe('#removeMessageIdFromConversation', () => {
it('it deletes message id in conversation correctly', () => { it('it deletes message id in conversation correctly', () => {
const state = { const state = {
@ -348,33 +268,4 @@ describe('#mutations', () => {
expect(state.conversations.byId[12].messages).toEqual([]); expect(state.conversations.byId[12].messages).toEqual([]);
}); });
}); });
describe('#setMessageUIFlag', () => {
it('it sets UI flag for conversation correctly', () => {
const state = {
messages: {
byId: {},
allIds: [],
uiFlags: {
byId: {
1: {
isCreating: false,
isPending: false,
isDeleting: false,
},
},
},
},
};
mutations.setMessageUIFlag(state, {
messageId: 1,
uiFlags: { isCreating: true },
});
expect(state.messages.uiFlags.byId[1]).toEqual({
isCreating: true,
isPending: false,
isDeleting: false,
});
});
});
}); });

View file

@ -1,11 +1,61 @@
import { mutations } from '../../message'; import { mutations } from '../../messageV2/mutations';
describe('#mutations', () => { describe('#mutations', () => {
describe('#toggleUpdateStatus', () => { describe('#updateMessageEntry', () => {
it('set update flags', () => { it('it updates message in conversation correctly', () => {
const state = { uiFlags: { status: '' } }; const state = {
mutations.toggleUpdateStatus(state, 'sent'); messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
expect(state.uiFlags.isUpdating).toEqual('sent'); };
const message = { id: 2, content: 'hello' };
mutations.updateMessageEntry(state, message);
expect(state.messages.byId[2].content).toEqual('hello');
});
it('it does not create message if message does not exist in conversation', () => {
const state = {
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
};
const message = { id: 23, content: 'hello' };
mutations.updateMessageEntry(state, message);
expect(state.messages.byId[23]).toEqual(undefined);
});
});
describe('#removeMessageEntry', () => {
it('it deletes message in conversation correctly', () => {
const state = {
messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] },
};
const messageId = 2;
mutations.removeMessageEntry(state, messageId);
expect(state.messages.byId[2]).toEqual(undefined);
});
});
describe('#setMessageUIFlag', () => {
it('it sets UI flag for conversation correctly', () => {
const state = {
messages: {
byId: {},
allIds: [],
uiFlags: {
byId: {
1: {
isCreating: false,
isPending: false,
isDeleting: false,
},
},
},
},
};
mutations.setMessageUIFlag(state, {
messageId: 1,
uiFlags: { isCreating: true },
});
expect(state.messages.uiFlags.byId[1]).toEqual({
isCreating: true,
isPending: false,
isDeleting: false,
});
}); });
}); });
}); });