Browse Source

fix: adjust tests, set pinia globally

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
pull/15328/head
Maksim Sukharev 5 months ago
parent
commit
8f66f7a4d5
  1. 6
      src/components/LeftSidebar/ConversationsList/Conversation.spec.js
  2. 10
      src/components/MessagesList/MessagesGroup/Message/Message.spec.js
  3. 6
      src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.spec.js
  4. 22
      src/components/RightSidebar/Participants/Participant.spec.js
  5. 8
      src/components/RightSidebar/Participants/ParticipantPermissionsEditor.spec.js
  6. 34
      src/components/RoomSelector.spec.js
  7. 8
      src/store/participantsStore.spec.js
  8. 4
      src/test-setup.js
  9. 148
      src/utils/SignalingTypingHandler.spec.js

6
src/components/LeftSidebar/ConversationsList/Conversation.spec.js

@ -477,14 +477,10 @@ describe('Conversation.vue', () => {
describe('deleting conversation', () => {
let actionHandler
let updateTokenAction
beforeEach(() => {
actionHandler = jest.fn().mockResolvedValueOnce()
updateTokenAction = jest.fn()
testStoreConfig.modules.conversationsStore.actions.deleteConversationFromServer = actionHandler
testStoreConfig.modules.tokenStore.getters.getToken = jest.fn().mockReturnValue(() => 'another-token')
testStoreConfig.modules.tokenStore.actions.updateToken = updateTokenAction
store = new Vuex.Store(testStoreConfig)
})
@ -498,7 +494,6 @@ describe('Conversation.vue', () => {
// Assert
expect(actionHandler).toHaveBeenCalledWith(expect.anything(), { token: TOKEN })
expect($router.push).not.toHaveBeenCalled()
expect(updateTokenAction).not.toHaveBeenCalled()
})
test('does not delete conversation when not confirmed', async () => {
@ -511,7 +506,6 @@ describe('Conversation.vue', () => {
// Assert
expect(actionHandler).not.toHaveBeenCalled()
expect($router.push).not.toHaveBeenCalled()
expect(updateTokenAction).not.toHaveBeenCalled()
})
test('hides "delete conversation" action when not allowed', async () => {

10
src/components/MessagesList/MessagesGroup/Message/Message.spec.js

@ -24,6 +24,7 @@ import { ATTENDEE, CONVERSATION, MESSAGE, PARTICIPANT } from '../../../../consta
import { EventBus } from '../../../../services/EventBus.ts'
import storeConfig from '../../../../store/storeConfig.js'
import { useActorStore } from '../../../../stores/actor.ts'
import { useTokenStore } from '../../../../stores/token.ts'
// needed because of https://github.com/vuejs/vue-test-utils/issues/1507
const RichTextStub = {
@ -48,11 +49,15 @@ describe('Message.vue', () => {
let injected
const getVisualLastReadMessageIdMock = jest.fn()
let actorStore
let tokenStore
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
setActivePinia(createPinia())
const actorStore = useActorStore()
actorStore = useActorStore()
tokenStore = useTokenStore()
conversationProps = {
token: TOKEN,
@ -68,9 +73,8 @@ describe('Message.vue', () => {
actorStore.actorId = 'user-id-1'
actorStore.actorType = ATTENDEE.ACTOR_TYPE.USERS
tokenStore.token = TOKEN
testStoreConfig = cloneDeep(storeConfig)
testStoreConfig.modules.tokenStore.getters.getToken
= jest.fn().mockReturnValue(() => TOKEN)
testStoreConfig.modules.conversationsStore.getters.conversation
= jest.fn().mockReturnValue((token) => conversationProps)
testStoreConfig.modules.messagesStore.getters.getVisualLastReadMessageId

6
src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.spec.js

@ -15,6 +15,7 @@ import { ATTENDEE, CONVERSATION, MESSAGE, PARTICIPANT } from '../../../../../con
import storeConfig from '../../../../../store/storeConfig.js'
import { useActorStore } from '../../../../../stores/actor.ts'
import { useIntegrationsStore } from '../../../../../stores/integrations.js'
import { useTokenStore } from '../../../../../stores/token.ts'
import { findNcActionButton, findNcButton } from '../../../../../test-helpers.js'
describe('MessageButtonsBar.vue', () => {
@ -26,12 +27,14 @@ describe('MessageButtonsBar.vue', () => {
let injected
let conversationProps
let actorStore
let tokenStore
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
setActivePinia(createPinia())
actorStore = useActorStore()
tokenStore = useTokenStore()
conversationProps = {
token: TOKEN,
@ -42,12 +45,11 @@ describe('MessageButtonsBar.vue', () => {
}
testStoreConfig = cloneDeep(storeConfig)
testStoreConfig.modules.tokenStore.getters.getToken
= jest.fn().mockReturnValue(() => TOKEN)
testStoreConfig.modules.conversationsStore.getters.conversation
= jest.fn().mockReturnValue((token) => conversationProps)
actorStore.actorType = ATTENDEE.ACTOR_TYPE.USERS
actorStore.actorId = 'user-id-1'
tokenStore.token = TOKEN
messageProps = {
previousMessageId: 100,

22
src/components/RightSidebar/Participants/Participant.spec.js

@ -24,20 +24,26 @@ import Participant from './Participant.vue'
import { ATTENDEE, PARTICIPANT, WEBINAR } from '../../../constants.ts'
import storeConfig from '../../../store/storeConfig.js'
import { useActorStore } from '../../../stores/actor.ts'
import { useTokenStore } from '../../../stores/token.ts'
import { findNcActionButton, findNcButton } from '../../../test-helpers.js'
describe('Participant.vue', () => {
const TOKEN = 'XXTOKENXX'
let conversation
let participant
let store
let localVue
let testStoreConfig
let actorStore
let tokenStore
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
setActivePinia(createPinia())
const actorStore = useActorStore()
actorStore = useActorStore()
tokenStore = useTokenStore()
participant = {
displayName: 'Alice',
@ -58,18 +64,18 @@ describe('Participant.vue', () => {
}
conversation = {
token: 'current-token',
token: TOKEN,
participantType: PARTICIPANT.TYPE.USER,
lobbyState: WEBINAR.LOBBY.NONE,
}
actorStore.actorId = 'user-actor-id'
actorStore.actorType = ATTENDEE.ACTOR_TYPE.USERS
tokenStore.token = TOKEN
const conversationGetterMock = jest.fn().mockReturnValue(conversation)
testStoreConfig = cloneDeep(storeConfig)
testStoreConfig.modules.tokenStore.getters.getToken = () => () => 'current-token'
testStoreConfig.modules.conversationsStore.getters.conversation = () => conversationGetterMock
store = new Vuex.Store(testStoreConfig)
})
@ -356,7 +362,7 @@ describe('Participant.vue', () => {
await actionButton.find('button').trigger('click')
expect(demoteFromModeratorAction).toHaveBeenCalledWith(expect.anything(), {
token: 'current-token',
token: TOKEN,
attendeeId: 'alice-attendee-id',
})
}
@ -448,7 +454,7 @@ describe('Participant.vue', () => {
await actionButton.find('button').trigger('click')
expect(promoteToModeratorAction).toHaveBeenCalledWith(expect.anything(), {
token: 'current-token',
token: TOKEN,
attendeeId: 'alice-attendee-id',
})
}
@ -541,7 +547,7 @@ describe('Participant.vue', () => {
await actionButton.find('button').trigger('click')
expect(resendInvitationsAction).toHaveBeenCalledWith(expect.anything(), {
token: 'current-token',
token: TOKEN,
attendeeId: 'alice-attendee-id',
actorId: 'alice@mail.com',
})
@ -588,7 +594,7 @@ describe('Participant.vue', () => {
await button.find('button').trigger('click')
expect(removeAction).toHaveBeenCalledWith(expect.anything(), {
token: 'current-token',
token: TOKEN,
attendeeId: 'alice-attendee-id',
banParticipant: false,
internalNote: '',
@ -630,7 +636,7 @@ describe('Participant.vue', () => {
await button.find('button').trigger('click')
expect(removeAction).toHaveBeenCalledWith(expect.anything(), {
token: 'current-token',
token: TOKEN,
attendeeId: 'alice-attendee-id',
banParticipant: true,
internalNote,

8
src/components/RightSidebar/Participants/ParticipantPermissionsEditor.spec.js

@ -4,11 +4,13 @@
*/
import { createLocalVue, mount } from '@vue/test-utils'
import { cloneDeep } from 'lodash'
import { createPinia, setActivePinia } from 'pinia'
import Vuex from 'vuex'
import PermissionsEditor from '../../PermissionsEditor/PermissionsEditor.vue'
import ParticipantPermissionsEditor from './ParticipantPermissionsEditor.vue'
import { ATTENDEE, PARTICIPANT } from '../../../constants.ts'
import storeConfig from '../../../store/storeConfig.js'
import { useTokenStore } from '../../../stores/token.ts'
describe('ParticipantPermissionsEditor.vue', () => {
let conversation
@ -17,9 +19,13 @@ describe('ParticipantPermissionsEditor.vue', () => {
let localVue
let testStoreConfig
let tokenStore
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
setActivePinia(createPinia())
tokenStore = useTokenStore()
participant = {
displayName: 'Alice',
@ -40,10 +46,10 @@ describe('ParticipantPermissionsEditor.vue', () => {
],
}
tokenStore.token = 'XXTOKENXX'
const conversationGetterMock = jest.fn().mockReturnValue(conversation)
testStoreConfig = cloneDeep(storeConfig)
testStoreConfig.modules.tokenStore.getters.getToken = () => () => 'current-token'
testStoreConfig.modules.conversationsStore.getters.conversation = () => conversationGetterMock
// Add a mock function for the action and see if its called and with which arguments
testStoreConfig.modules.participantsStore.actions.setPermissions = jest.fn()

34
src/components/RoomSelector.spec.js

@ -11,6 +11,7 @@ import NcDialog from '@nextcloud/vue/components/NcDialog'
import ConversationSearchResult from './LeftSidebar/ConversationsList/ConversationSearchResult.vue'
import RoomSelector from './RoomSelector.vue'
import { CONVERSATION } from '../constants.ts'
import { useTokenStore } from '../stores/token.ts'
import { generateOCSResponse } from '../test-helpers.js'
jest.mock('@nextcloud/axios', () => ({
@ -35,8 +36,12 @@ const ConversationsSearchListVirtualStub = {
describe('RoomSelector', () => {
let conversations
let tokenStore
beforeEach(() => {
tokenStore = useTokenStore()
tokenStore.token = 'current-token'
conversations = [{
token: 'token-3',
displayName: 'zzz',
@ -80,16 +85,6 @@ describe('RoomSelector', () => {
type: CONVERSATION.TYPE.GROUP,
objectType: 'file',
}]
global.OCA.Talk = {
instance: {
$store: {
getters: {
getToken: jest.fn().mockReturnValue('current-token'),
},
},
},
}
})
afterEach(() => {
@ -120,7 +115,24 @@ describe('RoomSelector', () => {
describe('rendering', () => {
it('renders sorted conversations list fetched from server', async () => {
// Arrange
const wrapper = await mountRoomSelector()
const wrapper = await mountRoomSelector({ isPlugin: true })
expect(axios.get).toHaveBeenCalledWith(
generateOcsUrl('/apps/spreed/api/v4/room'),
{ params: { includeStatus: 1 } },
)
// Assert
const list = wrapper.findAllComponents({ name: 'NcListItem' })
expect(list).toHaveLength(4)
expect(list.at(0).props('name')).toBe(conversations[1].displayName)
expect(list.at(1).props('name')).toBe(conversations[0].displayName)
expect(list.at(2).props('name')).toBe(conversations[2].displayName)
expect(list.at(3).props('name')).toBe(conversations[4].displayName)
})
it('excludes current conversation if mounted inside of Talk', async () => {
// Arrange
const wrapper = await mountRoomSelector({ isPlugin: false })
expect(axios.get).toHaveBeenCalledWith(
generateOcsUrl('/apps/spreed/api/v4/room'),
{ params: { includeStatus: 1 } },

8
src/store/participantsStore.spec.js

@ -32,6 +32,7 @@ import {
import { useActorStore } from '../stores/actor.ts'
import { useGuestNameStore } from '../stores/guestName.js'
import { useSessionStore } from '../stores/session.ts'
import { useTokenStore } from '../stores/token.ts'
import { generateOCSErrorResponse, generateOCSResponse } from '../test-helpers.js'
import participantsStore from './participantsStore.js'
import storeConfig from './storeConfig.js'
@ -75,6 +76,7 @@ describe('participantsStore', () => {
let store = null
let guestNameStore = null
let actorStore
let tokenStore
beforeEach(() => {
localVue = createLocalVue()
@ -82,6 +84,7 @@ describe('participantsStore', () => {
setActivePinia(createPinia())
guestNameStore = useGuestNameStore()
actorStore = useActorStore()
tokenStore = useTokenStore()
testStoreConfig = cloneDeep(participantsStore)
store = new Vuex.Store(testStoreConfig)
@ -797,15 +800,15 @@ describe('participantsStore', () => {
})
describe('joining conversation', () => {
let getTokenMock
let participantData
let joinedConversationEventMock
beforeEach(() => {
tokenStore.token = TOKEN
joinedConversationEventMock = jest.fn()
EventBus.once('joined-conversation', joinedConversationEventMock)
getTokenMock = jest.fn().mockReturnValue(TOKEN)
participantData = {
actorId: 'actor-id',
sessionId: 'session-id-1',
@ -818,7 +821,6 @@ describe('participantsStore', () => {
attendeeId: 1,
}))
testStoreConfig.getters.getToken = () => getTokenMock
testStoreConfig.actions.addConversation = jest.fn().mockImplementation((context) => {
// needed for the updateSessionId call which requires this
context.dispatch('addParticipantOnce', {

4
src/test-setup.js

@ -3,6 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { createPinia, setActivePinia } from 'pinia'
import Vue from 'vue'
import { mockedCapabilities } from './__mocks__/capabilities.ts'
@ -138,3 +139,6 @@ console.error = function(message) {
originalError.apply(console, arguments)
throw (message instanceof Error ? message : new Error(message))
}
// Set up Pinia for state management in tests
setActivePinia(createPinia())

148
src/utils/SignalingTypingHandler.spec.js

@ -7,37 +7,42 @@ import { cloneDeep } from 'lodash'
import Vuex from 'vuex'
import storeConfig from '../store/storeConfig.js'
import { useActorStore } from '../stores/actor.ts'
import { useTokenStore } from '../stores/token.ts'
import SignalingTypingHandler from './SignalingTypingHandler.js'
describe('SignalingTypingHandler', () => {
let store
let actorStore
let tokenStore
let signaling
let signalingTypingHandler
const TOKEN = 'XXTOKENXX'
const addLocalParticipantInTheTokenData = {
token: 'theToken',
token: TOKEN,
participant: {
sessionIds: ['localNextcloudSessionId'],
attendeeId: 'localAttendeeId',
},
}
const addUser1ParticipantInTheTokenData = {
token: 'theToken',
token: TOKEN,
participant: {
sessionIds: ['user1NextcloudSessionId'],
attendeeId: 'user1AttendeeId',
},
}
const addGuest1ParticipantInTheTokenData = {
token: 'theToken',
token: TOKEN,
participant: {
sessionIds: ['guest1NextcloudSessionId'],
attendeeId: 'guest1AttendeeId',
},
}
const addGuest2ParticipantInTheTokenData = {
token: 'theToken',
token: TOKEN,
participant: {
sessionIds: ['guest2NextcloudSessionId'],
attendeeId: 'guest2AttendeeId',
@ -75,7 +80,8 @@ describe('SignalingTypingHandler', () => {
beforeEach(() => {
const testStoreConfig = cloneDeep(storeConfig)
store = new Vuex.Store(testStoreConfig)
const actorStore = useActorStore()
actorStore = useActorStore()
tokenStore = useTokenStore()
signaling = new function() {
this._handlers = {}
@ -123,12 +129,18 @@ describe('SignalingTypingHandler', () => {
})
})
afterEach(() => {
jest.clearAllMocks()
tokenStore.token = ''
tokenStore.lastJoinedConversationToken = null
})
describe('start typing', () => {
test('when there are no other participants in the room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.token = TOKEN
tokenStore.lastJoinedConversationToken = TOKEN
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -138,15 +150,15 @@ describe('SignalingTypingHandler', () => {
signalingTypingHandler.setTyping(true)
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(0)
})
test('when there is another participant in the room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
@ -158,7 +170,7 @@ describe('SignalingTypingHandler', () => {
signalingTypingHandler.setTyping(true)
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(1)
expect(signaling.emit).toHaveBeenCalledWith('message', { type: 'startedTyping', to: 'user1SignalingSessionId' })
})
@ -166,8 +178,8 @@ describe('SignalingTypingHandler', () => {
test('when there are other participants in the room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -181,15 +193,15 @@ describe('SignalingTypingHandler', () => {
signalingTypingHandler.setTyping(true)
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(2)
expect(signaling.emit).toHaveBeenNthCalledWith(1, 'message', { type: 'startedTyping', to: 'user1SignalingSessionId' })
expect(signaling.emit).toHaveBeenNthCalledWith(2, 'message', { type: 'startedTyping', to: 'guest1SignalingSessionId' })
})
test('when signaling is not set yet', () => {
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -198,23 +210,23 @@ describe('SignalingTypingHandler', () => {
signalingTypingHandler.setSignaling(signaling)
// Typing is not set once finally joined the room.
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(0)
})
test('when room is not joined yet', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
tokenStore.updateToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
signalingTypingHandler.setTyping(true)
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateLastJoinedConversationToken(TOKEN)
// Typing is not set once finally joined the room.
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(0)
})
})
@ -223,8 +235,8 @@ describe('SignalingTypingHandler', () => {
test('when there are no other participants in the room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -235,15 +247,15 @@ describe('SignalingTypingHandler', () => {
signalingTypingHandler.setTyping(true)
signalingTypingHandler.setTyping(false)
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(0)
})
test('when there is another participant in the room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
@ -256,7 +268,7 @@ describe('SignalingTypingHandler', () => {
signalingTypingHandler.setTyping(true)
signalingTypingHandler.setTyping(false)
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(2)
expect(signaling.emit).toHaveBeenNthCalledWith(1, 'message', { type: 'startedTyping', to: 'user1SignalingSessionId' })
expect(signaling.emit).toHaveBeenNthCalledWith(2, 'message', { type: 'stoppedTyping', to: 'user1SignalingSessionId' })
@ -265,8 +277,8 @@ describe('SignalingTypingHandler', () => {
test('when there are other participants in the room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -281,7 +293,7 @@ describe('SignalingTypingHandler', () => {
signalingTypingHandler.setTyping(true)
signalingTypingHandler.setTyping(false)
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(4)
expect(signaling.emit).toHaveBeenNthCalledWith(1, 'message', { type: 'startedTyping', to: 'user1SignalingSessionId' })
expect(signaling.emit).toHaveBeenNthCalledWith(2, 'message', { type: 'startedTyping', to: 'guest1SignalingSessionId' })
@ -290,8 +302,8 @@ describe('SignalingTypingHandler', () => {
})
test('when signaling is not set yet', () => {
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -301,24 +313,24 @@ describe('SignalingTypingHandler', () => {
signalingTypingHandler.setSignaling(signaling)
// Typing is not set once finally joined the room.
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(0)
})
test('when room is not joined yet', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
tokenStore.updateToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
signalingTypingHandler.setTyping(true)
signalingTypingHandler.setTyping(false)
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateLastJoinedConversationToken(TOKEN)
// Typing is not set once finally joined the room.
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(0)
})
})
@ -327,8 +339,8 @@ describe('SignalingTypingHandler', () => {
test('in the current room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -345,7 +357,7 @@ describe('SignalingTypingHandler', () => {
from: 'user1SignalingSessionId',
}])
expect(store.getters.participantsListTyping('theToken')).toEqual([
expect(store.getters.participantsListTyping(TOKEN)).toEqual([
expectedUser1Participant,
])
})
@ -357,8 +369,8 @@ describe('SignalingTypingHandler', () => {
// not misbehave.
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
store.dispatch('addParticipant', addGuest1ParticipantInTheTokenData)
@ -373,7 +385,7 @@ describe('SignalingTypingHandler', () => {
from: 'user1SignalingSessionId',
}])
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
})
})
@ -381,8 +393,8 @@ describe('SignalingTypingHandler', () => {
test('in the current room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -403,7 +415,7 @@ describe('SignalingTypingHandler', () => {
from: 'user1SignalingSessionId',
}])
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
})
test('in another room', () => {
@ -413,8 +425,8 @@ describe('SignalingTypingHandler', () => {
// not misbehave.
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
store.dispatch('addParticipant', addGuest1ParticipantInTheTokenData)
@ -433,15 +445,15 @@ describe('SignalingTypingHandler', () => {
from: 'user1SignalingSessionId',
}])
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
})
})
test('current participant leaves when typing', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
@ -457,7 +469,7 @@ describe('SignalingTypingHandler', () => {
localParticipantInSignalingParticipantList,
]])
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(1)
expect(signaling.emit).toHaveBeenCalledWith('message', { type: 'startedTyping', to: 'user1SignalingSessionId' })
})
@ -465,8 +477,8 @@ describe('SignalingTypingHandler', () => {
test('other participants join when current participant is typing', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
store.dispatch('addParticipant', addGuest1ParticipantInTheTokenData)
@ -484,7 +496,7 @@ describe('SignalingTypingHandler', () => {
user1ParticipantInSignalingParticipantList,
]])
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(2)
expect(signaling.emit).toHaveBeenNthCalledWith(1, 'message', { type: 'startedTyping', to: 'guest1SignalingSessionId' })
expect(signaling.emit).toHaveBeenNthCalledWith(2, 'message', { type: 'startedTyping', to: 'user1SignalingSessionId' })
@ -493,8 +505,8 @@ describe('SignalingTypingHandler', () => {
test('other participants join when current participant is no longer typing', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
store.dispatch('addParticipant', addGuest1ParticipantInTheTokenData)
@ -513,7 +525,7 @@ describe('SignalingTypingHandler', () => {
user1ParticipantInSignalingParticipantList,
]])
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(2)
expect(signaling.emit).toHaveBeenNthCalledWith(1, 'message', { type: 'startedTyping', to: 'guest1SignalingSessionId' })
expect(signaling.emit).toHaveBeenNthCalledWith(2, 'message', { type: 'stoppedTyping', to: 'guest1SignalingSessionId' })
@ -522,8 +534,8 @@ describe('SignalingTypingHandler', () => {
test('other participants leave when they were typing', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -551,7 +563,7 @@ describe('SignalingTypingHandler', () => {
guest1ParticipantInSignalingParticipantList,
]])
expect(store.getters.participantsListTyping('theToken')).toEqual([
expect(store.getters.participantsListTyping(TOKEN)).toEqual([
expectedGuest2Participant,
])
})
@ -559,8 +571,8 @@ describe('SignalingTypingHandler', () => {
test('other participants leave when they were not typing', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -592,7 +604,7 @@ describe('SignalingTypingHandler', () => {
guest1ParticipantInSignalingParticipantList,
]])
expect(store.getters.participantsListTyping('theToken')).toEqual([
expect(store.getters.participantsListTyping(TOKEN)).toEqual([
expectedGuest2Participant,
])
})
@ -601,8 +613,8 @@ describe('SignalingTypingHandler', () => {
test('prevents start typing in the current room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
@ -616,15 +628,15 @@ describe('SignalingTypingHandler', () => {
signalingTypingHandler.setTyping(true)
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
expect(signaling.emit).toHaveBeenCalledTimes(0)
})
test('prevents other participants start typing in the current room', () => {
signalingTypingHandler.setSignaling(signaling)
store.dispatch('updateToken', 'theToken')
store.dispatch('updateLastJoinedConversationToken', 'theToken')
tokenStore.updateToken(TOKEN)
tokenStore.updateLastJoinedConversationToken(TOKEN)
store.dispatch('addParticipant', addUser1ParticipantInTheTokenData)
store.dispatch('addParticipant', addLocalParticipantInTheTokenData)
@ -643,7 +655,7 @@ describe('SignalingTypingHandler', () => {
from: 'user1SignalingSessionId',
}])
expect(store.getters.participantsListTyping('theToken')).toEqual([])
expect(store.getters.participantsListTyping(TOKEN)).toEqual([])
})
})
})
Loading…
Cancel
Save