From 6daa8220192a0a210d85201fcbf477f821361605 Mon Sep 17 00:00:00 2001 From: DorraJaouad Date: Mon, 15 Jan 2024 11:32:09 +0100 Subject: [PATCH] Add tests and revert some added conditions Signed-off-by: DorraJaouad --- src/stores/__tests__/chatExtras.spec.js | 42 +++++++++++++++++++++++++ src/stores/chatExtras.js | 8 ++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/stores/__tests__/chatExtras.spec.js b/src/stores/__tests__/chatExtras.spec.js index 5fdd61be0a5..f85e826fd93 100644 --- a/src/stores/__tests__/chatExtras.spec.js +++ b/src/stores/__tests__/chatExtras.spec.js @@ -117,6 +117,48 @@ describe('chatExtrasStore', () => { }) }) + describe('current edit input message', () => { + it('sets current edit input message', () => { + // Act + chatExtrasStore.setChatEditInput({ token: 'token-1', text: 'This is an edited message' }) + + // Assert + expect(chatExtrasStore.getChatEditInput('token-1')).toStrictEqual('This is an edited message') + }) + + it('clears current edit input message', () => { + // Arrange + chatExtrasStore.setChatEditInput({ token: 'token-1', text: 'This is an edited message' }) + + // Act + chatExtrasStore.removeChatEditInput('token-1') + + // Assert + expect(chatExtrasStore.chatEditInput['token-1']).not.toBeDefined() + expect(chatExtrasStore.getChatEditInput('token-1')).toBe('') + }) + + it('sets current to-edit message id', () => { + // Arrange + chatExtrasStore.setMessageIdToEdit('token-1', 'id-1') + + // Assert + expect(chatExtrasStore.messageIdToEdit['token-1']).toStrictEqual('id-1') + }) + + it('clears current to-edit message id', () => { + // Arrange + chatExtrasStore.setMessageIdToEdit('token-1', 'id-1') + + // Act + chatExtrasStore.removeMessageIdToEdit('token-1') + + // Assert + expect(chatExtrasStore.chatEditInput['token-1']).not.toBeDefined() // chatEditInput is cleared + expect(chatExtrasStore.getMessageIdToEdit('token-1')).toBe(undefined) + }) + }) + describe('purge store', () => { it('clears store for provided token', async () => { // Arrange diff --git a/src/stores/chatExtras.js b/src/stores/chatExtras.js index 82f5bf08421..db90deccaaf 100644 --- a/src/stores/chatExtras.js +++ b/src/stores/chatExtras.js @@ -125,9 +125,7 @@ export const useChatExtrasStore = defineStore('chatExtras', { * @param {string} token The conversation token */ removeParentIdToReply(token) { - if (this.parentToReply[token]) { - Vue.delete(this.parentToReply, token) - } + Vue.delete(this.parentToReply, token) }, /** @@ -181,9 +179,7 @@ export const useChatExtrasStore = defineStore('chatExtras', { */ removeMessageIdToEdit(token) { this.removeChatEditInput(token) - if (this.messageIdToEdit[token]) { - Vue.delete(this.messageIdToEdit, token) - } + Vue.delete(this.messageIdToEdit, token) }, /**