-
+
{{ currentConversationName }}
@@ -111,7 +111,7 @@ export default {
return !this.$store.getters.getUserId()
},
- isGuestAndhasNotUsername() {
+ isGuestWithoutDisplayName() {
const userName = this.$store.getters.getDisplayName()
return !userName && this.currentUserIsGuest
},
diff --git a/src/components/SetGuestUsername.vue b/src/components/SetGuestUsername.vue
index be6c03c2bca2..b7034e18c474 100644
--- a/src/components/SetGuestUsername.vue
+++ b/src/components/SetGuestUsername.vue
@@ -128,7 +128,7 @@ export default {
methods: {
handleChooseUserName() {
- this.guestNameStore.submitUserName(this.token, this.guestUserName)
+ this.guestNameStore.submitGuestUsername(this.token, this.guestUserName)
this.isEditingUsername = false
},
diff --git a/src/stores/__tests__/guestName.spec.js b/src/stores/__tests__/guestName.spec.js
index 48a7625ab792..e797deec17aa 100644
--- a/src/stores/__tests__/guestName.spec.js
+++ b/src/stores/__tests__/guestName.spec.js
@@ -1,7 +1,14 @@
import { createPinia, setActivePinia } from 'pinia'
+import { setGuestUserName } from '../../services/participantsService.js'
+import vuexStore from '../../store/index.js'
+import { generateOCSErrorResponse } from '../../test-helpers.js'
import { useGuestNameStore } from '../guestName.js'
+jest.mock('../../services/participantsService', () => ({
+ setGuestUserName: jest.fn(),
+}))
+
describe('guestNameStore', () => {
let store
@@ -135,4 +142,75 @@ describe('guestNameStore', () => {
expect(global.t).toHaveBeenCalledWith('spreed', 'Guest')
})
+ test('stores the display name when guest submits it', async () => {
+ // Arrange
+ const actor1 = {
+ token: 'token-1',
+ actorId: 'actor-id1',
+ actorDisplayName: t('spreed', 'Guest'),
+ }
+
+ vuexStore.dispatch('setCurrentUser', { uid: 'actor-id1' })
+
+ const newName = 'actor 1'
+
+ // Mock implementation of setGuestUserName
+ setGuestUserName.mockResolvedValue()
+
+ // Act
+ await store.submitGuestUsername(actor1.token, newName)
+
+ // Assert
+ expect(setGuestUserName).toHaveBeenCalledWith(actor1.token, newName)
+ expect(localStorage.setItem).toHaveBeenCalledWith('nick', newName)
+ expect(store.getGuestName('token-1', 'actor-id1')).toBe('actor 1')
+ expect(vuexStore.getters.getDisplayName()).toBe('actor 1')
+ })
+
+ test('removes display name from local storage when user sumbits an empty new name', async () => {
+ // Arrange
+ const actor1 = {
+ token: 'token-1',
+ actorId: 'actor-id1',
+ actorDisplayName: 'actor 1',
+ }
+ const newName = ''
+
+ vuexStore.dispatch('setCurrentUser', { uid: 'actor-id1' })
+
+ // Mock implementation of setGuestUserName
+ setGuestUserName.mockResolvedValue()
+
+ // Act
+ await store.submitGuestUsername(actor1.token, newName)
+
+ // Assert
+ expect(setGuestUserName).toHaveBeenCalledWith(actor1.token, newName)
+ expect(localStorage.removeItem).toHaveBeenCalledWith('nick')
+ })
+
+ test('resets to previous display name if there is an error in setting the new one', async () => {
+ // Arrange
+ const actor1 = {
+ token: 'token-1',
+ actorId: 'actor-id1',
+ actorDisplayName: 'old actor 1',
+ }
+
+ vuexStore.dispatch('setCurrentUser', { uid: 'actor-id1' })
+ store.addGuestName(actor1, { noUpdate: false })
+
+ const newName = 'actor 1'
+
+ // Mock implementation of setGuestUserName
+ const error = generateOCSErrorResponse({ payload: {}, status: 400 })
+ setGuestUserName.mockRejectedValue(error)
+
+ // Act
+ await store.submitGuestUsername(actor1.token, newName)
+
+ // Assert
+ expect(setGuestUserName).toHaveBeenCalledWith(actor1.token, newName)
+ expect(vuexStore.getters.getDisplayName()).toBe(actor1.actorDisplayName)
+ })
})
diff --git a/src/stores/guestName.js b/src/stores/guestName.js
index f9778c20a014..bb489dca6d98 100644
--- a/src/stores/guestName.js
+++ b/src/stores/guestName.js
@@ -93,7 +93,7 @@ export const useGuestNameStore = defineStore('guestName', {
* @param {string} token the token of the conversation
* @param {string} name the new guest name
*/
- async submitUserName(token, name) {
+ async submitGuestUsername(token, name) {
const actorId = store.getters.getActorId()
const previousName = this.getGuestName(token, actorId)