Skip to content

Commit

Permalink
fix: adjust tests
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <[email protected]>
  • Loading branch information
DorraJaouad committed Apr 30, 2024
1 parent 7864cfb commit 56f104d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import MessageBody from './MessagePart/MessageBody.vue'
import Quote from '../../../Quote.vue'

import * as useIsInCallModule from '../../../../composables/useIsInCall.js'
import * as useMessageInfoModule from '../../../../composables/useMessageInfo.js'
import { CONVERSATION, ATTENDEE, PARTICIPANT } from '../../../../constants.js'
import { EventBus } from '../../../../services/EventBus.js'
import storeConfig from '../../../../store/storeConfig.js'
Expand Down Expand Up @@ -312,6 +313,7 @@ describe('Message.vue', () => {
})

describe('rich objects', () => {
let useMessageInfoSpy
/**
* @param {object} message The rich-object-string message text
* @param {object} messageParameters The rich-object-string parameters
Expand All @@ -337,6 +339,14 @@ describe('Message.vue', () => {
return messageEl
}

beforeEach(() => {
useMessageInfoSpy = jest.spyOn(useMessageInfoModule, 'useMessageInfo')
})

afterEach(() => {
useMessageInfoSpy.mockRestore()
})

test('renders mentions', () => {
const mentions = {
'mention-user1': {
Expand Down Expand Up @@ -414,6 +424,11 @@ describe('Message.vue', () => {
type: 'file',
},
}

useMessageInfoSpy.mockReturnValue({
isFileShare: () => true,
})

const messageEl = renderRichObject(
caption,
params, {
Expand Down Expand Up @@ -744,7 +759,6 @@ describe('Message.vue', () => {
propsData: messageProps,
provide: injected,
})

const message = wrapper.findComponent({ name: 'NcRichText' })
expect(message.attributes('text')).toBe('test message')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'

import MessageButtonsBar from './../MessageButtonsBar/MessageButtonsBar.vue'

import * as useMessageInfoModule from '../../../../../composables/useMessageInfo.js'
import { CONVERSATION, PARTICIPANT, ATTENDEE } from '../../../../../constants.js'
import storeConfig from '../../../../../store/storeConfig.js'
import { useIntegrationsStore } from '../../../../../stores/integrations.js'
Expand Down Expand Up @@ -96,13 +97,20 @@ describe('MessageButtonsBar.vue', () => {
})

describe('actions', () => {
let useMessageInfoSpy

beforeEach(() => {
store = new Store(testStoreConfig)

injected = {
getMessagesListScroller: jest.fn(),
}

useMessageInfoSpy = jest.spyOn(useMessageInfoModule, 'useMessageInfo')
})

afterEach(() => {
useMessageInfoSpy.mockRestore()
})

describe('reply action', () => {
Expand Down Expand Up @@ -212,6 +220,9 @@ describe('MessageButtonsBar.vue', () => {
}

test('hides private reply action for own messages', async () => {
useMessageInfoSpy.mockReturnValue({
isMyMsg: () => true,
})
// using default message props which have the
// actor id set to the current user
testPrivateReplyActionVisible(false)
Expand Down Expand Up @@ -244,6 +255,9 @@ describe('MessageButtonsBar.vue', () => {
const mockDate = new Date('2020-05-07 10:00:00')
jest.spyOn(global.Date, 'now')
.mockImplementation(() => mockDate)
useMessageInfoSpy.mockReturnValue({
isDeleteable: () => true,
})
const wrapper = shallowMount(MessageButtonsBar, {
localVue,
store,
Expand Down Expand Up @@ -301,6 +315,9 @@ describe('MessageButtonsBar.vue', () => {
})

test('show delete action for file messages', () => {
useMessageInfoSpy.mockReturnValue({
isDeleteable: () => true,
})
messageProps.message = '{file}'
messageProps.messageParameters.file = {}
testDeleteMessageVisible(true)
Expand All @@ -313,13 +330,19 @@ describe('MessageButtonsBar.vue', () => {
})

test('shows delete action on other people messages for moderators', () => {
useMessageInfoSpy.mockReturnValue({
isDeleteable: () => true,
})
messageProps.actorId = 'another-user'
conversationProps.type = CONVERSATION.TYPE.GROUP
conversationProps.participantType = PARTICIPANT.TYPE.MODERATOR
testDeleteMessageVisible(true, null)
})

test('shows delete action on other people messages for owner', () => {
useMessageInfoSpy.mockReturnValue({
isDeleteable: () => true,
})
messageProps.actorId = 'another-user'
conversationProps.type = CONVERSATION.TYPE.PUBLIC
conversationProps.participantType = PARTICIPANT.TYPE.OWNER
Expand Down

0 comments on commit 56f104d

Please sign in to comment.