Skip to content

Commit

Permalink
Add tests and revert some added conditions
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <dorra.jaoued7@gmail.com>
  • Loading branch information
DorraJaouad committed Jan 15, 2024
1 parent 2c4ec35 commit 6daa822
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
42 changes: 42 additions & 0 deletions src/stores/__tests__/chatExtras.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/stores/chatExtras.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},

/**
Expand Down Expand Up @@ -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)
},

/**
Expand Down

0 comments on commit 6daa822

Please sign in to comment.