From bf98ccb6fb51a6299b368a59cd03f34805b850a3 Mon Sep 17 00:00:00 2001 From: Nithin David <1277421+nithindavid@users.noreply.github.com> Date: Fri, 17 Sep 2021 21:50:16 +0530 Subject: [PATCH] fixes broken tests --- .../widget/store/modules/messageV2/actions.js | 4 +- .../specs/conversation_new/mutation.spec.js | 121 +----------------- .../modules/specs/message/mutations.spec.js | 62 ++++++++- 3 files changed, 64 insertions(+), 123 deletions(-) diff --git a/app/javascript/widget/store/modules/messageV2/actions.js b/app/javascript/widget/store/modules/messageV2/actions.js index a6417198b..cd9ad2b0b 100644 --- a/app/javascript/widget/store/modules/messageV2/actions.js +++ b/app/javascript/widget/store/modules/messageV2/actions.js @@ -1,5 +1,5 @@ -import MessagePublicAPI from 'widget/api/messagePublic'; -import { refreshActionCableConnector } from '../../helpers/actionCable'; +import MessagePublicAPI from 'widget/api/messagesPublic'; +import { refreshActionCableConnector } from 'widget/helpers/actionCable'; import { createTemporaryMessage, createTemporaryAttachmentMessage, diff --git a/app/javascript/widget/store/modules/specs/conversation_new/mutation.spec.js b/app/javascript/widget/store/modules/specs/conversation_new/mutation.spec.js index 0efe6f4ea..530de0f80 100644 --- a/app/javascript/widget/store/modules/specs/conversation_new/mutation.spec.js +++ b/app/javascript/widget/store/modules/specs/conversation_new/mutation.spec.js @@ -1,4 +1,4 @@ -import { mutations } from '../../conversation_new/mutations'; +import { mutations } from '../../conversationv2/mutations'; describe('#mutations', () => { describe('#setUIFlag', () => { @@ -82,7 +82,7 @@ describe('#mutations', () => { }); expect(state.conversations).toEqual({ byId: { - 120: { id: 120, channel: 'facebook' }, + 120: { id: 120, channel: 'facebook', content_attributes: {} }, }, allIds: [120], }); @@ -199,7 +199,7 @@ describe('#mutations', () => { }); }); - describe('#addMessageIds', () => { + describe('#addMessageIdsToConversation', () => { it('it adds a list of message ids to existing conversation entry', () => { const state = { conversations: { @@ -212,31 +212,7 @@ describe('#mutations', () => { { id: 2, content: 'hi' }, { id: 3, content: 'hello' }, ]; - mutations.addMessageIds(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, { + mutations.addMessageIdsToConversation(state, { conversationId: 120, messages, }); @@ -251,7 +227,7 @@ describe('#mutations', () => { messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] }, }; const messages = [{ id: 3, content: 'hello' }]; - mutations.addMessageIds(state, { + mutations.addMessageIdsToConversation(state, { conversationId: 120, messages, }); @@ -266,7 +242,7 @@ describe('#mutations', () => { messages: { byId: { 2: { id: 2, content: 'hi' } }, allIds: [2] }, }; const messages = [{ id: 3, content: 'hello' }]; - mutations.addMessageIds(state, { + mutations.addMessageIdsToConversation(state, { conversationId: 120, 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', () => { it('it deletes message id in conversation correctly', () => { const state = { @@ -348,33 +268,4 @@ describe('#mutations', () => { 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, - }); - }); - }); }); diff --git a/app/javascript/widget/store/modules/specs/message/mutations.spec.js b/app/javascript/widget/store/modules/specs/message/mutations.spec.js index 3c7e6b30d..ef6fca5ba 100644 --- a/app/javascript/widget/store/modules/specs/message/mutations.spec.js +++ b/app/javascript/widget/store/modules/specs/message/mutations.spec.js @@ -1,11 +1,61 @@ -import { mutations } from '../../message'; +import { mutations } from '../../messageV2/mutations'; describe('#mutations', () => { - describe('#toggleUpdateStatus', () => { - it('set update flags', () => { - const state = { uiFlags: { status: '' } }; - mutations.toggleUpdateStatus(state, 'sent'); - expect(state.uiFlags.isUpdating).toEqual('sent'); + describe('#updateMessageEntry', () => { + it('it updates message in conversation correctly', () => { + const state = { + 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 = { + 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, + }); }); }); });