mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-16 16:11:34 +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
292 lines
10 KiB
TypeScript
292 lines
10 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {fireEvent, render, screen, waitFor} from '@testing-library/react-native';
|
|
import React from 'react';
|
|
import {BackHandler} from 'react-native';
|
|
|
|
import {savePreference} from '@actions/remote/preference';
|
|
import {Preferences, Screens} from '@constants';
|
|
import {getDefaultThemeByAppearance, useTheme} from '@context/theme';
|
|
import {navigateBack} from '@screens/navigation';
|
|
import {useCurrentScreen} from '@store/navigation_store';
|
|
import {renderWithIntl} from '@test/intl-test-helper';
|
|
|
|
import DisplayTheme from './display_theme';
|
|
|
|
jest.mock('@screens/navigation', () => ({
|
|
navigateBack: jest.fn(),
|
|
}));
|
|
jest.mock('@context/theme', () => ({
|
|
useTheme: jest.fn(),
|
|
getDefaultThemeByAppearance: jest.fn(),
|
|
}));
|
|
jest.mock('@actions/remote/preference');
|
|
jest.mock('@store/navigation_store');
|
|
|
|
jest.mocked(useTheme).mockReturnValue(Preferences.THEMES.denim);
|
|
jest.mocked(getDefaultThemeByAppearance).mockReturnValue(Preferences.THEMES.denim);
|
|
|
|
const displayThemeOtherProps = {
|
|
currentTeamId: '1',
|
|
currentUserId: '1',
|
|
};
|
|
|
|
describe('DisplayTheme', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should render with a few themes, denim selected', () => {
|
|
render(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim', 'sapphire']}
|
|
{...displayThemeOtherProps}
|
|
/>);
|
|
|
|
expect(screen.getByTestId('theme_display_settings.denim.option')).toBeTruthy();
|
|
expect(screen.getByTestId('theme_display_settings.denim.option.selected')).toBeTruthy();
|
|
|
|
expect(screen.getByTestId('theme_display_settings.sapphire.option')).toBeTruthy();
|
|
expect(screen.queryByTestId('theme_display_settings.sapphire.option.selected')).toBeFalsy();
|
|
});
|
|
|
|
it('should render with custom theme, current theme is custom', () => {
|
|
jest.mocked(useTheme).mockImplementation(() => ({...Preferences.THEMES.denim, type: 'custom'}));
|
|
|
|
renderWithIntl(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim', 'custom']}
|
|
{...displayThemeOtherProps}
|
|
/>);
|
|
|
|
expect(screen.getByTestId('theme_display_settings.custom.option')).toBeTruthy();
|
|
expect(screen.getByTestId('theme_display_settings.custom.option.selected')).toBeTruthy();
|
|
});
|
|
|
|
it('should render with custom theme (default) and user change to denim (non-custom)', async () => {
|
|
jest.mocked(useTheme).mockImplementation(() => ({...Preferences.THEMES.denim, type: 'custom'}));
|
|
|
|
renderWithIntl(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim', 'custom']}
|
|
{...displayThemeOtherProps}
|
|
/>);
|
|
|
|
expect(screen.getByTestId('theme_display_settings.custom.option')).toBeTruthy();
|
|
expect(screen.getByTestId('theme_display_settings.custom.option.selected')).toBeTruthy();
|
|
|
|
const denimTile = screen.getByTestId('theme_display_settings.denim.option');
|
|
|
|
fireEvent.press(denimTile);
|
|
|
|
await waitFor(() => {
|
|
expect(savePreference).toHaveBeenCalledWith(
|
|
expect.any(String),
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
category: 'theme',
|
|
value: expect.stringContaining('"type":"Denim"'),
|
|
}),
|
|
]),
|
|
);
|
|
expect(savePreference).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
// since we're mocking useTheme and savePreference, savePreference will post changes to the backend API, and upon success,
|
|
// it will update the `theme` preference via useTheme hook.
|
|
jest.mocked(useTheme).mockImplementation(() => ({...Preferences.THEMES.denim, type: 'Denim'}));
|
|
|
|
// clearing the savePreference mock to show that it will not be called again after re-rendering the component
|
|
jest.mocked(savePreference).mockClear();
|
|
|
|
screen.rerender(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim', 'custom']}
|
|
{...displayThemeOtherProps}
|
|
/>,
|
|
);
|
|
|
|
expect(savePreference).toHaveBeenCalledTimes(0);
|
|
|
|
expect(screen.getByTestId('theme_display_settings.denim.option.selected')).toBeTruthy();
|
|
});
|
|
|
|
it('should render only with custom theme, it gets de-selected, and then user re-selects it', async () => {
|
|
jest.mocked(useTheme).mockImplementation(() => ({...Preferences.THEMES.denim, type: 'custom'}));
|
|
|
|
renderWithIntl(
|
|
<DisplayTheme
|
|
allowedThemeKeys={[]}
|
|
{...displayThemeOtherProps}
|
|
/>);
|
|
|
|
jest.mocked(useTheme).mockImplementation(() => ({...Preferences.THEMES.denim, type: 'Denim'}));
|
|
|
|
screen.rerender(
|
|
<DisplayTheme
|
|
allowedThemeKeys={[]}
|
|
{...displayThemeOtherProps}
|
|
/>);
|
|
|
|
const customTile = screen.getByTestId('theme_display_settings.custom.option');
|
|
|
|
fireEvent.press(customTile);
|
|
|
|
await waitFor(() => {
|
|
expect(savePreference).toHaveBeenCalledWith(
|
|
expect.any(String),
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
category: 'theme',
|
|
value: expect.stringContaining('"type":"custom"'),
|
|
}),
|
|
]),
|
|
);
|
|
});
|
|
});
|
|
|
|
it('should render denim, then a different client set the theme to custom, and this client should render custom and automatically switch to it', () => {
|
|
renderWithIntl(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim']}
|
|
{...displayThemeOtherProps}
|
|
/>);
|
|
|
|
expect(screen.queryByTestId('theme_display_settings.custom.option.selected')).toBeFalsy();
|
|
|
|
jest.mocked(useTheme).mockImplementation(() => ({...Preferences.THEMES.denim, type: 'custom'}));
|
|
|
|
screen.rerender(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim']}
|
|
{...displayThemeOtherProps}
|
|
/>);
|
|
|
|
expect(screen.getByTestId('theme_display_settings.custom.option.selected')).toBeTruthy();
|
|
});
|
|
|
|
it('should not call popTopScreen (closes the screen) when changing theme', async () => {
|
|
renderWithIntl(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim', 'sapphire']}
|
|
{...displayThemeOtherProps}
|
|
/>,
|
|
);
|
|
|
|
const sapphireTile = screen.getByTestId('theme_display_settings.sapphire.option');
|
|
|
|
fireEvent.press(sapphireTile);
|
|
|
|
jest.mocked(useTheme).mockImplementation(() => ({...Preferences.THEMES.sapphire, type: 'Sapphire'}));
|
|
|
|
screen.rerender(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim', 'sapphire']}
|
|
{...displayThemeOtherProps}
|
|
/>,
|
|
);
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByTestId('theme_display_settings.sapphire.option.selected')).toBeTruthy();
|
|
});
|
|
|
|
expect(navigateBack).toHaveBeenCalledTimes(0);
|
|
});
|
|
|
|
it('should call navigateBack when Android back button is pressed', () => {
|
|
jest.mocked(useCurrentScreen).mockImplementation(() => Screens.SETTINGS_DISPLAY_THEME);
|
|
const androidBackButtonHandler = jest.spyOn(BackHandler, 'addEventListener');
|
|
|
|
renderWithIntl(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim', 'custom']}
|
|
{...displayThemeOtherProps}
|
|
/>,
|
|
);
|
|
|
|
// simulate Android back button press
|
|
androidBackButtonHandler.mock.calls[0][1]();
|
|
|
|
expect(navigateBack).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('should allow user to select two different themes using normal interaction', async () => {
|
|
jest.useFakeTimers();
|
|
|
|
const numOfSavePreferenceCalls = 2;
|
|
renderWithIntl(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim', 'sapphire']}
|
|
{...displayThemeOtherProps}
|
|
/>,
|
|
);
|
|
|
|
const sapphireTile = screen.getByTestId('theme_display_settings.sapphire.option');
|
|
|
|
fireEvent.press(sapphireTile);
|
|
|
|
jest.advanceTimersByTime(750);
|
|
jest.useRealTimers();
|
|
|
|
await waitFor(() => {
|
|
expect(savePreference).toHaveBeenCalledWith(
|
|
expect.any(String),
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
category: 'theme',
|
|
value: expect.stringContaining('"type":"Sapphire"'),
|
|
}),
|
|
]),
|
|
);
|
|
expect(savePreference).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
jest.useFakeTimers();
|
|
jest.advanceTimersByTime(750);
|
|
|
|
const denimTile = screen.getByTestId('theme_display_settings.denim.option');
|
|
|
|
fireEvent.press(denimTile);
|
|
|
|
// firing denimTile will not cause the savePreference to be called again since we have the prevent double tap
|
|
expect(savePreference).toHaveBeenCalledTimes(numOfSavePreferenceCalls);
|
|
|
|
jest.useRealTimers();
|
|
});
|
|
|
|
it('should not allow user to select a theme rapidly', async () => {
|
|
const numOfSavePreferenceCalls = 1;
|
|
renderWithIntl(
|
|
<DisplayTheme
|
|
allowedThemeKeys={['denim', 'sapphire']}
|
|
{...displayThemeOtherProps}
|
|
/>,
|
|
);
|
|
|
|
const sapphireTile = screen.getByTestId('theme_display_settings.sapphire.option');
|
|
|
|
fireEvent.press(sapphireTile);
|
|
|
|
await waitFor(() => {
|
|
expect(savePreference).toHaveBeenCalledWith(
|
|
expect.any(String),
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
category: 'theme',
|
|
value: expect.stringContaining('"type":"Sapphire"'),
|
|
}),
|
|
]),
|
|
);
|
|
expect(savePreference).toHaveBeenCalledTimes(numOfSavePreferenceCalls);
|
|
});
|
|
|
|
const denimTile = screen.getByTestId('theme_display_settings.denim.option');
|
|
|
|
fireEvent.press(denimTile);
|
|
|
|
// firing denimTile will not cause the savePreference to be called again since we have the prevent double tap
|
|
expect(savePreference).toHaveBeenCalledTimes(numOfSavePreferenceCalls);
|
|
});
|
|
});
|