mattermost-mobile-upstream/app/screens/report_a_problem/copy_metadata.test.tsx
Rajat Dabade cf49418108
Report a problem not redirect to default email application (#9703)
* review comment

* i18n fix

* review comments

* review comments

* Fix import order in report_problem.test.tsx

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>

* Add distinctUntilChanged to observeIsFreeEdition and fix skip-screen condition

- Added distinctUntilChanged() to observeIsFreeEdition to match sibling helpers
- Removed attachLogsEnabled from skip-screen condition as it controls file picker for post composition, not report email
- Removed unused attachLogsEnabled prop and observable from settings report_problem component
- Updated tests to reflect the removed condition

Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>

* Remove unused Screens import from report_problem test

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor Agent <agent@cursor.com>
Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-14 09:10:39 -04:00

114 lines
3.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import Clipboard from '@react-native-clipboard/clipboard';
import {fireEvent} from '@testing-library/react-native';
import React from 'react';
import {Screens} from '@constants';
import {SNACK_BAR_TYPE} from '@constants/snack_bar';
import {renderWithIntl} from '@test/intl-test-helper';
import {metadataToString} from '@utils/share_logs';
import {showSnackBar} from '@utils/snack_bar';
import CopyMetadata from './copy_metadata';
jest.mock('@react-native-clipboard/clipboard', () => ({
setString: jest.fn(),
}));
jest.mock('@utils/snack_bar', () => ({
showSnackBar: jest.fn(),
}));
describe('screens/report_a_problem/copy_metadata', () => {
const metadata = {
currentUserId: 'user1',
currentTeamId: 'team1',
serverVersion: '7.8.0',
appVersion: '2.0.0',
appPlatform: 'ios',
deviceModel: 'iPhone 14',
};
const componentId = Screens.REPORT_PROBLEM;
beforeEach(() => {
jest.clearAllMocks();
});
it('renders all metadata fields', () => {
const {getByText} = renderWithIntl(
<CopyMetadata
metadata={metadata}
componentId={componentId}
/>,
);
// Check title
expect(getByText('METADATA:')).toBeTruthy();
// Check each metadata field is displayed
expect(getByText('Current User ID: user1')).toBeTruthy();
expect(getByText('Current Team ID: team1')).toBeTruthy();
expect(getByText('Server Version: 7.8.0')).toBeTruthy();
expect(getByText('App Version: 2.0.0')).toBeTruthy();
expect(getByText('App Platform: ios')).toBeTruthy();
});
it('copies metadata to clipboard when copy button is pressed', () => {
const {getByText} = renderWithIntl(
<CopyMetadata
metadata={metadata}
componentId={componentId}
/>,
);
const copyButton = getByText('Copy');
fireEvent.press(copyButton);
expect(Clipboard.setString).toHaveBeenCalledWith(
metadataToString(metadata),
);
expect(showSnackBar).toHaveBeenCalledWith({
barType: SNACK_BAR_TYPE.INFO_COPIED,
sourceScreen: componentId,
});
});
it('handles empty metadata', () => {
const emptyMetadata = {
currentUserId: '',
currentTeamId: '',
serverVersion: '',
appVersion: '',
appPlatform: '',
deviceModel: '',
};
const {getByText} = renderWithIntl(
<CopyMetadata
metadata={emptyMetadata}
componentId={componentId}
/>,
);
// Check that empty values are displayed correctly
expect(getByText('Current User ID: ')).toBeTruthy();
expect(getByText('Current Team ID: ')).toBeTruthy();
expect(getByText('Server Version: ')).toBeTruthy();
expect(getByText('App Version: ')).toBeTruthy();
expect(getByText('App Platform: ')).toBeTruthy();
const copyButton = getByText('Copy');
fireEvent.press(copyButton);
expect(Clipboard.setString).toHaveBeenCalledWith(
metadataToString(emptyMetadata),
);
expect(showSnackBar).toHaveBeenCalledWith({
barType: SNACK_BAR_TYPE.INFO_COPIED,
sourceScreen: componentId,
});
});
});