Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Code scanning - action / CodeQL-Build (push) Failing after 2s
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
172 lines
4.8 KiB
TypeScript
172 lines
4.8 KiB
TypeScript
import type { MessageActionContext } from '@rocket.chat/apps-engine/definition/ui';
|
|
import type { IMessage, IRoom } from '@rocket.chat/core-typings';
|
|
import { mockAppRoot } from '@rocket.chat/mock-providers';
|
|
import { renderHook } from '@testing-library/react';
|
|
|
|
import { usePermalinkAction } from './usePermalinkAction';
|
|
import { createFakeUser } from '../../../../tests/mocks/data';
|
|
import type { MessageActionConfig } from '../../../lib/MessageAction';
|
|
|
|
// Mock the getPermaLink function
|
|
jest.mock('../../../lib/getPermaLink', () => ({
|
|
getPermaLink: jest.fn(() => Promise.resolve('https://example.com/permalink')),
|
|
}));
|
|
|
|
const user = createFakeUser({
|
|
_id: 'current-user-id',
|
|
username: 'currentuser',
|
|
active: true,
|
|
roles: ['admin'],
|
|
type: 'user',
|
|
});
|
|
|
|
const appRoot = mockAppRoot()
|
|
.withUser(user)
|
|
.withTranslations('en', 'core', {
|
|
Copy_link: 'Copy link',
|
|
Copied: 'Copied',
|
|
})
|
|
.build();
|
|
|
|
const createMockMessage = (overrides: Partial<IMessage> = {}): IMessage => ({
|
|
_id: 'message-id',
|
|
rid: 'room-id',
|
|
msg: 'Test message',
|
|
ts: new Date(),
|
|
u: { _id: 'user-id', username: 'testuser' },
|
|
_updatedAt: new Date(),
|
|
channels: [],
|
|
file: { _id: 'file-id', name: 'file.txt', type: 'text/plain', size: 100, format: 'text/plain' },
|
|
mentions: [],
|
|
reactions: {},
|
|
starred: [],
|
|
...overrides,
|
|
});
|
|
|
|
const createMockRoom = (overrides: Partial<IRoom> = {}): IRoom => ({
|
|
_id: 'room-id',
|
|
t: 'c' as const,
|
|
name: 'test-room',
|
|
msgs: 0,
|
|
u: { _id: 'user-id', username: 'testuser' },
|
|
usersCount: 1,
|
|
_updatedAt: new Date(),
|
|
...overrides,
|
|
});
|
|
|
|
describe('usePermalinkAction', () => {
|
|
it('should be enabled for normal messages', () => {
|
|
const message = createMockMessage();
|
|
const room = createMockRoom();
|
|
const config = {
|
|
id: 'permalink',
|
|
context: ['message', 'message-mobile'],
|
|
type: 'communication',
|
|
order: 0,
|
|
} as { context: MessageActionContext[]; order: number } & Pick<MessageActionConfig, 'id' | 'type'>;
|
|
|
|
const { result } = renderHook(() => usePermalinkAction(message, config, { room }), { wrapper: appRoot });
|
|
|
|
expect(result.current).toEqual({
|
|
id: 'permalink',
|
|
icon: 'permalink',
|
|
label: 'Copy_link',
|
|
context: ['message', 'message-mobile'],
|
|
type: 'communication',
|
|
action: expect.any(Function),
|
|
order: 0,
|
|
group: 'menu',
|
|
disabled: false,
|
|
});
|
|
});
|
|
it('should be disabled for encrypted messages', () => {
|
|
const message = createMockMessage({
|
|
t: 'e2e',
|
|
e2e: 'done',
|
|
});
|
|
const room = createMockRoom();
|
|
const config = {
|
|
id: 'permalink',
|
|
context: ['message', 'message-mobile'],
|
|
type: 'communication',
|
|
order: 0,
|
|
} as { context: MessageActionContext[]; order: number } & Pick<MessageActionConfig, 'id' | 'type'>;
|
|
|
|
const { result } = renderHook(() => usePermalinkAction(message, config, { room }), { wrapper: appRoot });
|
|
|
|
expect(result.current).toEqual({
|
|
id: 'permalink',
|
|
icon: 'permalink',
|
|
label: 'Copy_link',
|
|
context: ['message', 'message-mobile'],
|
|
type: 'communication',
|
|
action: expect.any(Function),
|
|
order: 0,
|
|
group: 'menu',
|
|
disabled: true,
|
|
tooltip: 'Action_not_available_encrypted_content',
|
|
});
|
|
});
|
|
|
|
it('should be disabled for ABAC rooms', () => {
|
|
const message = createMockMessage();
|
|
const room = createMockRoom({
|
|
// @ts-expect-error to be implemented
|
|
abacAttributes: { someAttribute: 'value' },
|
|
});
|
|
const config = {
|
|
id: 'permalink',
|
|
context: ['message', 'message-mobile'],
|
|
type: 'communication',
|
|
order: 0,
|
|
} as { context: MessageActionContext[]; order: number } & Pick<MessageActionConfig, 'id' | 'type'>;
|
|
|
|
const { result } = renderHook(() => usePermalinkAction(message, config, { room }), { wrapper: appRoot });
|
|
|
|
expect(result.current).toEqual({
|
|
id: 'permalink',
|
|
icon: 'permalink',
|
|
label: 'Copy_link',
|
|
context: ['message', 'message-mobile'],
|
|
type: 'communication',
|
|
action: expect.any(Function),
|
|
order: 0,
|
|
group: 'menu',
|
|
disabled: true,
|
|
tooltip: 'Not_available_for_ABAC_enabled_rooms',
|
|
});
|
|
});
|
|
|
|
it('should be disabled for both encrypted messages and ABAC rooms', () => {
|
|
const message = createMockMessage({
|
|
t: 'e2e',
|
|
e2e: 'done',
|
|
});
|
|
const room = createMockRoom({
|
|
// @ts-expect-error to be implemented
|
|
abacAttributes: { someAttribute: 'value' },
|
|
});
|
|
const config = {
|
|
id: 'permalink',
|
|
context: ['message', 'message-mobile'],
|
|
type: 'communication',
|
|
order: 0,
|
|
} as { context: MessageActionContext[]; order: number } & Pick<MessageActionConfig, 'id' | 'type'>;
|
|
|
|
const { result } = renderHook(() => usePermalinkAction(message, config, { room }), { wrapper: appRoot });
|
|
|
|
expect(result.current).toEqual({
|
|
id: 'permalink',
|
|
icon: 'permalink',
|
|
label: 'Copy_link',
|
|
context: ['message', 'message-mobile'],
|
|
type: 'communication',
|
|
action: expect.any(Function),
|
|
order: 0,
|
|
group: 'menu',
|
|
disabled: true,
|
|
tooltip: 'Action_not_available_encrypted_content',
|
|
});
|
|
});
|
|
});
|