Skip to content

Commit

Permalink
test: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Jan 24, 2025
1 parent 12939d3 commit 435f43e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/ui-client/src/hooks/useUserDisplayName.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook } from '@testing-library/react';

import { useUserDisplayName } from './useUserDisplayName';

const fakeUser = {
name: 'John Doe',
username: 'john.doe',
};

it('should return username if UI_Use_Real_Name setting is false', () => {
const { result } = renderHook(() => useUserDisplayName(fakeUser), {
legacyRoot: true,
wrapper: mockAppRoot().withSetting('UI_Use_Real_Name', false).build(),
});

expect(result.current).toBe(fakeUser.username);
});

it('should return name if UI_Use_Real_Name setting is true', () => {
const { result } = renderHook(() => useUserDisplayName(fakeUser), {
legacyRoot: true,
wrapper: mockAppRoot().withSetting('UI_Use_Real_Name', true).build(),
});

expect(result.current).toBe(fakeUser.name);
});

it('should return username if UI_Use_Real_Name setting is true and user has no name', () => {
const { result } = renderHook(() => useUserDisplayName({ ...fakeUser, name: undefined }), {
legacyRoot: true,
wrapper: mockAppRoot().withSetting('UI_Use_Real_Name', true).build(),
});

expect(result.current).toBe(fakeUser.username);
});

0 comments on commit 435f43e

Please sign in to comment.