Skip to content

Commit

Permalink
test(capabilities): adjust tests for new changes
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed May 29, 2024
1 parent 659b8bf commit 30650ac
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 14 deletions.
159 changes: 159 additions & 0 deletions src/__mocks__/capabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { Capabilities } from '../types'

export const mockedCapabilities: Capabilities = {
spreed: {
features: [
'audio',
'video',
'chat-v2',
'conversation-v4',
'guest-signaling',
'empty-group-room',
'guest-display-names',
'multi-room-users',
'favorites',
'last-room-activity',
'no-ping',
'system-messages',
'delete-messages',
'mention-flag',
'in-call-flags',
'conversation-call-flags',
'notification-levels',
'invite-groups-and-mails',
'locked-one-to-one-rooms',
'read-only-rooms',
'listable-rooms',
'chat-read-marker',
'chat-unread',
'webinary-lobby',
'start-call-flag',
'chat-replies',
'circles-support',
'force-mute',
'sip-support',
'sip-support-nopin',
'chat-read-status',
'phonebook-search',
'raise-hand',
'room-description',
'rich-object-sharing',
'temp-user-avatar-api',
'geo-location-sharing',
'voice-message-sharing',
'signaling-v3',
'publishing-permissions',
'clear-history',
'direct-mention-flag',
'notification-calls',
'conversation-permissions',
'rich-object-list-media',
'rich-object-delete',
'unified-search',
'chat-permission',
'silent-send',
'silent-call',
'send-call-notification',
'talk-polls',
'breakout-rooms-v1',
'recording-v1',
'avatar',
'chat-get-context',
'single-conversation-status',
'chat-keep-notifications',
'typing-privacy',
'remind-me-later',
'bots-v1',
'markdown-messages',
'media-caption',
'session-state',
'note-to-self',
'recording-consent',
'sip-support-dialout',
'delete-messages-unlimited',
'edit-messages',
'silent-send-state',
'chat-read-last',
'federation-v1',
'ban-v1',
],
'features-local': [
'favorites',
'chat-read-status',
'listable-rooms',
'phonebook-search',
'temp-user-avatar-api',
'unified-search',
'avatar',
'remind-me-later',
'note-to-self',
],
config: {
attachments: {
allowed: true,
folder: '/Talk',
},
call: {
enabled: true,
'breakout-rooms': true,
recording: true,
'recording-consent': 0,
'supported-reactions': ['❤️', '🎉', '👏', '👍', '👎', '😂', '🤩', '🤔', '😲', '😥'],
'predefined-backgrounds': ['1_office', '2_home', '3_abstract'],
'can-upload-background': true,
'sip-enabled': true,
'sip-dialout-enabled': true,
'can-enable-sip': true,
},
chat: {
'max-length': 32000,
'read-privacy': 0,
'has-translation-providers': true,
'typing-privacy': 0,
},
conversations: {
'can-create': true,
},
federation: {
enabled: false,
'incoming-enabled': false,
'outgoing-enabled': false,
'only-trusted-servers': true,
},
previews: {
'max-gif-size': 3145728,
},
signaling: {
'session-ping-limit': 200,
},
},
'config-local': {
attachments: [
'allowed',
'folder',
],
call: [
'predefined-backgrounds',
'can-upload-background',
],
chat: [
'read-privacy',
'has-translation-providers',
'typing-privacy',
],
conversations: [
'can-create',
],
federation: [],
previews: [
'max-gif-size',
],
signaling: [],
},
version: '20.0.0-dev.0',
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ import FilePreview from './FilePreview.vue'

import storeConfig from '../../../../../store/storeConfig.js'

jest.mock('@nextcloud/capabilities', () => ({
getCapabilities: jest.fn(() => ({
spreed: {
config: {
previews: {
'max-gif-size': 1024,
},
},
}
})),
}))

describe('FilePreview.vue', () => {
let store
let localVue
Expand Down Expand Up @@ -312,8 +300,8 @@ describe('FilePreview.vue', () => {
})

test('renders static preview for big GIF files', async () => {
// bigger than max from capability
propsData.size = '2048'
// 4 MB, bigger than max from capability (3 MB)
propsData.size = '4194304'

const wrapper = shallowMount(FilePreview, {
localVue,
Expand Down
2 changes: 2 additions & 0 deletions src/composables/__tests__/useMessageInfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { useConversationInfo } from '../useConversationInfo.js'
import { useMessageInfo } from '../useMessageInfo.js'
import { useStore } from '../useStore.js'

// Test messages with 'edit-messages' and without 'delete-messages-unlimited' feature
jest.mock('@nextcloud/capabilities', () => ({
getCapabilities: jest.fn(() => ({
spreed: {
features: ['edit-messages'],
'features-local': [],
},
}))
}))
Expand Down
3 changes: 3 additions & 0 deletions src/services/conversationsService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ jest.mock('@nextcloud/axios', () => ({
get: jest.fn(),
}))

// Test requests when federations invite are enabled
jest.mock('@nextcloud/capabilities', () => ({
getCapabilities: jest.fn(() => ({
spreed: {
features: ['federation-v1'],
'features-local': [],
config: { federation: { enabled: true, 'outgoing-enabled': true } },
'config-local': { federation: [] },
},
}))
}))
Expand Down
2 changes: 2 additions & 0 deletions src/store/messagesStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jest.mock('@nextcloud/capabilities', () => ({
getCapabilities: jest.fn(() => ({
spreed: {
features: ['chat-read-last'],
'features-local': [],
'config-local': { chat: [] },
},
}))
}))
Expand Down
6 changes: 6 additions & 0 deletions src/test-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Vue from 'vue'

import { translate, translatePlural } from '@nextcloud/l10n'

import { mockedCapabilities } from './__mocks__/capabilities.ts'

jest.mock('extendable-media-recorder', () => ({
MediaRecorder: jest.fn(),
register: jest.fn(),
Expand All @@ -28,6 +30,10 @@ jest.mock('@nextcloud/upload', () => ({
getUploader: jest.fn(),
}))

jest.mock('@nextcloud/capabilities', () => ({
getCapabilities: jest.fn(() => mockedCapabilities),
}))

window.IntersectionObserver = jest.fn(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
Expand Down

0 comments on commit 30650ac

Please sign in to comment.