Files
upstream-rocketchat/apps/meteor/client/sidebar/hooks/useUnreadDisplay.spec.ts
upstream-mirror 30810eecd7
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
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

225 lines
7.1 KiB
TypeScript

import { mockAppRoot } from '@rocket.chat/mock-providers';
import { renderHook } from '@testing-library/react';
import { useUnreadDisplay } from './useUnreadDisplay';
import { createFakeSubscription } from '../../../tests/mocks/data';
const dmUnread = createFakeSubscription({
t: 'd',
unread: 3,
userMentions: 0,
groupMentions: 0,
tunread: undefined,
tunreadUser: undefined,
});
const dmThread = createFakeSubscription({
t: 'd',
unread: 3,
userMentions: 0,
groupMentions: 0,
tunread: ['1'],
tunreadUser: undefined,
});
const alert = createFakeSubscription({
t: 'p',
unread: 0,
userMentions: 0,
groupMentions: 0,
tunread: undefined,
tunreadUser: undefined,
alert: true,
});
const mentionAndGroupMention = createFakeSubscription({
t: 'p',
unread: 2,
userMentions: 1,
groupMentions: 1,
tunread: undefined,
tunreadUser: undefined,
alert: true,
});
const groupMention = createFakeSubscription({
t: 'p',
unread: 2,
userMentions: 0,
groupMentions: 2,
tunread: undefined,
tunreadUser: undefined,
alert: true,
});
const tunread = createFakeSubscription({
t: 'p',
unread: 0,
userMentions: 0,
groupMentions: 0,
tunread: ['1'],
tunreadUser: undefined,
alert: true,
});
const tunreadUser = createFakeSubscription({
t: 'p',
unread: 1,
userMentions: 0,
groupMentions: 0,
tunread: ['1'],
tunreadUser: ['1'],
alert: true,
});
const hideUnreadStatus = createFakeSubscription({
t: 'p',
hideUnreadStatus: true,
});
const hideUnreadAndMention = createFakeSubscription({
t: 'p',
hideUnreadStatus: true,
hideMentionStatus: true,
});
const noUnread = createFakeSubscription({
t: 'p',
unread: 0,
userMentions: 0,
groupMentions: 0,
tunread: undefined,
tunreadUser: undefined,
});
const wrapper = mockAppRoot()
.withTranslations('en', 'core', {
mentions_counter_one: '{{count}} mention',
mentions_counter_other: '{{count}} mentions',
threads_counter_one: '{{count}} unread threaded message',
threads_counter_other: '{{count}} unread threaded messages',
group_mentions_counter_one: '{{count}} group mention',
group_mentions_counter_other: '{{count}} group mentions',
unread_messages_counter_one: '{{count}} unread message',
unread_messages_counter_other: '{{count}} unread messages',
})
.build();
it('should return correct unread data for [Direct message unread]', async () => {
const { result } = renderHook(() => useUnreadDisplay(dmUnread), {
wrapper,
});
expect(result.current.unreadVariant).toBe('secondary');
expect(result.current.unreadTitle).toBe('3 unread messages');
expect(result.current.unreadCount).toHaveProperty('mentions', 0);
expect(result.current.unreadCount).toHaveProperty('threads', 0);
expect(result.current.unreadCount).toHaveProperty('groupMentions', 0);
expect(result.current.unreadCount).toHaveProperty('total', 3);
});
it('should return correct unread data for [Direct message with thread unread]', async () => {
const { result } = renderHook(() => useUnreadDisplay(dmThread), {
wrapper,
});
expect(result.current.unreadVariant).toBe('primary');
expect(result.current.unreadTitle).toBe('1 unread threaded message, 3 unread messages');
expect(result.current.unreadCount).toHaveProperty('mentions', 0);
expect(result.current.unreadCount).toHaveProperty('threads', 1);
expect(result.current.unreadCount).toHaveProperty('groupMentions', 0);
expect(result.current.unreadCount).toHaveProperty('total', 4);
});
it('should return correct unread data for [Channel with unread messages alert only]', async () => {
const { result } = renderHook(() => useUnreadDisplay(alert), {
wrapper,
});
expect(result.current.highlightUnread).toBe(true);
expect(result.current.showUnread).toBe(false);
expect(result.current.unreadCount).toHaveProperty('mentions', 0);
expect(result.current.unreadCount).toHaveProperty('threads', 0);
expect(result.current.unreadCount).toHaveProperty('groupMentions', 0);
expect(result.current.unreadCount).toHaveProperty('total', 0);
});
it('should return correct unread data for [Mention and group mention]', async () => {
const { result } = renderHook(() => useUnreadDisplay(mentionAndGroupMention), {
wrapper,
});
expect(result.current.unreadVariant).toBe('danger');
expect(result.current.unreadTitle).toBe('1 mention, 1 group mention');
expect(result.current.unreadCount).toHaveProperty('mentions', 1);
expect(result.current.unreadCount).toHaveProperty('threads', 0);
expect(result.current.unreadCount).toHaveProperty('groupMentions', 1);
expect(result.current.unreadCount).toHaveProperty('total', 2);
});
it('should return correct unread data for [Group mention]', async () => {
const { result } = renderHook(() => useUnreadDisplay(groupMention), {
wrapper,
});
expect(result.current.unreadVariant).toBe('warning');
expect(result.current.unreadTitle).toBe('2 group mentions');
expect(result.current.unreadCount).toHaveProperty('mentions', 0);
expect(result.current.unreadCount).toHaveProperty('threads', 0);
expect(result.current.unreadCount).toHaveProperty('groupMentions', 2);
expect(result.current.unreadCount).toHaveProperty('total', 2);
});
it('should return correct unread data for [Thread unread]', async () => {
const { result } = renderHook(() => useUnreadDisplay(tunread), {
wrapper,
});
expect(result.current.unreadVariant).toBe('primary');
expect(result.current.unreadTitle).toBe('1 unread threaded message');
expect(result.current.unreadCount).toHaveProperty('mentions', 0);
expect(result.current.unreadCount).toHaveProperty('groupMentions', 0);
expect(result.current.unreadCount).toHaveProperty('threads', 1);
expect(result.current.unreadCount).toHaveProperty('total', 1);
});
it('should return correct unread data for [Thread and thread user mention]', async () => {
const { result } = renderHook(() => useUnreadDisplay(tunreadUser), {
wrapper,
});
expect(result.current.unreadVariant).toBe('danger');
expect(result.current.unreadTitle).toBe('1 mention, 1 unread threaded message');
expect(result.current.unreadCount).toHaveProperty('mentions', 1);
expect(result.current.unreadCount).toHaveProperty('groupMentions', 0);
expect(result.current.unreadCount).toHaveProperty('threads', 1);
expect(result.current.unreadCount).toHaveProperty('total', 2);
});
it('should not highlight unread if hideUnreadStatus is enabled', async () => {
const { result } = renderHook(() => useUnreadDisplay(hideUnreadStatus));
expect(result.current.highlightUnread).toBe(false);
expect(result.current.showUnread).toBe(true);
});
it('should not show unread if hideUnreadStatus and hideMentionStatus is enabled', async () => {
const { result } = renderHook(() => useUnreadDisplay(hideUnreadAndMention));
expect(result.current.highlightUnread).toBe(false);
expect(result.current.showUnread).toBe(false);
});
it("should not show unread if there isn't any unread message", async () => {
const { result } = renderHook(() => useUnreadDisplay(noUnread));
expect(result.current.highlightUnread).toBe(false);
expect(result.current.showUnread).toBe(false);
expect(result.current.unreadCount).toHaveProperty('mentions', 0);
expect(result.current.unreadCount).toHaveProperty('groupMentions', 0);
expect(result.current.unreadCount).toHaveProperty('threads', 0);
expect(result.current.unreadCount).toHaveProperty('total', 0);
});