mattermost-mobile-upstream/app/screens/global_threads/global_threads.test.tsx
Elias Nahum b6fc85385e
Migrate from RNN to Expo router (#9402)
* Expo-Router partial migration

* Full migration to ExpoRouter

* i18n

* add tests

* Merge branch 'main' into expo-router

* align package-lock.json

* i18n

* feedback review

* feedback review

* android 16kb patch

* Refactored emoji picker keyboard using a state machine

* set android launch_screen in drawables instead of layout

* no conditional hooks

* remove duplicate call in test

* address feedback

* fix tests and address more feedback

* small corrections

* small corrections

* small corrections

* fix draft test

* fix draft test 2

* remove navigateToScreen in draff test

* fix nit in draft test

* remove doc file

* Feedback review

* fix snapshots

* improve test coverage

* fix i18n

* Upgrade t o RN 0.83, other dependencies and new architecture (#9737)

* library hardware-keyboard android new arch support fix

* library rnshare android new arch support fix

* library rnutils android new arch support fix

* library secure-pdf-viewer add new arch support

* Enable new arch on iOS and Android

* update emm and network client with new-arch

* update intune to use new-arch

* performance improvements

* fix tests

* fixes post input on new-arch

* fix android emoji picker

* remove doc

* run tests in parallel

* upgrade to React Native 0.83.9, Expo 55, React 19, and New Architecture

Bumps core dependencies to their latest versions:
- React Native 0.77.3 → 0.83.9 (New Architecture enabled)
- React 18.3.1 → 19.2.5
- Expo SDK 52 → 55
- TypeScript 5.8.3 → 6.0.3
- Node.js 22.16.0 → 24.15.0
- react-native-reanimated 3.17.3 → 4.3.0
- Various other dependency upgrades

Migrates iOS AppDelegate from Objective-C to Swift, updates Android
build tooling and Gradle wrapper, refreshes all patches and font
assets, and adapts app code, tests, and CI workflows throughout for
API changes introduced by these upgrades.

* remove unecessary dismissKeyboard in notifications

* feedback review

* update intune to use new-arch

* update @mattermost deps

* missing i18n string

* additional fixes

* update fastlane
2026-05-13 17:44:55 +08:00

151 lines
4.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {setGlobalThreadsTab} from '@actions/local/systems';
import NavigationHeader from '@components/navigation_header';
import {Screens} from '@constants';
import DatabaseManager from '@database/manager';
import useTabs from '@hooks/use_tabs';
import {renderWithEverything} from '@test/intl-test-helper';
import TestHelper from '@test/test_helper';
import GlobalThreads from './global_threads';
import Header from './threads_list/header';
import type {Database} from '@nozbe/watermelondb';
jest.mock('@hooks/device', () => ({
useIsTablet: jest.fn().mockReturnValue(false),
}));
jest.mock('@hooks/header', () => ({
useDefaultHeaderHeight: jest.fn().mockReturnValue(50),
}));
jest.mock('@hooks/team_switch', () => ({
useTeamSwitch: jest.fn().mockReturnValue(false),
}));
jest.mock('@actions/local/systems', () => ({
setGlobalThreadsTab: jest.fn(),
}));
jest.mock('@components/navigation_header', () => ({
__esModule: true,
default: jest.fn(),
}));
jest.mocked(NavigationHeader).mockImplementation((props) => React.createElement('NavigationHeader', props));
jest.mock('./threads_list/header', () => ({
__esModule: true,
default: jest.fn(),
}));
jest.mocked(Header).mockImplementation((props) => React.createElement('Header', props));
jest.mock('@hooks/use_tabs', () => ({
__esModule: true,
default: jest.fn(jest.requireActual('@hooks/use_tabs').default),
}));
describe('GlobalThreads', () => {
const serverUrl = 'https://example.com';
let database: Database;
const baseProps = {
componentId: Screens.GLOBAL_THREADS,
globalThreadsTab: 'all' as const,
hasUnreads: false,
teamId: 'team-id',
};
beforeEach(async () => {
await DatabaseManager.init([serverUrl]);
const result = DatabaseManager.serverDatabases[serverUrl]!;
database = result.database;
});
afterEach(async () => {
await DatabaseManager.deleteServerDatabase(serverUrl);
});
it('renders correctly with default props', () => {
renderWithEverything(<GlobalThreads {...baseProps}/>, {
database,
});
expect(useTabs).toHaveBeenCalledWith(
expect.any(String),
expect.arrayContaining([
expect.objectContaining({id: 'unreads', name: expect.objectContaining({defaultMessage: 'Unreads'})}),
expect.objectContaining({id: 'all', name: expect.objectContaining({defaultMessage: 'All Your Threads'})}),
]),
expect.any(Function),
expect.any(String),
);
});
it('shows dot indicator when hasUnreads is true', () => {
const {rerender} = renderWithEverything(
<GlobalThreads
{...baseProps}
hasUnreads={true}
/>,
{
database,
},
);
// Verify the unreads tab has a dot indicator
expect(useTabs).toHaveBeenCalledWith(
expect.any(String),
expect.arrayContaining([
expect.objectContaining({id: 'unreads', requiresUserAttention: true}),
expect.objectContaining({id: 'all', requiresUserAttention: false}),
]),
expect.any(Function),
expect.any(String),
);
jest.mocked(useTabs).mockClear();
rerender(
<GlobalThreads
{...baseProps}
hasUnreads={false}
/>,
);
expect(useTabs).toHaveBeenCalledWith(
expect.any(String),
expect.arrayContaining([
expect.objectContaining({id: 'unreads', requiresUserAttention: false}),
expect.objectContaining({id: 'all', requiresUserAttention: false}),
]),
expect.any(Function),
expect.any(String),
);
});
it('passes teamId to Header component', () => {
const {getByTestId} = renderWithEverything(<GlobalThreads {...baseProps}/>, {
database,
});
const header = getByTestId('global_threads.threads_list.header');
expect(header.props.teamId).toBe('team-id');
});
it('saves tab selection on unmount', async () => {
const {unmount} = renderWithEverything(<GlobalThreads {...baseProps}/>, {
database,
});
unmount();
expect(setGlobalThreadsTab).toHaveBeenCalledWith(expect.any(String), 'all');
await TestHelper.wait(250); // wait to give time to the promise to resolve and avoid an open handle
});
});