mattermost-mobile/app/screens/user_profile/index.test.ts
Guillermo Vayá 9699318043
Show profile message actions for non-DM user profiles (#9496)
* Show profile message actions for non-DM user profiles

* Add DM profile visibility safeguards and coverage

* Simplify DM channel name parsing and add reversed order test

Remove redundant manual split('__') validation in
isDirectMessageWithViewedUser, relying on getUserIdFromChannelName
which already handles both name orderings. Add test for reversed
DM channel name order (B__A) to prevent regressions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 12:49:07 +01:00

73 lines
2.1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {General} from '@constants';
import {isDirectMessageWithViewedUser} from './index';
describe('screens/user_profile/index', () => {
it('should return true when viewing the DM counterpart user', () => {
const result = isDirectMessageWithViewedUser(
{
name: 'current_user_id__other_user_id',
type: General.DM_CHANNEL,
},
'current_user_id',
'other_user_id',
);
expect(result).toBe(true);
});
it('should return false when viewing a user different from the DM counterpart', () => {
const result = isDirectMessageWithViewedUser(
{
name: 'current_user_id__other_user_id',
type: General.DM_CHANNEL,
},
'current_user_id',
'someone_else',
);
expect(result).toBe(false);
});
it('should return false for non-DM channels', () => {
const result = isDirectMessageWithViewedUser(
{
name: 'current_user_id__other_user_id',
type: General.OPEN_CHANNEL,
},
'current_user_id',
'other_user_id',
);
expect(result).toBe(false);
});
it('should return true when DM channel name has reversed user order', () => {
const result = isDirectMessageWithViewedUser(
{
name: 'other_user_id__current_user_id',
type: General.DM_CHANNEL,
},
'current_user_id',
'other_user_id',
);
expect(result).toBe(true);
});
it('should return false when DM channel name is malformed', () => {
const result = isDirectMessageWithViewedUser(
{
name: 'malformed_channel_name',
type: General.DM_CHANNEL,
},
'current_user_id',
'other_user_id',
);
expect(result).toBe(false);
});
});