mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-20 02:18:15 +00:00
* 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
232 lines
8.3 KiB
TypeScript
232 lines
8.3 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {type ComponentProps} from 'react';
|
|
|
|
import NavigationHeader from '@components/navigation_header';
|
|
import {General} from '@constants';
|
|
import {useServerUrl} from '@context/server';
|
|
import {fetchPlaybookRunsForChannel} from '@playbooks/actions/remote/runs';
|
|
import {goToCreateQuickChecklist, goToPlaybookRun, goToPlaybookRuns} from '@playbooks/screens/navigation';
|
|
import EphemeralStore from '@store/ephemeral_store';
|
|
import {renderWithIntl, waitFor} from '@test/intl-test-helper';
|
|
|
|
import ChannelHeader from './header';
|
|
|
|
jest.mock('@components/navigation_header', () => ({
|
|
__esModule: true,
|
|
default: jest.fn(),
|
|
}));
|
|
jest.mocked(NavigationHeader).mockImplementation((props) => React.createElement('NavigationHeader', {testID: 'navigation-header', ...props}));
|
|
|
|
jest.mock('@screens/navigation');
|
|
jest.mock('@playbooks/screens/navigation');
|
|
jest.mock('@playbooks/actions/remote/runs');
|
|
|
|
jest.mock('@calls/state', () => ({
|
|
getCallsConfig: jest.fn().mockReturnValue({
|
|
pluginEnabled: false,
|
|
}),
|
|
}));
|
|
|
|
const serverUrl = 'some.server.url';
|
|
jest.mock('@context/server');
|
|
jest.mocked(useServerUrl).mockReturnValue(serverUrl);
|
|
|
|
describe('ChannelHeader', () => {
|
|
function getBaseProps(): ComponentProps<typeof ChannelHeader> {
|
|
return {
|
|
channelId: 'channel-id',
|
|
channelType: 'O',
|
|
currentUserId: 'current-user-id',
|
|
displayName: 'Test Channel',
|
|
teamId: 'team-id',
|
|
hasPlaybookRuns: false,
|
|
playbooksActiveRuns: 0,
|
|
callsEnabledInChannel: false,
|
|
groupCallsAllowed: false,
|
|
isBookmarksEnabled: false,
|
|
canAddBookmarks: false,
|
|
hasBookmarks: false,
|
|
shouldRenderBookmarks: false,
|
|
isCustomStatusEnabled: false,
|
|
isCustomStatusExpired: false,
|
|
isOwnDirectMessage: false,
|
|
shouldRenderChannelBanner: false,
|
|
isPlaybooksEnabled: true,
|
|
isChannelAutotranslated: false,
|
|
};
|
|
}
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('shows playbook button with "+" when there are no active runs', () => {
|
|
const props = getBaseProps();
|
|
props.hasPlaybookRuns = false;
|
|
props.playbooksActiveRuns = 0;
|
|
props.isPlaybooksEnabled = true;
|
|
|
|
const {getByTestId} = renderWithIntl(<ChannelHeader {...props}/>);
|
|
|
|
const navHeader = getByTestId('navigation-header');
|
|
expect(navHeader.props.rightButtons).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
iconName: 'product-playbooks',
|
|
count: '+',
|
|
}),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('does not show playbook button when is DM or GM', () => {
|
|
const props = getBaseProps();
|
|
props.hasPlaybookRuns = true;
|
|
props.playbooksActiveRuns = 1;
|
|
props.channelType = General.DM_CHANNEL;
|
|
const {getByTestId, rerender} = renderWithIntl(<ChannelHeader {...props}/>);
|
|
const navHeader = getByTestId('navigation-header');
|
|
let rightButtons = navHeader.props.rightButtons;
|
|
expect(rightButtons).not.toEqual(expect.arrayContaining(
|
|
[
|
|
expect.objectContaining({
|
|
iconName: 'product-playbooks',
|
|
}),
|
|
]),
|
|
);
|
|
|
|
props.channelType = General.GM_CHANNEL;
|
|
rerender(<ChannelHeader {...props}/>);
|
|
rightButtons = navHeader.props.rightButtons;
|
|
expect(rightButtons).not.toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
iconName: 'product-playbooks',
|
|
}),
|
|
]),
|
|
);
|
|
|
|
props.channelType = General.OPEN_CHANNEL;
|
|
rerender(<ChannelHeader {...props}/>);
|
|
rightButtons = navHeader.props.rightButtons;
|
|
expect(rightButtons).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
iconName: 'product-playbooks',
|
|
}),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('shows playbook button with count when there are active runs', () => {
|
|
const props = getBaseProps();
|
|
props.playbooksActiveRuns = 3;
|
|
props.hasPlaybookRuns = true;
|
|
|
|
const {getByTestId} = renderWithIntl(<ChannelHeader {...props}/>);
|
|
|
|
const navHeader = getByTestId('navigation-header');
|
|
expect(navHeader.props.rightButtons).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
iconName: 'product-playbooks',
|
|
count: 3,
|
|
}),
|
|
]),
|
|
);
|
|
});
|
|
|
|
it('navigates to single playbook run when there is an active playbook provided', () => {
|
|
const props = getBaseProps();
|
|
props.playbooksActiveRuns = 1;
|
|
props.hasPlaybookRuns = true;
|
|
props.activeRunId = 'run-id';
|
|
|
|
const {getByTestId} = renderWithIntl(<ChannelHeader {...props}/>);
|
|
|
|
const navHeader = getByTestId('navigation-header');
|
|
const playbookButton = (navHeader.props as ComponentProps<typeof NavigationHeader>).rightButtons?.find((button) => button.iconName === 'product-playbooks');
|
|
expect(playbookButton).toBeTruthy();
|
|
|
|
playbookButton?.onPress();
|
|
expect(goToPlaybookRun).toHaveBeenCalledWith('run-id');
|
|
expect(goToPlaybookRuns).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('navigates to playbook runs list when there is no active playbook provided', () => {
|
|
const props = getBaseProps();
|
|
props.activeRunId = undefined;
|
|
props.playbooksActiveRuns = 3;
|
|
props.hasPlaybookRuns = true;
|
|
props.displayName = 'Test Channel';
|
|
|
|
const {getByTestId} = renderWithIntl(<ChannelHeader {...props}/>);
|
|
|
|
const navHeader = getByTestId('navigation-header');
|
|
const playbookButton = (navHeader.props as ComponentProps<typeof NavigationHeader>).rightButtons?.find((button) => button.iconName === 'product-playbooks');
|
|
expect(playbookButton).toBeTruthy();
|
|
|
|
playbookButton?.onPress();
|
|
expect(goToPlaybookRuns).toHaveBeenCalledWith('channel-id', 'Test Channel');
|
|
expect(goToPlaybookRun).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('navigates to create quick checklist screen when clicking + button with no active runs', () => {
|
|
const props = getBaseProps();
|
|
props.playbooksActiveRuns = 0;
|
|
props.hasPlaybookRuns = false;
|
|
props.displayName = 'Test Channel';
|
|
|
|
const {getByTestId} = renderWithIntl(<ChannelHeader {...props}/>);
|
|
|
|
const navHeader = getByTestId('navigation-header');
|
|
const playbookButton = (navHeader.props as ComponentProps<typeof NavigationHeader>).rightButtons?.find((button) => button.iconName === 'product-playbooks');
|
|
expect(playbookButton).toBeTruthy();
|
|
expect(playbookButton?.count).toBe('+');
|
|
|
|
playbookButton?.onPress();
|
|
|
|
expect(goToCreateQuickChecklist).toHaveBeenCalledWith(
|
|
'channel-id',
|
|
'Test Channel',
|
|
'current-user-id',
|
|
'team-id',
|
|
);
|
|
expect(goToPlaybookRun).not.toHaveBeenCalled();
|
|
expect(goToPlaybookRuns).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should not fetch runs when playbooks are disabled', async () => {
|
|
const ephemeralGetSpy = jest.spyOn(EphemeralStore, 'getChannelPlaybooksSynced');
|
|
|
|
const props = getBaseProps();
|
|
props.isPlaybooksEnabled = false;
|
|
ephemeralGetSpy.mockReturnValue(false);
|
|
|
|
renderWithIntl(<ChannelHeader {...props}/>);
|
|
|
|
await waitFor(() => {
|
|
expect(ephemeralGetSpy).not.toHaveBeenCalled();
|
|
expect(fetchPlaybookRunsForChannel).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
it('should not fetch runs when we already have the runs synced', async () => {
|
|
const ephemeralGetSpy = jest.spyOn(EphemeralStore, 'getChannelPlaybooksSynced');
|
|
|
|
const props = getBaseProps();
|
|
props.isPlaybooksEnabled = true;
|
|
|
|
ephemeralGetSpy.mockReturnValue(true);
|
|
|
|
renderWithIntl(<ChannelHeader {...props}/>);
|
|
|
|
await waitFor(() => {
|
|
expect(ephemeralGetSpy).toHaveBeenCalledWith(serverUrl, 'channel-id');
|
|
expect(fetchPlaybookRunsForChannel).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|